| import gradio as gr |
| from gtts import gTTS |
| import os |
|
|
| def text_to_speech(text): |
| if not text.strip(): |
| return None |
| tts = gTTS(text=text, lang="en") |
| file_path = "output.mp3" |
| tts.save(file_path) |
| |
| return file_path |
|
|
|
|
| with gr.Blocks() as demo: |
| gr.Markdown("## 🗣️ Text to Speech App") |
| text_input = gr.Textbox(label="Enter your text", placeholder="Type something...") |
| output_audio = gr.Audio(label="Generated Voice", type="filepath") |
| submit_btn = gr.Button("🔊 Submit") |
| |
| submit_btn.click(fn=text_to_speech, inputs=text_input, outputs=output_audio) |
|
|
| demo.launch(show_error=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |