Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from gtts import gTTS | |
| # Function to convert text to speech | |
| def text_to_speech_with_gtts(text, language='hi'): | |
| try: | |
| # Generate speech using gTTS | |
| tts = gTTS(text=text, lang=language, slow=False) | |
| output_file = "output.mp3" | |
| tts.save(output_file) | |
| return output_file # Return the file path for download | |
| except Exception as e: | |
| return f"An error occurred: {e}" | |
| # Gradio Interface | |
| iface = gr.Interface( | |
| fn=text_to_speech_with_gtts, | |
| inputs=[ | |
| gr.Textbox(lines=15, label="Enter the Full Story", placeholder="Type or paste your story here..."), | |
| gr.Textbox(label="Language Code (e.g., 'en', 'hi')", value='hi') | |
| ], | |
| outputs=gr.File(label="Download MP3"), | |
| title="Story to Speech Converter", | |
| description="Convert your story to speech using gTTS. Enter your text and download the MP3 file." | |
| ) | |
| # Launch Gradio Interface | |
| if __name__ == "__main__": | |
| iface.launch() | |