Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -39,7 +39,7 @@ async def paragraph_to_speech(text, voice, rate, pitch):
|
|
39 |
prefix = match.group(1)
|
40 |
pitch_mod_str = match.group(2)
|
41 |
text2 = text[len(match.group(0)):] # Remove the prefix and optional pitch modifier
|
42 |
-
|
43 |
if prefix == "1F":
|
44 |
voice_short_name = voice1F.split(" - ")[0]
|
45 |
elif prefix == "1M":
|
@@ -70,11 +70,16 @@ async def paragraph_to_speech(text, voice, rate, pitch):
|
|
70 |
current_pitch = 70 # Default pitch for the child voice
|
71 |
|
72 |
pitch_str = f"{current_pitch:+d}Hz"
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
# Main text-to-speech function that processes paragraphs
|
80 |
async def text_to_speech(text, voice, rate, pitch):
|
|
|
39 |
prefix = match.group(1)
|
40 |
pitch_mod_str = match.group(2)
|
41 |
text2 = text[len(match.group(0)):] # Remove the prefix and optional pitch modifier
|
42 |
+
print(f">>>Processing text: '{text}'")
|
43 |
if prefix == "1F":
|
44 |
voice_short_name = voice1F.split(" - ")[0]
|
45 |
elif prefix == "1M":
|
|
|
70 |
current_pitch = 70 # Default pitch for the child voice
|
71 |
|
72 |
pitch_str = f"{current_pitch:+d}Hz"
|
73 |
+
try:
|
74 |
+
communicate = edge_tts.Communicate(text2, voice_short_name, rate=rate_str, pitch=pitch_str)
|
75 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
76 |
+
tmp_path = tmp_file.name
|
77 |
+
await communicate.save(tmp_path)
|
78 |
+
return tmp_path
|
79 |
+
except Exception as e:
|
80 |
+
print(f"Edge TTS error processing '{processed_text}': {e}")
|
81 |
+
return None
|
82 |
+
#return None
|
83 |
|
84 |
# Main text-to-speech function that processes paragraphs
|
85 |
async def text_to_speech(text, voice, rate, pitch):
|