Spaces:
Running
Running
Update app.py
Browse files7 unmodified lines8910111213141 unmodified line16171819202122232425262728293022 unmodified lines5354555657587 unmodified linesvoices = await edge_tts.list_voices()return {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}async def text_to_speech(text, voice, rate, pitch):if not text.strip():return None, "Please enter text to convert."if not voice:1 unmodified linevoice_short_name = voice.split(" - ")[0]rate_str = f"{rate:+d}%"pitch_str = f"{pitch:+d}Hz"communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, pitch=pitch_str)with 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, None22 unmodified linesgr.Textbox(label="Input Text", lines=5),gr.Dropdown(choices=[""] + list(voices.keys()), label="Select Voice", value=""),gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Rate Adjustment (%)", step=1),gr.Slider(minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1)],outputs=[7 unmodified lines8910111213141 unmodified line1617181920212223242526272829303122 unmodified lines545556575859607 unmodified linesvoices = await edge_tts.list_voices()return {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}async def text_to_speech(text, voice, rate, volume, pitch):if not text.strip():return None, "Please enter text to convert."if not voice:1 unmodified linevoice_short_name = voice.split(" - ")[0]rate_str = f"{rate:+d}%"volume_str = f"{volume:+d}%"pitch_str = f"{pitch:+d}Hz"communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, volume=volume_str, pitch=pitch_str)with 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, volume, pitch):audio, warning = await text_to_speech(text, voice, rate, volume, pitch)if warning:return audio, gr.Warning(warning)return audio, None22 unmodified linesgr.Textbox(label="Input Text", lines=5),gr.Dropdown(choices=[""] + list(voices.keys()), label="Select Voice", value=""),gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Rate Adjustment (%)", step=1),gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Volume Adjustment (%)", step=1),gr.Slider(minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1)],outputs=[
app.py+6-4