Gregniuki commited on
Commit
adac44f
·
verified ·
1 Parent(s): 5c1fc8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -138,6 +138,7 @@ E2TTS_ema_model2 = load_custom(
138
 
139
 
140
 
 
141
  def chunk_text(text, max_chars=100):
142
  """
143
  Splits the input text into chunks, each with a maximum number of characters.
@@ -152,9 +153,9 @@ def chunk_text(text, max_chars=100):
152
  Returns:
153
  List[str]: A list of text chunks.
154
  """
 
155
  chunks = []
156
  current_chunk = ""
157
- split_after_space_chars = 135
158
 
159
  # Split the text into sentences based on punctuation followed by whitespace
160
  sentences = re.split(r"(?<=[;:,.!?])\s+|(?<=[;:,。!?])", text)
@@ -170,11 +171,19 @@ def chunk_text(text, max_chars=100):
170
  current_chunk = sentence + " "
171
 
172
  # If current chunk exceeds split_after_space_chars and no punctuation, split at space
173
- if len(current_chunk) > split_after_space_chars and re.search(r"\w", current_chunk):
174
- split_index = current_chunk.rfind(" ")
175
- if split_index != -1:
176
- chunks.append(current_chunk[:split_index].strip()) # Add the chunk before the space
177
- current_chunk = current_chunk[split_index:].strip() # Start new chunk after the space
 
 
 
 
 
 
 
 
178
 
179
  # Append any remaining text in current_chunk to chunks
180
  if current_chunk:
@@ -184,6 +193,7 @@ def chunk_text(text, max_chars=100):
184
 
185
 
186
 
 
187
  @gpu_decorator
188
  def infer_batch(ref_audio, ref_text, gen_text_batches, exp_name, remove_silence, cross_fade_duration=0.15, progress=gr.Progress()):
189
  if exp_name == "English":
 
138
 
139
 
140
 
141
+
142
  def chunk_text(text, max_chars=100):
143
  """
144
  Splits the input text into chunks, each with a maximum number of characters.
 
153
  Returns:
154
  List[str]: A list of text chunks.
155
  """
156
+ split_after_space_chars = 135
157
  chunks = []
158
  current_chunk = ""
 
159
 
160
  # Split the text into sentences based on punctuation followed by whitespace
161
  sentences = re.split(r"(?<=[;:,.!?])\s+|(?<=[;:,。!?])", text)
 
171
  current_chunk = sentence + " "
172
 
173
  # If current chunk exceeds split_after_space_chars and no punctuation, split at space
174
+ if len(current_chunk) > split_after_space_chars:
175
+ # Check if the chunk has punctuation
176
+ if not re.search(r"[;:,.!?;:,。!?]", current_chunk):
177
+ # No punctuation; split after the last space before 135 characters
178
+ split_index = current_chunk.rfind(" ", 0, split_after_space_chars)
179
+ if split_index != -1:
180
+ chunks.append(current_chunk[:split_index].strip()) # Add the chunk before the space
181
+ current_chunk = current_chunk[split_index:].strip() # Start new chunk after the space
182
+ else:
183
+ # Chunk contains punctuation; just add it to chunks
184
+ if current_chunk:
185
+ chunks.append(current_chunk.strip())
186
+ current_chunk = ""
187
 
188
  # Append any remaining text in current_chunk to chunks
189
  if current_chunk:
 
193
 
194
 
195
 
196
+
197
  @gpu_decorator
198
  def infer_batch(ref_audio, ref_text, gen_text_batches, exp_name, remove_silence, cross_fade_duration=0.15, progress=gr.Progress()):
199
  if exp_name == "English":