import edge_tts import gradio as gr import tempfile import anyio language_dict = { 'Abeo': 'en-NG-AbeoNeural', 'Ana': 'en-US-AnaNeural', 'Andrew': 'en-US-AndrewNeural', 'Aria': 'en-US-AriaNeural', 'Asilia': 'en-KE-AsiliaNeural', 'Ava': 'en-US-AvaNeural', 'Brian': 'en-US-BrianNeural', 'Christopher': 'en-US-ChristopherNeural', 'Chilemba': 'en-KE-ChilembaNeural', 'Clara': 'en-CA-ClaraNeural', 'Connor': 'en-IE-ConnorNeural', 'Emily': 'en-IE-EmilyNeural', 'Elimu': 'en-TZ-ElimuNeural', 'Emma': 'en-US-EmmaNeural', 'Eric': 'en-US-EricNeural', 'Ezinne': 'en-NG-EzinneNeural', 'Guy': 'en-US-GuyNeural', 'Imani': 'en-TZ-ImaniNeural', 'James': 'en-PH-JamesNeural', 'Jenny': 'en-US-JennyNeural', 'Leah': 'en-ZA-LeahNeural', 'Libby': 'en-GB-LibbyNeural', 'Liam': 'en-CA-LiamNeural', 'Luke': 'en-ZA-LukeNeural', 'Luna': 'en-SG-LunaNeural', 'Maisie': 'en-GB-MaisieNeural', 'Michelle': 'en-US-MichelleNeural', 'Mitchell': 'en-NZ-MitchellNeural', 'Molly': 'en-NZ-MollyNeural', 'Natasha': 'en-AU-NatashaNeural', 'Neerja': 'en-IN-NeerjaExpressiveNeural', 'Prabhat': 'en-IN-PrabhatNeural', 'Roger': 'en-US-RogerNeural', 'Rosa': 'en-PH-RosaNeural', 'Ryan': 'en-GB-RyanNeural', 'Sam': 'en-HK-SamNeural', 'Sonia': 'en-GB-SoniaNeural', 'Steffan': 'en-US-SteffanNeural', 'Thomas': 'en-GB-ThomasNeural', 'Wayne': 'en-SG-WayneNeural', 'William': 'en-AU-WilliamNeural', 'Yan': 'en-HK-YanNeural' } async def text_to_speech_edge(text, language_code): voice = language_dict.get(language_code, "default_voice") communicate = edge_tts.Communicate(text, voice) with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file: tmp_path = tmp_file.name await communicate.save(tmp_path) return f"Speech synthesis completed for: {text}", tmp_path input_text = gr.Textbox(lines=5, label="Input Text") output_text = gr.Textbox(label="Output Text") output_audio = gr.Audio(type="filepath", label="Exported Audio") language = gr.Dropdown(choices=list(language_dict.keys()), label="Choose the Voice Model") # Gradio interface iface = gr.Blocks() with iface: gr.Interface( fn=text_to_speech_edge, inputs=[input_text, language], outputs=[output_text, output_audio], title="Edge TTS", description="Microsoft Edge Text-To-Speech (Forked & Fixed Ilaria TTS)", ) iface.launch() if __name__ == "__main__": anyio.run(interface.launch, backend="asyncio")