Spaces:
Running
Running
Jimmy Vu
commited on
Commit
·
7c7451a
1
Parent(s):
1a5f5c4
Split long text
Browse files- gradio_app.py +20 -17
gradio_app.py
CHANGED
@@ -235,23 +235,26 @@ def inference(input_text, language, speaker_id=None, gpt_cond_latent=None, speak
|
|
235 |
sentence = normalize_vietnamese_text(sentence)
|
236 |
text_tokens = torch.IntTensor(xtts_model.tokenizer.encode(sentence, lang=lang)).unsqueeze(0).to(xtts_model.device)
|
237 |
num_of_tokens += text_tokens.shape[-1]
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
|
|
|
|
|
|
255 |
return np.concatenate(out_wavs), num_of_tokens
|
256 |
|
257 |
|
|
|
235 |
sentence = normalize_vietnamese_text(sentence)
|
236 |
text_tokens = torch.IntTensor(xtts_model.tokenizer.encode(sentence, lang=lang)).unsqueeze(0).to(xtts_model.device)
|
237 |
num_of_tokens += text_tokens.shape[-1]
|
238 |
+
txts = [sentence]
|
239 |
+
if len(sentence) >= max_text_length: txts = split_sentence(sentence)
|
240 |
+
for txt in txts:
|
241 |
+
logger.info(f"[{lang}] {txt}")
|
242 |
+
try:
|
243 |
+
out = xtts_model.inference(
|
244 |
+
text=txt,
|
245 |
+
language=lang,
|
246 |
+
gpt_cond_latent=gpt_cond_latent,
|
247 |
+
speaker_embedding=speaker_embedding,
|
248 |
+
temperature=temperature,
|
249 |
+
top_p=top_p,
|
250 |
+
top_k=top_k,
|
251 |
+
repetition_penalty=repetition_penalty,
|
252 |
+
length_penalty=dynamic_length_penalty(len(sentence)),
|
253 |
+
enable_text_splitting=True,
|
254 |
+
)
|
255 |
+
out_wavs.append(out["wav"])
|
256 |
+
except Exception as e:
|
257 |
+
logger.error(f"Error processing text: {txt} - {e}")
|
258 |
return np.concatenate(out_wavs), num_of_tokens
|
259 |
|
260 |
|