Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,59 +48,70 @@ async def process_transcript_line(line, voice, rate, pitch):
|
|
48 |
if not text_with_commands.strip():
|
49 |
return start_time_ms, None
|
50 |
|
51 |
-
|
|
|
52 |
current_rate = rate
|
53 |
current_pitch = pitch
|
54 |
processed_text = text_with_commands
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
if text_with_commands.startswith("1F"):
|
68 |
-
|
69 |
current_pitch = 25
|
70 |
processed_text = text_with_commands[2:].strip()
|
71 |
elif text_with_commands.startswith("2F"):
|
72 |
-
|
73 |
processed_text = text_with_commands[2:].strip()
|
74 |
elif text_with_commands.startswith("3F"):
|
75 |
-
|
76 |
processed_text = text_with_commands[2:].strip()
|
77 |
elif text_with_commands.startswith("4F"):
|
78 |
-
|
79 |
processed_text = text_with_commands[2:].strip()
|
80 |
elif text_with_commands.startswith("1M"):
|
81 |
-
|
82 |
processed_text = text_with_commands[2:].strip()
|
83 |
elif text_with_commands.startswith("2M"):
|
84 |
-
|
85 |
processed_text = text_with_commands[2:].strip()
|
86 |
elif text_with_commands.startswith("3M"):
|
87 |
-
|
88 |
processed_text = text_with_commands[2:].strip()
|
89 |
elif text_with_commands.startswith("4M"):
|
90 |
-
|
91 |
processed_text = text_with_commands[2:].strip()
|
92 |
elif text_with_commands.startswith("1O"): # Old man voice
|
93 |
-
|
94 |
current_pitch = -20
|
95 |
current_rate = -10
|
96 |
processed_text = text_with_commands[2:].strip()
|
97 |
elif text_with_commands.startswith("1C"): #Child voice
|
98 |
-
|
99 |
processed_text = text_with_commands[2:].strip()
|
100 |
|
101 |
rate_str = f"{current_rate:+d}%"
|
102 |
pitch_str = f"{current_pitch:+d}Hz"
|
103 |
-
communicate = edge_tts.Communicate(processed_text,
|
104 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
105 |
audio_path = tmp_file.name
|
106 |
await communicate.save(audio_path)
|
|
|
48 |
if not text_with_commands.strip():
|
49 |
return start_time_ms, None
|
50 |
|
51 |
+
current_voice_full = voice # Store the full voice string from the dropdown
|
52 |
+
current_voice_short = current_voice_full.split(" - ")[0] if current_voice_full else ""
|
53 |
current_rate = rate
|
54 |
current_pitch = pitch
|
55 |
processed_text = text_with_commands
|
56 |
|
57 |
+
voice1_full = "en-AU-WilliamNeural - en-AU (Male)"
|
58 |
+
voice1_short = voice1_full.split(" - ")[0]
|
59 |
+
voice1F_full ="en-GB-SoniaNeural - en-GB (Female)"
|
60 |
+
voice1F_short = voice1F_full.split(" - ")[0]
|
61 |
+
voice2_full = "en-GB-RyanNeural - en-GB (Male)"
|
62 |
+
voice2_short = voice2_full.split(" - ")[0]
|
63 |
+
voice2F_full = "en-US-JennyNeural - en-US (Female)"
|
64 |
+
voice2F_short = voice2F_full.split(" - ")[0]
|
65 |
+
voice3_full ="en-US-BrianMultilingualNeural - en-US (Male)" #good for reading
|
66 |
+
voice3_short = voice3_full.split(" - ")[0]
|
67 |
+
voice3F_full = "en-HK-YanNeural - en-HK (Female)"
|
68 |
+
voice3F_short = voice3F_full.split(" - ")[0]
|
69 |
+
voice4_full = "en-GB-ThomasNeural - en-GB (Male)"
|
70 |
+
voice4_short = voice4_full.split(" - ")[0]
|
71 |
+
voice4F_full ="en-US-EmmaNeural - en-US (Female)"
|
72 |
+
voice4F_short = voice4F_full.split(" - ")[0]
|
73 |
+
voice5_full = "en-GB-RyanNeural - en-GB (Male)" #Old Man
|
74 |
+
voice5_short = voice5_full.split(" - ")[0]
|
75 |
+
voice6_full = "en-GB-MaisieNeural - en-GB (Female)" #Child
|
76 |
+
voice6_short = voice6_full.split(" - ")[0]
|
77 |
|
78 |
if text_with_commands.startswith("1F"):
|
79 |
+
current_voice_short = voice1F_short
|
80 |
current_pitch = 25
|
81 |
processed_text = text_with_commands[2:].strip()
|
82 |
elif text_with_commands.startswith("2F"):
|
83 |
+
current_voice_short = voice2F_short
|
84 |
processed_text = text_with_commands[2:].strip()
|
85 |
elif text_with_commands.startswith("3F"):
|
86 |
+
current_voice_short = voice3F_short
|
87 |
processed_text = text_with_commands[2:].strip()
|
88 |
elif text_with_commands.startswith("4F"):
|
89 |
+
current_voice_short = voice4F_short
|
90 |
processed_text = text_with_commands[2:].strip()
|
91 |
elif text_with_commands.startswith("1M"):
|
92 |
+
current_voice_short = voice1_short
|
93 |
processed_text = text_with_commands[2:].strip()
|
94 |
elif text_with_commands.startswith("2M"):
|
95 |
+
current_voice_short = voice2_short
|
96 |
processed_text = text_with_commands[2:].strip()
|
97 |
elif text_with_commands.startswith("3M"):
|
98 |
+
current_voice_short = voice3_short
|
99 |
processed_text = text_with_commands[2:].strip()
|
100 |
elif text_with_commands.startswith("4M"):
|
101 |
+
current_voice_short = voice4_short
|
102 |
processed_text = text_with_commands[2:].strip()
|
103 |
elif text_with_commands.startswith("1O"): # Old man voice
|
104 |
+
current_voice_short = voice5_short
|
105 |
current_pitch = -20
|
106 |
current_rate = -10
|
107 |
processed_text = text_with_commands[2:].strip()
|
108 |
elif text_with_commands.startswith("1C"): #Child voice
|
109 |
+
current_voice_short = voice6_short
|
110 |
processed_text = text_with_commands[2:].strip()
|
111 |
|
112 |
rate_str = f"{current_rate:+d}%"
|
113 |
pitch_str = f"{current_pitch:+d}Hz"
|
114 |
+
communicate = edge_tts.Communicate(processed_text, current_voice_short, rate=rate_str, pitch=pitch_str)
|
115 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
116 |
audio_path = tmp_file.name
|
117 |
await communicate.save(audio_path)
|