| import asyncio | |
| import tempfile | |
| import gradio as gr | |
| import edge_tts | |
| VOICE = "de-DE-KatjaNeural" | |
| def synthesize(text: str) -> str: | |
| async def run(): | |
| communicate = edge_tts.Communicate(text, VOICE) | |
| with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as f: | |
| path = f.name | |
| await communicate.save(path) | |
| return path | |
| return asyncio.run(run()) | |
| demo = gr.Interface( | |
| fn=synthesize, | |
| inputs=gr.Textbox(label="Text"), | |
| outputs=gr.Audio(label="Audio"), | |
| api_name="synthesize", | |
| title="Witz TTS", | |
| description="German TTS via Microsoft Edge neural voice (de-DE-KatjaNeural).", | |
| ) | |
| demo.launch() | |