kripeshAlt's picture
Update app.py
02540e4 verified
raw
history blame contribute delete
970 Bytes
import gradio as gr
import asyncio
import edge_tts
# Async function to generate TTS
async def generate_tts(text, voice="en-US-JennyNeural"):
output_path = "output.mp3"
communicate = edge_tts.Communicate(text, voice)
await communicate.save(output_path)
return output_path
# Gradio wrapper for async function
def tts_wrapper(text, voice):
return asyncio.run(generate_tts(text, voice))
# Available voice list (optional - you can expand this)
voices = [
"en-US-JennyNeural",
"en-US-GuyNeural",
"en-GB-LibbyNeural",
"en-IN-NeerjaNeural"
]
# Gradio Interface
gr.Interface(
fn=tts_wrapper,
inputs=[
gr.Textbox(label="Enter text to speak"),
gr.Dropdown(choices=voices, label="Choose Voice", value="en-US-JennyNeural")
],
outputs=gr.Audio(type="filepath", label="Generated Speech"),
title="Edge TTS with Gradio",
description="Enter text and get TTS audio using Microsoft Edge voices."
).launch()