Inial commited on
Commit
c07bc42
·
verified ·
1 Parent(s): 607b268

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -1,27 +1,27 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- def tts_fn(text, language_iso_code):
5
- code = language_iso_code.strip().lower()
6
  model_id = f"facebook/mms-tts-{code}"
7
  try:
8
  tts = pipeline("text-to-speech", model=model_id)
9
- out = tts(text)
10
- return f"✅ Model: {model_id}", (out["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: 1100+ Languages (ISO Code Input Only)")
16
  with gr.Row():
17
- language = gr.Textbox(label="Language ISO Code (e.g. eng, mhr, bod)", placeholder="Enter ISO code here")
18
- text = gr.Textbox(label="Enter your text", placeholder="Type something here…")
19
  with gr.Row():
20
- btn = gr.Button("Speak")
21
  with gr.Row():
22
- out_text = gr.Textbox(label="Info")
23
- out_audio = gr.Audio(label="Audio", type="filepath")
24
 
25
- btn.click(fn=tts_fn, inputs=[text, language], outputs=[out_text, out_audio])
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()