Spaces:
Sleeping
Sleeping
adding female voice when paragraph starts with FF
Browse filesvoice1 = "en-HK-SamNeural - en-HK (Male)"
voice2 = "en-HK-YanNeural - en-HK (Female)"
if not text.strip():
return None
if text.startswith("FF"):
text2 = text[2:] # Remove the first two characters ("FF")
voice_short_name =voice2.split(" - ")[0]
else:
voice_short_name = voice.split(" - ")[0]
app.py
CHANGED
@@ -12,9 +12,15 @@ async def get_voices():
|
|
12 |
|
13 |
# Text-to-speech function for a single paragraph
|
14 |
async def paragraph_to_speech(text, voice, rate, pitch):
|
|
|
|
|
15 |
if not text.strip():
|
16 |
return None
|
17 |
-
|
|
|
|
|
|
|
|
|
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)
|
|
|
12 |
|
13 |
# Text-to-speech function for a single paragraph
|
14 |
async def paragraph_to_speech(text, voice, rate, pitch):
|
15 |
+
voice1 = "en-HK-SamNeural - en-HK (Male)"
|
16 |
+
voice2 = "en-HK-YanNeural - en-HK (Female)"
|
17 |
if not text.strip():
|
18 |
return None
|
19 |
+
if text.startswith("FF"):
|
20 |
+
text2 = text[2:] # Remove the first two characters ("FF")
|
21 |
+
voice_short_name =voice2.split(" - ")[0]
|
22 |
+
else:
|
23 |
+
voice_short_name = voice.split(" - ")[0]
|
24 |
rate_str = f"{rate:+d}%"
|
25 |
pitch_str = f"{pitch:+d}Hz"
|
26 |
communicate = edge_tts.Communicate(text, voice_short_name, rate=rate_str, pitch=pitch_str)
|