Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -81,42 +81,46 @@ async def paragraph_to_speech(text, voice, rate, pitch):
|
|
81 |
current_rate = rate
|
82 |
current_pitch = pitch
|
83 |
if part.startswith("1F"):
|
84 |
-
processed_text = part[2:]
|
85 |
current_voice = voice1F.split(" - ")[0]
|
86 |
current_pitch = 25
|
87 |
elif part.startswith("2F"):
|
88 |
-
processed_text = part[2:]
|
89 |
current_voice = voice2F.split(" - ")[0]
|
90 |
elif part.startswith("3F"):
|
91 |
-
processed_text = part[2:]
|
92 |
current_voice = voice3F.split(" - ")[0]
|
93 |
elif part.startswith("1M"):
|
94 |
-
processed_text = part[2:]
|
95 |
current_voice = voice1.split(" - ")[0]
|
96 |
elif part.startswith("2M"):
|
97 |
-
processed_text = part[2:]
|
98 |
current_voice = voice2.split(" - ")[0]
|
99 |
elif part.startswith("3M"):
|
100 |
-
processed_text = part[2:]
|
101 |
current_voice = voice3.split(" - ")[0]
|
102 |
elif part.startswith("1C"):
|
103 |
-
processed_text = part[2:]
|
104 |
current_voice = voice4.split(" - ")[0]
|
105 |
elif part.startswith("1O"):
|
106 |
-
processed_text = part[2:]
|
107 |
current_voice = voice5.split(" - ")[0]
|
108 |
-
current_pitch = -
|
109 |
-
current_rate = -
|
110 |
else:
|
111 |
# Use selected voice, or fallback to default
|
112 |
#voice_short_name = (voice or default_voice).split(" - ")[0]
|
113 |
current_voice = (voice or default_voice).split(" - ")[0]
|
114 |
processed_text=part[:]
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
118 |
# Remove only the first integer found
|
119 |
-
|
|
|
|
|
120 |
rate_str = f"{current_rate:+d}%"
|
121 |
#if part[2:4].isdigit():
|
122 |
# processed_text = part[4:]
|
|
|
81 |
current_rate = rate
|
82 |
current_pitch = pitch
|
83 |
if part.startswith("1F"):
|
84 |
+
#processed_text = part[2:]
|
85 |
current_voice = voice1F.split(" - ")[0]
|
86 |
current_pitch = 25
|
87 |
elif part.startswith("2F"):
|
88 |
+
#processed_text = part[2:]
|
89 |
current_voice = voice2F.split(" - ")[0]
|
90 |
elif part.startswith("3F"):
|
91 |
+
#processed_text = part[2:]
|
92 |
current_voice = voice3F.split(" - ")[0]
|
93 |
elif part.startswith("1M"):
|
94 |
+
#processed_text = part[2:]
|
95 |
current_voice = voice1.split(" - ")[0]
|
96 |
elif part.startswith("2M"):
|
97 |
+
#processed_text = part[2:]
|
98 |
current_voice = voice2.split(" - ")[0]
|
99 |
elif part.startswith("3M"):
|
100 |
+
#processed_text = part[2:]
|
101 |
current_voice = voice3.split(" - ")[0]
|
102 |
elif part.startswith("1C"):
|
103 |
+
#processed_text = part[2:]
|
104 |
current_voice = voice4.split(" - ")[0]
|
105 |
elif part.startswith("1O"):
|
106 |
+
#processed_text = part[2:]
|
107 |
current_voice = voice5.split(" - ")[0]
|
108 |
+
current_pitch = -20
|
109 |
+
current_rate = -10
|
110 |
else:
|
111 |
# Use selected voice, or fallback to default
|
112 |
#voice_short_name = (voice or default_voice).split(" - ")[0]
|
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'(?<=\D)-?\d+', part) # Look behind for non-digit before number
|
117 |
+
if match:
|
118 |
+
match = re.search(r'-?\d+', part)
|
119 |
+
current_pitch = int(match.group()) # Extract and convert the number to an integer
|
120 |
# Remove only the first integer found
|
121 |
+
# Step 2: Remove the found number from the string
|
122 |
+
new_text = re.sub(r'(?<=\D)-?\d+', '', part, count=1).strip()
|
123 |
+
processed_text = new_text[2:] #cut out the prefix like 1F, 3M etc
|
124 |
rate_str = f"{current_rate:+d}%"
|
125 |
#if part[2:4].isdigit():
|
126 |
# processed_text = part[4:]
|