mirror of
https://github.com/Paillat-dev/viralfactory.git
synced 2026-01-02 01:06:19 +00:00
Fix import, fix option indices in init, formatting
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import gradio as gr
|
import gradio as gr
|
||||||
|
|
||||||
import TTS
|
from TTS.api import TTS
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
@@ -95,9 +95,9 @@ class CoquiTTSEngine(BaseTTSEngine):
|
|||||||
def __init__(self, options: list):
|
def __init__(self, options: list):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.voice = options[0][0]
|
self.voice = options[0]
|
||||||
self.language = options[1][0]
|
self.language = options[1]
|
||||||
self.to_force_duration = options[2][0]
|
self.to_force_duration = options[2]
|
||||||
self.duration = options[3]
|
self.duration = options[3]
|
||||||
|
|
||||||
os.environ["COQUI_TOS_AGREED"] = "1"
|
os.environ["COQUI_TOS_AGREED"] = "1"
|
||||||
@@ -107,20 +107,22 @@ class CoquiTTSEngine(BaseTTSEngine):
|
|||||||
self.tts.to(device)
|
self.tts.to(device)
|
||||||
|
|
||||||
def synthesize(self, text: str, path: str):
|
def synthesize(self, text: str, path: str):
|
||||||
"""
|
"""
|
||||||
Synthesizes the given text into speech and saves it to the specified file path.
|
Synthesizes the given text into speech and saves it to the specified file path.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
text (str): The text to synthesize into speech.
|
text (str): The text to synthesize into speech.
|
||||||
path (str): The file path to save the synthesized speech.
|
path (str): The file path to save the synthesized speech.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
float: The time taken to synthesize the speech with whispering effect.
|
float: The time taken to synthesize the speech with whispering effect.
|
||||||
"""
|
"""
|
||||||
self.tts.tts_to_file(text=text, file_path=path, lang=self.language, speaker=self.voice)
|
self.tts.tts_to_file(
|
||||||
if self.to_force_duration:
|
text=text, file_path=path, lang=self.language, speaker=self.voice
|
||||||
self.force_duration(float(self.duration), path)
|
)
|
||||||
return self.time_with_whisper(path)
|
if self.to_force_duration:
|
||||||
|
self.force_duration(float(self.duration), path)
|
||||||
|
return self.time_with_whisper(path)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_options(cls) -> list:
|
def get_options(cls) -> list:
|
||||||
@@ -138,12 +140,20 @@ class CoquiTTSEngine(BaseTTSEngine):
|
|||||||
value=cls.languages[0],
|
value=cls.languages[0],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
duration_checkbox = gr.Checkbox(label="Force duration", info="Force the duration of the generated audio to be at most the specified value", value=False)
|
duration_checkbox = gr.Checkbox(
|
||||||
duration = gr.Number(label="Duration [s]", value=57, step=1, minimum=10, visible=False)
|
label="Force duration",
|
||||||
|
info="Force the duration of the generated audio to be at most the specified value",
|
||||||
|
value=False,
|
||||||
|
)
|
||||||
|
duration = gr.Number(
|
||||||
|
label="Duration [s]", value=57, step=1, minimum=10, visible=False
|
||||||
|
)
|
||||||
duration_switch = lambda x: gr.update(visible=x)
|
duration_switch = lambda x: gr.update(visible=x)
|
||||||
duration_checkbox.change(duration_switch, inputs=[duration_checkbox], outputs=[duration])
|
duration_checkbox.change(
|
||||||
|
duration_switch, inputs=[duration_checkbox], outputs=[duration]
|
||||||
|
)
|
||||||
|
|
||||||
options.append(duration_checkbox)
|
options.append(duration_checkbox)
|
||||||
options.append(duration)
|
options.append(duration)
|
||||||
return options
|
return options
|
||||||
|
|||||||
Reference in New Issue
Block a user