| import gradio as gr |
| import gtts |
| from gtts.lang import tts_langs |
|
|
| def tts_interface(input_text, voice): |
| l,v = voice |
| tts = gtts.gTTS(text=input_text, lang=l) |
| tts.save("output.mp3") |
| return "output.mp3" |
|
|
| iface = gr.Interface( |
| fn=tts_interface, |
| inputs=[gr.inputs.Textbox(lines=5), gr.inputs.Dropdown(choices=[(k, v) for k, v in tts_langs().items()])], |
| outputs=gr.outputs.Audio(type="filepath"), |
| title="Text-to-Speech Converter", |
| description="Enter a text and get its spoken version as an MP3 file." |
| ) |
|
|
| iface.launch() |