Spaces:
Running
Running
File size: 966 Bytes
465fd1a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
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()
|