Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ async def get_voices():
|
|
8 |
voices = await edge_tts.list_voices()
|
9 |
return {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}
|
10 |
|
11 |
-
async def text_to_speech(text, voice, rate, pitch):
|
12 |
if not text.strip():
|
13 |
return None, "Please enter text to convert."
|
14 |
if not voice:
|
@@ -16,15 +16,16 @@ async def text_to_speech(text, voice, rate, pitch):
|
|
16 |
|
17 |
voice_short_name = voice.split(" - ")[0]
|
18 |
rate_str = f"{rate:+d}%"
|
|
|
19 |
pitch_str = f"{pitch:+d}Hz"
|
20 |
-
communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, pitch=pitch_str)
|
21 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
22 |
tmp_path = tmp_file.name
|
23 |
await communicate.save(tmp_path)
|
24 |
return tmp_path, None
|
25 |
|
26 |
-
async def tts_interface(text, voice, rate, pitch):
|
27 |
-
audio, warning = await text_to_speech(text, voice, rate, pitch)
|
28 |
if warning:
|
29 |
return audio, gr.Warning(warning)
|
30 |
return audio, None
|
@@ -53,6 +54,7 @@ async def create_demo():
|
|
53 |
gr.Textbox(label="Input Text", lines=5),
|
54 |
gr.Dropdown(choices=[""] + list(voices.keys()), label="Select Voice", value=""),
|
55 |
gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Rate Adjustment (%)", step=1),
|
|
|
56 |
gr.Slider(minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1)
|
57 |
],
|
58 |
outputs=[
|
|
|
8 |
voices = await edge_tts.list_voices()
|
9 |
return {f"{v['ShortName']} - {v['Locale']} ({v['Gender']})": v['ShortName'] for v in voices}
|
10 |
|
11 |
+
async def text_to_speech(text, voice, rate, volume, pitch):
|
12 |
if not text.strip():
|
13 |
return None, "Please enter text to convert."
|
14 |
if not voice:
|
|
|
16 |
|
17 |
voice_short_name = voice.split(" - ")[0]
|
18 |
rate_str = f"{rate:+d}%"
|
19 |
+
volume_str = f"{volume:+d}%"
|
20 |
pitch_str = f"{pitch:+d}Hz"
|
21 |
+
communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, volume=volume_str, pitch=pitch_str)
|
22 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
23 |
tmp_path = tmp_file.name
|
24 |
await communicate.save(tmp_path)
|
25 |
return tmp_path, None
|
26 |
|
27 |
+
async def tts_interface(text, voice, rate, volume, pitch):
|
28 |
+
audio, warning = await text_to_speech(text, voice, rate, volume, pitch)
|
29 |
if warning:
|
30 |
return audio, gr.Warning(warning)
|
31 |
return audio, None
|
|
|
54 |
gr.Textbox(label="Input Text", lines=5),
|
55 |
gr.Dropdown(choices=[""] + list(voices.keys()), label="Select Voice", value=""),
|
56 |
gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Rate Adjustment (%)", step=1),
|
57 |
+
gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Volume Adjustment (%)", step=1),
|
58 |
gr.Slider(minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1)
|
59 |
],
|
60 |
outputs=[
|