cnph001 commited on
Commit
4f3af59
·
verified ·
1 Parent(s): 8462870

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
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'(?<=\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
  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}%"