Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -113,14 +113,17 @@ async def paragraph_to_speech(text, voice, rate, pitch):
|
|
113 |
current_voice = (voice or default_voice).split(" - ")[0]
|
114 |
processed_text=part[:]
|
115 |
# Step 1: Use regex to find the first number, possibly negative, after a prefix (e.g., F-)
|
116 |
-
match = re.search(r'
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
121 |
# Step 2: Remove the found number from the string
|
122 |
-
new_text = re.sub(r'
|
123 |
-
processed_text = new_text[2:] #cut out the prefix like 1F, 3M etc
|
|
|
124 |
else:
|
125 |
processed_text = part[2:]
|
126 |
rate_str = f"{current_rate:+d}%"
|
|
|
113 |
current_voice = (voice or default_voice).split(" - ")[0]
|
114 |
processed_text=part[:]
|
115 |
# Step 1: Use regex to find the first number, possibly negative, after a prefix (e.g., F-)
|
116 |
+
#match = re.search(r'[A-Za-z]\d+', part) # Look for a letter followed by one or more digits
|
117 |
+
match = re.search(r'[A-Za-z]+\-?\d+', part) # Look for a letter(s) followed by an optional '-' and digits
|
118 |
+
if match:
|
119 |
+
# Extract the prefix (e.g., '2F') and number (e.g., '-20')
|
120 |
+
prefix = ''.join([ch for ch in match.group() if ch.isalpha()]) # Extract letters (prefix)
|
121 |
+
number = int(''.join([ch for ch in match.group() if ch.isdigit() or ch == '-'])) # Extract digits (number)
|
122 |
+
current_pitch = number
|
123 |
# Step 2: Remove the found number from the string
|
124 |
+
new_text = re.sub(r'[A-Za-z]+\-?\d+', '', part, count=1).strip() # Remove prefix and number (e.g., '2F-20')
|
125 |
+
#processed_text = new_text[2:] #cut out the prefix like 1F, 3M etc
|
126 |
+
processed_text = new_text[len(prefix):] # Dynamically remove the prefix part
|
127 |
else:
|
128 |
processed_text = part[2:]
|
129 |
rate_str = f"{current_rate:+d}%"
|