Fix import, fix option indices in init, formatting

This commit is contained in:
2024-02-15 17:52:19 +01:00
parent c57817df85
commit 67237a5ecf

View File

@@ -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"
@@ -117,7 +117,9 @@ class CoquiTTSEngine(BaseTTSEngine):
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(
text=text, file_path=path, lang=self.language, speaker=self.voice
)
if self.to_force_duration: if self.to_force_duration:
self.force_duration(float(self.duration), path) self.force_duration(float(self.duration), path)
return self.time_with_whisper(path) return self.time_with_whisper(path)
@@ -139,10 +141,18 @@ class CoquiTTSEngine(BaseTTSEngine):
), ),
] ]
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)