Download app.py from son10401/Voice: direct link, hf CLI and curl.
- Browser
- Download file 2.76 kB
-
https://huggingface.co/spaces/son10401/Voice/resolve/main/app.py
- Command line
-
hf download hf://spaces/son10401/Voice/app.py
-
curl -L -o app.py https://huggingface.co/spaces/son10401/Voice/resolve/main/app.py
2.76 kB
| import sys | |
| import subprocess | |
| try: | |
| import edge_tts | |
| except ImportError: | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", "edge-tts"]) | |
| import edge_tts | |
| try: | |
| import spaces | |
| except ImportError: | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", "spaces"]) | |
| import spaces | |
| import asyncio | |
| import gradio as gr | |
| VOICES = { | |
| "မမမြ (Mya Mya) - Female (Myanmar)": "my-MM-NilarNeural", | |
| "ဦးကျော် (U Kyaw) - Male (Myanmar)": "my-MM-ThihaNeural", | |
| "Jenny - Female (US English)": "en-US-JennyNeural", | |
| "Guy - Male (US English)": "en-US-GuyNeural" | |
| } | |
| async def generate_edge_tts(text, voice_name, rate_speed): | |
| if not text or not text.strip(): | |
| return None, "⚠️ စာသား ထည့်ပါ" | |
| try: | |
| voice = VOICES.get(voice_name, "my-MM-NilarNeural") | |
| speed_str = f"{rate_speed:+d}%" if rate_speed != 0 else "+0%" | |
| output_file = "output.mp3" | |
| communicate = edge_tts.Communicate(text, voice, rate=speed_str) | |
| await communicate.save(output_file) | |
| return output_file, "✅ Audio ထုတ်ယူပြီးပါပြီ" | |
| except Exception as e: | |
| return None, f"Error: {str(e)}" | |
| def process_tts(text, voice_name, rate_speed): | |
| return asyncio.run(generate_edge_tts(text, voice_name, rate_speed)) | |
| with gr.Blocks() as app: | |
| gr.Markdown("# 🇲🇲 Myanmar & English Free TTS Studio") | |
| with gr.Row(): | |
| with gr.Column(): | |
| text_input = gr.Textbox( | |
| label="စာသား ရိုက်ထည့်ရန် (Input Text)", | |
| placeholder="မြန်မာ သို့မဟုတ် English စာသား ရိုက်ထည့်ပါ...", | |
| lines=8 | |
| ) | |
| voice_select = gr.Dropdown( | |
| label="အသံရွေးချယ်ရန် (Voice)", | |
| choices=list(VOICES.keys()), | |
| value="မမမြ (Mya Mya) - Female (Myanmar)" | |
| ) | |
| speed_slider = gr.Slider( | |
| label="အသံအနှေးအမြန် (Speed Rate %)", | |
| minimum=-50, | |
| maximum=50, | |
| value=0, | |
| step=5 | |
| ) | |
| generate_btn = gr.Button("🚀 Generate Audio", variant="primary") | |
| with gr.Column(): | |
| status_output = gr.Textbox(label="Status", interactive=False) | |
| audio_output = gr.Audio(label="Generated Audio", type="filepath") | |
| generate_btn.click( | |
| fn=process_tts, | |
| inputs=[text_input, voice_select, speed_slider], | |
| outputs=[audio_output, status_output] | |
| ) | |
| app.queue().launch(ssr_mode=False) | |