Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from TTS.api import TTS
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC")
|
| 8 |
|
| 9 |
-
# 2️⃣ Text to speech function
|
| 10 |
def text_to_speech(text):
|
| 11 |
if not text.strip():
|
| 12 |
return None, "Please enter text."
|
| 13 |
-
|
| 14 |
-
# Save audio in /tmp (Hugging Face safe path)
|
| 15 |
output_path = "/tmp/output.wav"
|
| 16 |
-
|
| 17 |
try:
|
| 18 |
tts.tts_to_file(text=text, file_path=output_path)
|
| 19 |
return output_path, None
|
| 20 |
except Exception as e:
|
| 21 |
-
return None, f"TTS
|
| 22 |
|
| 23 |
-
# 3️⃣ Gradio Interface
|
| 24 |
with gr.Blocks() as demo:
|
| 25 |
-
gr.Markdown("# 🎙️ Hugging Face TTS Demo")
|
| 26 |
-
|
| 27 |
text_input = gr.Textbox(label="Enter Text", lines=5)
|
| 28 |
audio_output = gr.Audio(label="Generated Speech", type="filepath")
|
| 29 |
warning_md = gr.Markdown("", visible=True)
|
| 30 |
-
|
| 31 |
generate_btn = gr.Button("Generate Speech")
|
| 32 |
generate_btn.click(fn=text_to_speech, inputs=text_input, outputs=[audio_output, warning_md])
|
| 33 |
-
|
| 34 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from TTS.api import TTS
|
|
|
|
| 3 |
|
| 4 |
+
# Load Hugging Face TTS model
|
| 5 |
+
tts = TTS("tts_models/en/ljspeech/tacotron2-DDC")
|
|
|
|
| 6 |
|
|
|
|
| 7 |
def text_to_speech(text):
|
| 8 |
if not text.strip():
|
| 9 |
return None, "Please enter text."
|
|
|
|
|
|
|
| 10 |
output_path = "/tmp/output.wav"
|
|
|
|
| 11 |
try:
|
| 12 |
tts.tts_to_file(text=text, file_path=output_path)
|
| 13 |
return output_path, None
|
| 14 |
except Exception as e:
|
| 15 |
+
return None, f"TTS failed: {e}"
|
| 16 |
|
|
|
|
| 17 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
| 18 |
text_input = gr.Textbox(label="Enter Text", lines=5)
|
| 19 |
audio_output = gr.Audio(label="Generated Speech", type="filepath")
|
| 20 |
warning_md = gr.Markdown("", visible=True)
|
|
|
|
| 21 |
generate_btn = gr.Button("Generate Speech")
|
| 22 |
generate_btn.click(fn=text_to_speech, inputs=text_input, outputs=[audio_output, warning_md])
|
| 23 |
+
|
| 24 |
demo.launch()
|