Spaces:
Sleeping
Sleeping
Update app.py
Browse files1 unmodified line2345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758176 unmodified lines235236237238239240241242243244245246109 unmodified lines3563573583593603613623633643653663673683693701 unmodified lineimport edge_ttsimport asyncioimport tempfileimport os# -----------------------------# Core TTS helpers# -----------------------------async def get_voices():voices = await edge_tts.list_voices()# Keep label style similar to ElevenLabs voice list (clean, informative)voice_labels = [f"{v['ShortName']} - {v['Locale']} ({v['Gender']})"for v in voices]# Sort alphabetically for nicer UIvoice_labels.sort()return voice_labelsasync def text_to_speech(text, voice, rate, pitch):if not text.strip():return None, "Please enter some text to synthesize."if not voice:return None, "Please select a voice."# Voice label is like: "en-US-AriaNeural - en-US (Female)"voice_short_name = voice.split(" - ")[0].strip()rate_str = f"{rate:+d}%"pitch_str = f"{pitch:+d}Hz"communicate = edge_tts.Communicate(text=text,voice=voice_short_name,rate=rate_str,pitch=pitch_str,)# Save to temporary MP3 filewith tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:tmp_path = tmp_file.nameawait communicate.save(tmp_path)return tmp_path, Noneasync def tts_interface(text, voice, rate, pitch):audio, warning = await text_to_speech(text, voice, rate, pitch)if warning:return audio, gr.Warning(warning)return audio, None# -----------------------------# Eburon Speech – ElevenLabs-like UI# -----------------------------EBURON_CSS = """body {176 unmodified lines}"""async def create_demo():voices = await get_voices()with gr.Blocks(analytics_enabled=False,css=EBURON_CSS,title="Eburon Speech Studio") as demo:# Header109 unmodified linesgenerate_btn.click(fn=tts_interface,inputs=[text_input, voice_dropdown, rate_slider, pitch_slider],outputs=[audio_output, warning_md])return demoasync def main():demo = await create_demo()demo.queue(default_concurrency_limit=50)demo.launch(show_api=False)if __name__ == "__main__":asyncio.run(main())1 unmodified line2345678910176 unmodified lines187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250109 unmodified lines3603613623633643653663673683693703713723733743753763773783793803811 unmodified lineimport edge_ttsimport asyncioimport tempfile# -----------------------------# Custom CSS for Eburon Speech UI# -----------------------------EBURON_CSS = """body {176 unmodified lines}"""# -----------------------------# Core TTS helpers# -----------------------------async def get_voices():voices = await edge_tts.list_voices()voice_labels = [f"{v['ShortName']} - {v['Locale']} ({v['Gender']})"for v in voices]voice_labels.sort()return voice_labelsasync def text_to_speech(text, voice, rate, pitch):if not text.strip():return None, "Please enter some text to synthesize."if not voice:return None, "Please select a voice."# Voice label: "en-US-AriaNeural - en-US (Female)"voice_short_name = voice.split(" - ")[0].strip()rate_str = f"{rate:+d}%"pitch_str = f"{pitch:+d}Hz"communicate = edge_tts.Communicate(text=text,voice=voice_short_name,rate=rate_str,pitch=pitch_str,)# Save to temporary MP3 filewith tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:tmp_path = tmp_file.nameawait communicate.save(tmp_path)return tmp_path, Noneasync def tts_interface(text, voice, rate, pitch):audio, warning = await text_to_speech(text, voice, rate, pitch)if warning:# Gradio 6: Warning modal objectreturn audio, gr.Warning(warning)return audio, None# -----------------------------# Eburon Speech – ElevenLabs-like UI# -----------------------------async def create_demo():voices = await get_voices()# Gradio 6: do NOT pass css to Blocks, move it to demo.launch()with gr.Blocks(analytics_enabled=False,title="Eburon Speech Studio") as demo:# Header109 unmodified linesgenerate_btn.click(fn=tts_interface,inputs=[text_input, voice_dropdown, rate_slider, pitch_slider],outputs=[audio_output, warning_md],)return demoasync def main():demo = await create_demo()demo.queue(default_concurrency_limit=50)# Gradio 6: css + footer_links go in launch(), show_api is removeddemo.launch(css=EBURON_CSS,footer_links=["gradio", "settings"], # hides API link (like show_api=False))if __name__ == "__main__":asyncio.run(main())
app.py+63-52