Gregniuki commited on
Commit
89a95a4
·
verified ·
1 Parent(s): cf18133

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -11
app.py CHANGED
@@ -21,7 +21,7 @@ from model.utils import (
21
  from infer.utils_infer import (
22
  load_vocoder,
23
  load_model,
24
- preprocess_ref_audio_text,
25
  infer_process,
26
  remove_silence_edges,
27
  remove_silence_for_generated_wav,
@@ -136,17 +136,17 @@ E2TTS_ema_model2 = load_custom(
136
  "hf://Gregniuki/F5-tts_English_German_Polish/Polish/model_500000.pt", "", F5TTS_model_cfg
137
  )
138
 
139
- import re
140
 
141
  def chunk_text(text, max_chars=100):
142
  """
143
- Splits the input text into chunks, each with a maximum number of characters
144
- (but splits only after a space if the chunk exceeds the character limit).
145
-
 
146
  Args:
147
  text (str): The text to be split.
148
  max_chars (int): The maximum number of characters per chunk.
149
-
150
  Returns:
151
  List[str]: A list of text chunks.
152
  """
@@ -157,15 +157,23 @@ def chunk_text(text, max_chars=100):
157
  sentences = re.split(r"(?<=[;:,.!?])\s+|(?<=[;:,。!?])", text)
158
 
159
  for sentence in sentences:
160
- # Check if adding this sentence to the current chunk will exceed the max_chars
161
  if len(current_chunk) + len(sentence) + 1 <= max_chars: # +1 for the space
162
  current_chunk += sentence + " "
163
  else:
 
164
  if current_chunk:
165
- # Add the current chunk to the list and reset it
166
- chunks.append(current_chunk.strip())
167
- # Start a new chunk with the current sentence
168
- current_chunk = sentence + " "
 
 
 
 
 
 
 
169
 
170
  # Append any remaining text in current_chunk to chunks
171
  if current_chunk:
@@ -174,6 +182,7 @@ def chunk_text(text, max_chars=100):
174
  return chunks
175
 
176
 
 
177
  @gpu_decorator
178
  def infer_batch(ref_audio, ref_text, gen_text_batches, exp_name, remove_silence, cross_fade_duration=0.15, progress=gr.Progress()):
179
  if exp_name == "English":
 
21
  from infer.utils_infer import (
22
  load_vocoder,
23
  load_model,
24
+ # preprocess_ref_audio_text,
25
  infer_process,
26
  remove_silence_edges,
27
  remove_silence_for_generated_wav,
 
136
  "hf://Gregniuki/F5-tts_English_German_Polish/Polish/model_500000.pt", "", F5TTS_model_cfg
137
  )
138
 
 
139
 
140
  def chunk_text(text, max_chars=100):
141
  """
142
+ Splits the input text into chunks, each with a maximum number of characters.
143
+ If a chunk exceeds the character limit, it will split at a space after the limit is exceeded,
144
+ but only if no punctuation mark is present at the split point.
145
+
146
  Args:
147
  text (str): The text to be split.
148
  max_chars (int): The maximum number of characters per chunk.
149
+
150
  Returns:
151
  List[str]: A list of text chunks.
152
  """
 
157
  sentences = re.split(r"(?<=[;:,.!?])\s+|(?<=[;:,。!?])", text)
158
 
159
  for sentence in sentences:
160
+ # Check if adding this sentence exceeds the max_chars limit
161
  if len(current_chunk) + len(sentence) + 1 <= max_chars: # +1 for the space
162
  current_chunk += sentence + " "
163
  else:
164
+ # If the chunk exceeds max_chars and no punctuation at the end, split at the last space
165
  if current_chunk:
166
+ # Find the last space in the current chunk and split there
167
+ split_index = current_chunk.rfind(" ")
168
+ if split_index != -1:
169
+ chunks.append(current_chunk[:split_index].strip())
170
+ current_chunk = current_chunk[split_index:].strip() + sentence
171
+ else:
172
+ # If no space is found (unusual case), append the chunk as is
173
+ chunks.append(current_chunk.strip())
174
+ else:
175
+ # If no chunk is being built, just append the sentence
176
+ current_chunk = sentence + " "
177
 
178
  # Append any remaining text in current_chunk to chunks
179
  if current_chunk:
 
182
  return chunks
183
 
184
 
185
+
186
  @gpu_decorator
187
  def infer_batch(ref_audio, ref_text, gen_text_batches, exp_name, remove_silence, cross_fade_duration=0.15, progress=gr.Progress()):
188
  if exp_name == "English":