reformatted and removed comments
Browse files
app.py
CHANGED
|
@@ -38,7 +38,6 @@ print(model.device)
|
|
| 38 |
|
| 39 |
# Whisper - speech-to-text
|
| 40 |
def whisper_stt(audio):
|
| 41 |
-
print("Inside Whisper TTS")
|
| 42 |
# load audio and pad/trim it to fit 30 seconds
|
| 43 |
audio = whisper.load_audio(audio)
|
| 44 |
audio = whisper.pad_or_trim(audio)
|
|
@@ -65,32 +64,32 @@ def whisper_stt(audio):
|
|
| 65 |
|
| 66 |
# Coqui - Text-to-Speech
|
| 67 |
def tts(text: str, model_name: str):
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
|
| 95 |
def engine(audio, context):
|
| 96 |
# Get voice query to text
|
|
@@ -140,7 +139,5 @@ with demo:
|
|
| 140 |
|
| 141 |
b1.click(engine, inputs=[in_audio, in_context], outputs=[out_query, out_textbox, out_audio])
|
| 142 |
|
| 143 |
-
#with gr.Row():
|
| 144 |
-
# gr.Markdown("")
|
| 145 |
|
| 146 |
demo.launch(enable_queue=True, debug=True)
|
|
|
|
| 38 |
|
| 39 |
# Whisper - speech-to-text
|
| 40 |
def whisper_stt(audio):
|
|
|
|
| 41 |
# load audio and pad/trim it to fit 30 seconds
|
| 42 |
audio = whisper.load_audio(audio)
|
| 43 |
audio = whisper.pad_or_trim(audio)
|
|
|
|
| 64 |
|
| 65 |
# Coqui - Text-to-Speech
|
| 66 |
def tts(text: str, model_name: str):
|
| 67 |
+
if len(text) > MAX_TXT_LEN:
|
| 68 |
+
text = text[:MAX_TXT_LEN]
|
| 69 |
+
print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
|
| 70 |
+
print(text, model_name)
|
| 71 |
+
# download model
|
| 72 |
+
model_path, config_path, model_item = tts_manager.download_model(f"tts_models/{model_name}")
|
| 73 |
+
vocoder_name: Optional[str] = model_item["default_vocoder"]
|
| 74 |
+
# download vocoder
|
| 75 |
+
vocoder_path = None
|
| 76 |
+
vocoder_config_path = None
|
| 77 |
+
if vocoder_name is not None:
|
| 78 |
+
vocoder_path, vocoder_config_path, _ = tts_manager.download_model(vocoder_name)
|
| 79 |
+
# init synthesizer
|
| 80 |
+
synthesizer = Synthesizer(
|
| 81 |
+
model_path, config_path, None, None, vocoder_path, vocoder_config_path,
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
# synthesize
|
| 85 |
+
if synthesizer is None:
|
| 86 |
+
raise NameError("model not found")
|
| 87 |
+
wavs = synthesizer.tts(text)
|
| 88 |
+
|
| 89 |
+
# return output
|
| 90 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
| 91 |
+
synthesizer.save_wav(wavs, fp)
|
| 92 |
+
return fp.name
|
| 93 |
|
| 94 |
def engine(audio, context):
|
| 95 |
# Get voice query to text
|
|
|
|
| 139 |
|
| 140 |
b1.click(engine, inputs=[in_audio, in_context], outputs=[out_query, out_textbox, out_audio])
|
| 141 |
|
|
|
|
|
|
|
| 142 |
|
| 143 |
demo.launch(enable_queue=True, debug=True)
|