ai-tts-real / app.py
WeVi's picture
Update app.py
2f86cf8 verified
import gradio as gr
import asyncio
import edge_tts
import nest_asyncio
nest_asyncio.apply()
# Voice options
voices = {
"Hindi - Swara (Female)": "hi-IN-SwaraNeural",
"Hindi - Mohan (Male)": "hi-IN-MohanNeural",
"English - Jenny (Female)": "en-US-JennyNeural",
"English - Guy (Male)": "en-US-GuyNeural",
"Indian English - Neerja (Female)": "en-IN-NeerjaNeural",
"Indian English - Prabhat (Male)": "en-IN-PrabhatNeural"
}
# Async function to generate voice
async def tts(text, voice_label, rate):
voice = voices[voice_label]
rate_str = f"{'+' if rate >= 0 else ''}{int(rate)}%"
output_file = "voice.mp3"
communicate = edge_tts.Communicate(text=text, voice=voice, rate=rate_str)
await communicate.save(output_file)
return output_file
# Sync wrapper for Gradio
def generate_voice(text, voice, rate):
return asyncio.run(tts(text, voice, rate))
# Gradio UI
interface = gr.Interface(
fn=generate_voice,
inputs=[
gr.Textbox(label="๐ŸŽ™๏ธ Enter Your Script Text", placeholder="Type your text here...", lines=4),
gr.Dropdown(choices=list(voices.keys()), label="๐Ÿ—ฃ๏ธ Select Voice", value="Hindi - Swara (Female)"),
gr.Slider(minimum=-50, maximum=50, step=5, value=0, label="โš™๏ธ Rate (Speed %)"),
],
outputs=gr.Audio(type="filepath", label="๐Ÿ”Š Output Voice"),
title="๐Ÿง  AI Voice Generator",
description="Generate realistic Hindi & English voices using Microsoft edge-tts engine"
)
interface.launch()