Update app.py
Browse files
app.py
CHANGED
|
@@ -195,21 +195,20 @@ def tts_streaming(text: str, voice: str = "af_heart", speed: float = 1.0, format
|
|
| 195 |
print(chunk)
|
| 196 |
|
| 197 |
# For the first chunk, prepend 0; for later chunks, start with the previous chunk's last token.
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
# token_to_send = [0] + chunk_tokens + [0]
|
| 203 |
|
| 204 |
# Save the last token of this chunk for the next iteration.
|
| 205 |
-
|
| 206 |
|
| 207 |
# Prepare the model input (a batch of one sequence).
|
| 208 |
-
final_token = [
|
| 209 |
|
| 210 |
# Use the number of tokens to select the appropriate style vector.
|
| 211 |
-
style_index = len(
|
| 212 |
-
print(len(voices))
|
| 213 |
if style_index >= len(voices):
|
| 214 |
style_index = len(voices) - 1 # Fallback if index is out-of-bounds.
|
| 215 |
ref_s = voices[style_index]
|
|
|
|
| 195 |
print(chunk)
|
| 196 |
|
| 197 |
# For the first chunk, prepend 0; for later chunks, start with the previous chunk's last token.
|
| 198 |
+
if i == 0:
|
| 199 |
+
tokens_to_send = [0] + chunk_tokens + [0]
|
| 200 |
+
else:
|
| 201 |
+
tokens_to_send = [prev_last_token] + chunk_tokens + [0]
|
| 202 |
# token_to_send = [0] + chunk_tokens + [0]
|
| 203 |
|
| 204 |
# Save the last token of this chunk for the next iteration.
|
| 205 |
+
prev_last_token = chunk_tokens[-1]
|
| 206 |
|
| 207 |
# Prepare the model input (a batch of one sequence).
|
| 208 |
+
final_token = [tokens_to_send]
|
| 209 |
|
| 210 |
# Use the number of tokens to select the appropriate style vector.
|
| 211 |
+
style_index = len(chunk_tokens) + 2
|
|
|
|
| 212 |
if style_index >= len(voices):
|
| 213 |
style_index = len(voices) - 1 # Fallback if index is out-of-bounds.
|
| 214 |
ref_s = voices[style_index]
|