Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -141,9 +141,10 @@ E2TTS_ema_model2 = load_custom(
|
|
| 141 |
|
| 142 |
def chunk_text(text, max_chars=100):
|
| 143 |
"""
|
| 144 |
-
Splits the input text into chunks,
|
| 145 |
-
|
| 146 |
-
and the chunk exceeds `split_after_space_chars
|
|
|
|
| 147 |
|
| 148 |
Args:
|
| 149 |
text (str): The text to be split.
|
|
@@ -161,31 +162,32 @@ def chunk_text(text, max_chars=100):
|
|
| 161 |
sentences = re.split(r"(?<=[;:,.!?])\s+|(?<=[;:,。!?])", text)
|
| 162 |
|
| 163 |
for sentence in sentences:
|
| 164 |
-
# If adding this sentence
|
| 165 |
if len(current_chunk) + len(sentence) + 1 <= max_chars: # +1 for space
|
| 166 |
current_chunk += sentence + " "
|
| 167 |
else:
|
| 168 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
if current_chunk:
|
| 170 |
chunks.append(current_chunk.strip())
|
| 171 |
current_chunk = sentence + " "
|
| 172 |
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 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 |
-
#
|
| 189 |
if current_chunk:
|
| 190 |
chunks.append(current_chunk.strip())
|
| 191 |
|
|
@@ -194,6 +196,7 @@ def chunk_text(text, max_chars=100):
|
|
| 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":
|
|
|
|
| 141 |
|
| 142 |
def chunk_text(text, max_chars=100):
|
| 143 |
"""
|
| 144 |
+
Splits the input text into chunks, ensuring:
|
| 145 |
+
- Chunks are split by punctuation where possible.
|
| 146 |
+
- If no punctuation is found and the chunk exceeds `split_after_space_chars`,
|
| 147 |
+
it is split into smaller chunks of up to `split_after_space_chars`.
|
| 148 |
|
| 149 |
Args:
|
| 150 |
text (str): The text to be split.
|
|
|
|
| 162 |
sentences = re.split(r"(?<=[;:,.!?])\s+|(?<=[;:,。!?])", text)
|
| 163 |
|
| 164 |
for sentence in sentences:
|
| 165 |
+
# If adding this sentence doesn't exceed max_chars, append it to the current chunk
|
| 166 |
if len(current_chunk) + len(sentence) + 1 <= max_chars: # +1 for space
|
| 167 |
current_chunk += sentence + " "
|
| 168 |
else:
|
| 169 |
+
# If current chunk exceeds split_after_space_chars, handle the splitting
|
| 170 |
+
while len(current_chunk) > split_after_space_chars:
|
| 171 |
+
split_index = current_chunk.rfind(" ", 0, split_after_space_chars)
|
| 172 |
+
if split_index == -1: # No spaces to split; force split at 135 characters
|
| 173 |
+
split_index = split_after_space_chars
|
| 174 |
+
chunks.append(current_chunk[:split_index].strip())
|
| 175 |
+
current_chunk = current_chunk[split_index:].strip()
|
| 176 |
+
|
| 177 |
+
# Add the current chunk to the list and start a new chunk
|
| 178 |
if current_chunk:
|
| 179 |
chunks.append(current_chunk.strip())
|
| 180 |
current_chunk = sentence + " "
|
| 181 |
|
| 182 |
+
# If the remaining chunk exceeds split_after_space_chars, split it further
|
| 183 |
+
while len(current_chunk) > split_after_space_chars:
|
| 184 |
+
split_index = current_chunk.rfind(" ", 0, split_after_space_chars)
|
| 185 |
+
if split_index == -1: # No spaces to split; force split at 135 characters
|
| 186 |
+
split_index = split_after_space_chars
|
| 187 |
+
chunks.append(current_chunk[:split_index].strip())
|
| 188 |
+
current_chunk = current_chunk[split_index:].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
+
# Add any leftover chunk
|
| 191 |
if current_chunk:
|
| 192 |
chunks.append(current_chunk.strip())
|
| 193 |
|
|
|
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
+
|
| 200 |
@gpu_decorator
|
| 201 |
def infer_batch(ref_audio, ref_text, gen_text_batches, exp_name, remove_silence, cross_fade_duration=0.15, progress=gr.Progress()):
|
| 202 |
if exp_name == "English":
|