File size: 1,017 Bytes
12ec115
4a1e036
cf3eeb6
c07bc42
 
12ec115
 
 
c07bc42
 
283162e
 
 
 
c07bc42
283162e
c07bc42
 
283162e
c07bc42
283162e
c07bc42
 
283162e
c07bc42
283162e
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
from transformers import pipeline

def tts_fn(text, lang_code):
    code = lang_code.strip().lower()
    model_id = f"facebook/mms-tts-{code}"
    try:
        tts = pipeline("text-to-speech", model=model_id)
        output = tts(text)
        return f"βœ… Model: {model_id}", (output["audio"], "output.wav")
    except Exception as e:
        return f"❌ Error: {str(e)}", None

with gr.Blocks() as demo:
    gr.Markdown("# 🌐 MMS-TTS by ISO Code\nJust enter language code like `mhr`, `bod`, `kaz`, etc.")
    with gr.Row():
        lang_code = gr.Textbox(label="Language Code (ISO 639-3)", placeholder="e.g. mhr")
        text = gr.Textbox(label="Text", placeholder="Enter text to synthesize")
    with gr.Row():
        button = gr.Button("Generate Speech")
    with gr.Row():
        out_text = gr.Textbox(label="Status")
        out_audio = gr.Audio(label="Audio Output", type="filepath")

    button.click(fn=tts_fn, inputs=[text, lang_code], outputs=[out_text, out_audio])

demo.launch()