Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
def tts_fn(text,
|
| 5 |
-
code =
|
| 6 |
model_id = f"facebook/mms-tts-{code}"
|
| 7 |
try:
|
| 8 |
tts = pipeline("text-to-speech", model=model_id)
|
| 9 |
-
|
| 10 |
-
return f"✅ Model: {model_id}", (
|
| 11 |
except Exception as e:
|
| 12 |
return f"❌ Error: {str(e)}", None
|
| 13 |
|
| 14 |
with gr.Blocks() as demo:
|
| 15 |
-
gr.Markdown("# 🌐 MMS-TTS
|
| 16 |
with gr.Row():
|
| 17 |
-
|
| 18 |
-
text = gr.Textbox(label="
|
| 19 |
with gr.Row():
|
| 20 |
-
|
| 21 |
with gr.Row():
|
| 22 |
-
out_text = gr.Textbox(label="
|
| 23 |
-
out_audio = gr.Audio(label="Audio", type="filepath")
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
def tts_fn(text, lang_code):
|
| 5 |
+
code = lang_code.strip().lower()
|
| 6 |
model_id = f"facebook/mms-tts-{code}"
|
| 7 |
try:
|
| 8 |
tts = pipeline("text-to-speech", model=model_id)
|
| 9 |
+
output = tts(text)
|
| 10 |
+
return f"✅ Model: {model_id}", (output["audio"], "output.wav")
|
| 11 |
except Exception as e:
|
| 12 |
return f"❌ Error: {str(e)}", None
|
| 13 |
|
| 14 |
with gr.Blocks() as demo:
|
| 15 |
+
gr.Markdown("# 🌐 MMS-TTS by ISO Code\nJust enter language code like `mhr`, `bod`, `kaz`, etc.")
|
| 16 |
with gr.Row():
|
| 17 |
+
lang_code = gr.Textbox(label="Language Code (ISO 639-3)", placeholder="e.g. mhr")
|
| 18 |
+
text = gr.Textbox(label="Text", placeholder="Enter text to synthesize")
|
| 19 |
with gr.Row():
|
| 20 |
+
button = gr.Button("Generate Speech")
|
| 21 |
with gr.Row():
|
| 22 |
+
out_text = gr.Textbox(label="Status")
|
| 23 |
+
out_audio = gr.Audio(label="Audio Output", type="filepath")
|
| 24 |
|
| 25 |
+
button.click(fn=tts_fn, inputs=[text, lang_code], outputs=[out_text, out_audio])
|
| 26 |
|
| 27 |
demo.launch()
|