| 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() |