Blane_TTS / app.py
Blane187's picture
Update app.py
003c48c verified
import gradio as gr
import edge_tts
async def tts(text, language):
tts = edge_tts.Communicate(text, voice=language)
await tts.save("output.mp3")
return "output.mp3"
def generate_tts(text, language):
import asyncio
return asyncio.run(tts(text, language))
languages = {
"English": "en-US-JennyNeural",
"Indonesian": "id-ID-GadisNeural",
"Korean": "ko-KR-SunHiNeural",
"Japanese": "ja-JP-NanamiNeural",
"Malaysian": "ms-MY-OsmanNeural"
}
def get_audio_file(text, lang_key):
language = languages[lang_key]
return generate_tts(text, language)
with gr.Blocks(theme="Blane187/fuchsia") as demo:
gr.Markdown("# Blane TTS")
text_input = gr.Textbox(label="Input Text", lines=4)
language_input = gr.Dropdown(list(languages.keys()), label="Select Language")
tts_button = gr.Button("Generate TTS")
audio_output = gr.Audio(label="Generated Audio")
tts_button.click(get_audio_file, inputs=[text_input, language_input], outputs=audio_output)
demo.launch()