Update app.py
Browse files
app.py
CHANGED
@@ -46,7 +46,6 @@ async def generate_audio_with_voice_prefix(text_segment, default_voice, rate, pi
|
|
46 |
current_rate = rate
|
47 |
current_pitch = pitch
|
48 |
processed_text = text_segment.strip()
|
49 |
-
|
50 |
voice1_full = "en-AU-WilliamNeural - en-AU (Male)"
|
51 |
voice1_short = voice1_full.split(" - ")[0]
|
52 |
voice1F_full ="en-GB-SoniaNeural - en-GB (Female)"
|
@@ -75,56 +74,83 @@ async def generate_audio_with_voice_prefix(text_segment, default_voice, rate, pi
|
|
75 |
voice9F_short = voice7_full.split(" - ")[0]
|
76 |
voice9_full = "ko-KR-HyunsuMultilingualNeural - ko-KR (Male)" #Vietnamese
|
77 |
voice9_short = voice8_full.split(" - ")[0]
|
78 |
-
|
79 |
if processed_text.startswith("1F"):
|
80 |
current_voice_short = voice1F_short
|
81 |
current_pitch = 25
|
82 |
-
|
|
|
83 |
elif processed_text.startswith("2F"):
|
84 |
current_voice_short = voice2F_short
|
85 |
-
processed_text = processed_text[2:].strip()
|
|
|
86 |
elif processed_text.startswith("3F"):
|
87 |
current_voice_short = voice3F_short
|
88 |
-
processed_text = processed_text[2:].strip()
|
|
|
89 |
elif processed_text.startswith("4F"):
|
90 |
current_voice_short = voice4F_short
|
91 |
-
processed_text = processed_text[2:].strip()
|
|
|
92 |
elif processed_text.startswith("1M"):
|
93 |
current_voice_short = voice1_short
|
94 |
-
processed_text = processed_text[2:].strip()
|
|
|
95 |
elif processed_text.startswith("2M"):
|
96 |
current_voice_short = voice2_short
|
97 |
-
processed_text = processed_text[2:].strip()
|
|
|
98 |
elif processed_text.startswith("3M"):
|
99 |
current_voice_short = voice3_short
|
100 |
-
processed_text = processed_text[2:].strip()
|
|
|
101 |
elif processed_text.startswith("4M"):
|
102 |
current_voice_short = voice4_short
|
103 |
-
processed_text = processed_text[2:].strip()
|
|
|
104 |
elif processed_text.startswith("1O"): # Old man voice
|
105 |
current_voice_short = voice5_short
|
106 |
current_pitch = -20
|
107 |
current_rate = -10
|
108 |
-
processed_text = processed_text[2:].strip()
|
|
|
109 |
elif processed_text.startswith("1C"): #Child voice
|
110 |
current_voice_short = voice6_short
|
111 |
-
processed_text = processed_text[2:].strip()
|
112 |
-
|
113 |
elif processed_text.startswith("1V"): #Female VN
|
114 |
current_voice_short = voice7_short
|
115 |
-
processed_text = processed_text[2:].strip()
|
|
|
116 |
elif processed_text.startswith("2V"):
|
117 |
current_voice_short = voice8_short
|
118 |
-
processed_text = processed_text[2:].strip()
|
|
|
119 |
elif processed_text.startswith("3V"): #Female VN
|
120 |
current_voice_short = voice9F_short
|
121 |
current_pitch = 25
|
122 |
-
processed_text = processed_text[2:].strip()
|
|
|
123 |
elif processed_text.startswith("4V"):
|
124 |
current_voice_short = voice9_short
|
125 |
current_pitch = -20
|
126 |
-
processed_text = processed_text[2:].strip()
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
if processed_text:
|
129 |
rate_str = f"{current_rate:+d}%"
|
130 |
pitch_str = f"{current_pitch:+d}Hz"
|
|
|
46 |
current_rate = rate
|
47 |
current_pitch = pitch
|
48 |
processed_text = text_segment.strip()
|
|
|
49 |
voice1_full = "en-AU-WilliamNeural - en-AU (Male)"
|
50 |
voice1_short = voice1_full.split(" - ")[0]
|
51 |
voice1F_full ="en-GB-SoniaNeural - en-GB (Female)"
|
|
|
74 |
voice9F_short = voice7_full.split(" - ")[0]
|
75 |
voice9_full = "ko-KR-HyunsuMultilingualNeural - ko-KR (Male)" #Vietnamese
|
76 |
voice9_short = voice8_full.split(" - ")[0]
|
77 |
+
detect=0
|
78 |
if processed_text.startswith("1F"):
|
79 |
current_voice_short = voice1F_short
|
80 |
current_pitch = 25
|
81 |
+
detect=1
|
82 |
+
#processed_text = processed_text[2:].strip()
|
83 |
elif processed_text.startswith("2F"):
|
84 |
current_voice_short = voice2F_short
|
85 |
+
#processed_text = processed_text[2:].strip()
|
86 |
+
detect=1
|
87 |
elif processed_text.startswith("3F"):
|
88 |
current_voice_short = voice3F_short
|
89 |
+
#processed_text = processed_text[2:].strip()
|
90 |
+
detect=1
|
91 |
elif processed_text.startswith("4F"):
|
92 |
current_voice_short = voice4F_short
|
93 |
+
#processed_text = processed_text[2:].strip()
|
94 |
+
detect=1
|
95 |
elif processed_text.startswith("1M"):
|
96 |
current_voice_short = voice1_short
|
97 |
+
#processed_text = processed_text[2:].strip()
|
98 |
+
detect=1
|
99 |
elif processed_text.startswith("2M"):
|
100 |
current_voice_short = voice2_short
|
101 |
+
#processed_text = processed_text[2:].strip()
|
102 |
+
detect=1
|
103 |
elif processed_text.startswith("3M"):
|
104 |
current_voice_short = voice3_short
|
105 |
+
#processed_text = processed_text[2:].strip()
|
106 |
+
detect=1
|
107 |
elif processed_text.startswith("4M"):
|
108 |
current_voice_short = voice4_short
|
109 |
+
#processed_text = processed_text[2:].strip()
|
110 |
+
detect=1
|
111 |
elif processed_text.startswith("1O"): # Old man voice
|
112 |
current_voice_short = voice5_short
|
113 |
current_pitch = -20
|
114 |
current_rate = -10
|
115 |
+
#processed_text = processed_text[2:].strip()
|
116 |
+
detect=1
|
117 |
elif processed_text.startswith("1C"): #Child voice
|
118 |
current_voice_short = voice6_short
|
119 |
+
#processed_text = processed_text[2:].strip()
|
120 |
+
detect=1
|
121 |
elif processed_text.startswith("1V"): #Female VN
|
122 |
current_voice_short = voice7_short
|
123 |
+
#processed_text = processed_text[2:].strip()
|
124 |
+
detect=1
|
125 |
elif processed_text.startswith("2V"):
|
126 |
current_voice_short = voice8_short
|
127 |
+
#processed_text = processed_text[2:].strip()
|
128 |
+
detect=1
|
129 |
elif processed_text.startswith("3V"): #Female VN
|
130 |
current_voice_short = voice9F_short
|
131 |
current_pitch = 25
|
132 |
+
#processed_text = processed_text[2:].strip()
|
133 |
+
detect=1
|
134 |
elif processed_text.startswith("4V"):
|
135 |
current_voice_short = voice9_short
|
136 |
current_pitch = -20
|
137 |
+
#processed_text = processed_text[2:].strip()
|
138 |
+
detect=1
|
139 |
+
#Looking for number following prefix, which are pitch values.
|
140 |
+
#match = re.search(r'[A-Za-z]\d+', part) # Look for a letter followed by one or more digits
|
141 |
+
match = re.search(r'[A-Za-z]+\-?\d+', processed_text) # Look for a letter(s) followed by an optional '-' and digits
|
142 |
+
if match:
|
143 |
+
# Extract the prefix (e.g., '2F') and number (e.g., '-20')
|
144 |
+
prefix = ''.join([ch for ch in match.group() if ch.isalpha()]) # Extract letters (prefix)
|
145 |
+
number = int(''.join([ch for ch in match.group() if ch.isdigit() or ch == '-'])) # Extract digits (number)
|
146 |
+
current_pitch += number
|
147 |
+
# Step 2: Remove the found number from the string
|
148 |
+
new_text = re.sub(r'[A-Za-z]+\-?\d+', '', processed_text, count=1).strip() # Remove prefix and number (e.g., '2F-20')
|
149 |
+
#processed_text = new_text[2:] #cut out the prefix like 1F, 3M etc
|
150 |
+
processed_text = new_text[len(prefix):] # Dynamically remove the prefix part
|
151 |
+
else:
|
152 |
+
if detect:
|
153 |
+
processed_text = part[2:]
|
154 |
if processed_text:
|
155 |
rate_str = f"{current_rate:+d}%"
|
156 |
pitch_str = f"{current_pitch:+d}Hz"
|