cnph001 commited on
Commit
9995337
·
verified ·
1 Parent(s): 0b4c9e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -14
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 = -30
109
- current_rate = -15
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
- if (re.search(r'-?\d+', part)): #if there are any digit following the voice tag, eg 1F20 or 1F-20
116
- match = re.search(r'-?\d+', part)
117
- pitch = int(match.group()) #Set pitch to set value as noted in the tag
 
 
118
  # Remove only the first integer found
119
- processed_text = re.sub(r'-?\d+', '', part, count=1).strip() #cut out the pitch int from text part
 
 
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:]