Spaces:
Sleeping
Sleeping
| from gtts import gTTS | |
| import gradio as gr | |
| import tempfile | |
| def text_to_speech(text, lang='en', slow=False): | |
| try: | |
| # Create temporary file | |
| with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp: | |
| tts = gTTS(text=text, lang=lang, slow=slow) | |
| tts.save(tmp.name) | |
| return tmp.name | |
| except Exception as e: | |
| return f"❌ Error: {str(e)}" | |
| iface = gr.Interface( | |
| fn=text_to_speech, | |
| inputs=[ | |
| gr.Textbox(label="Enter text", placeholder="Type something..."), | |
| gr.Dropdown(choices=["en", "es", "fr", "de", "ur", "hi"], value="en", label="Language"), | |
| gr.Checkbox(label="Slow mode") | |
| ], | |
| outputs=gr.Audio(type="filepath", label="Generated Audio"), | |
| title="🗣️ Text-to-Speech Converter", | |
| description="Converts text into speech using Google TTS (gTTS)." | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() |