my-tts-api / app.py
prerna-AI's picture
Update app.py
0e5ce44 verified
Raw History Blame Contribute Delete
601 Bytes
import gradio as gr
from gtts import gTTS
import tempfile
def tts(text, lang="en"):
if not text:
return None
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as f:
tts = gTTS(text=text, lang=lang)
tts.save(f.name)
return f.name
iface = gr.Interface(
fn=tts,
inputs=[gr.Textbox(label="Text to Speak"), gr.Textbox(label="Language (default=en)")],
outputs=gr.Audio(type="filepath"),
title="My Free TTS API",
description="Enter text and get an MP3 using gTTS."
)
iface.launch(server_name="0.0.0.0", server_port=7860, share=True)