| import gradio as gr |
| import gtts |
| import io |
|
|
| def text_to_speech(text): |
| if text: |
| try: |
| |
| speech = gtts.gTTS(text) |
| mp3_data = io.BytesIO() |
| speech.save(mp3_data) |
| mp3_data.seek(0) |
| return mp3_data.getvalue() |
| except Exception as e: |
| return str(e) |
| else: |
| return None |
|
|
| iface = gr.Interface( |
| fn=text_to_speech, |
| inputs=gr.inputs.Text(default="Enter text here...", label="Input Text"), |
| outputs=gr.outputs.Audio(label="Voice"), |
| title="Text to Speech", |
| description="Enter text and click 'Generate' to convert it to speech.", |
| theme="blue", |
| live=False, |
| ) |
|
|
| iface.launch() |
|
|