Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -126,23 +126,17 @@ def text_to_speech(text, audio_file=None):
|
|
| 126 |
with torch.no_grad():
|
| 127 |
speech = model.generate_speech(inputs["input_ids"], speaker_embeddings.unsqueeze(0), vocoder=vocoder)
|
| 128 |
|
| 129 |
-
# Convert the generated speech to numpy array format
|
| 130 |
speech_np = speech.cpu().numpy()
|
|
|
|
|
|
|
| 131 |
|
| 132 |
-
# Save the speech to a temporary file in WAV format
|
| 133 |
-
output_file = "output.wav"
|
| 134 |
-
sf.write(output_file, speech_np, 16000)
|
| 135 |
-
|
| 136 |
-
# Return the path to the audio file
|
| 137 |
-
return output_file
|
| 138 |
-
|
| 139 |
iface = gr.Interface(
|
| 140 |
fn=text_to_speech,
|
| 141 |
inputs=[
|
| 142 |
gr.Textbox(label="Enter Turkish text to convert to speech")
|
| 143 |
],
|
| 144 |
outputs=[
|
| 145 |
-
gr.Audio(label="Generated Speech")
|
| 146 |
],
|
| 147 |
title="Turkish SpeechT5 Text-to-Speech Demo",
|
| 148 |
description="Enter Turkish text, and listen to the generated speech."
|
|
|
|
| 126 |
with torch.no_grad():
|
| 127 |
speech = model.generate_speech(inputs["input_ids"], speaker_embeddings.unsqueeze(0), vocoder=vocoder)
|
| 128 |
|
|
|
|
| 129 |
speech_np = speech.cpu().numpy()
|
| 130 |
+
speech_np = speech_np / np.max(np.abs(speech_np))
|
| 131 |
+
return (16000, speech_np)
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
iface = gr.Interface(
|
| 134 |
fn=text_to_speech,
|
| 135 |
inputs=[
|
| 136 |
gr.Textbox(label="Enter Turkish text to convert to speech")
|
| 137 |
],
|
| 138 |
outputs=[
|
| 139 |
+
gr.Audio(label="Generated Speech", type="numpy")
|
| 140 |
],
|
| 141 |
title="Turkish SpeechT5 Text-to-Speech Demo",
|
| 142 |
description="Enter Turkish text, and listen to the generated speech."
|