Spaces:
Running
Running
Update app.py
Browse files7 unmodified lines891011111213141 unmodified line1617181920202122232425262627272829303122 unmodified lines545556575859607 unmodified lines voices = 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):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 line voice_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, pitch=pitch_str) 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.name await communicate.save(tmp_path) return tmp_path, None
async def tts_interface(text, voice, rate, pitch): audio, warning = await text_to_speech(text, voice, rate, pitch)async 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 lines gr.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