Update tts.py
Browse files
tts.py
CHANGED
@@ -71,11 +71,9 @@ def generate_speech(text, language="vi", speaker_wav=None, normalize_text=True):
|
|
71 |
raise ValueError(f"Ngôn ngữ {language} không được hỗ trợ.")
|
72 |
if len(text) < 2:
|
73 |
raise ValueError("Văn bản quá ngắn.")
|
74 |
-
|
75 |
try:
|
76 |
if normalize_text and language == "vi":
|
77 |
text = normalize_vietnamese_text(text)
|
78 |
-
|
79 |
with torch.no_grad():
|
80 |
with autocast(enabled=use_fp16):
|
81 |
gpt_cond_latent, speaker_embedding = MODEL.get_conditioning_latents(
|
@@ -93,8 +91,7 @@ def generate_speech(text, language="vi", speaker_wav=None, normalize_text=True):
|
|
93 |
temperature=0.75,
|
94 |
enable_text_splitting=True,
|
95 |
)
|
96 |
-
|
97 |
-
output_file = "output.wav"
|
98 |
torchaudio.save(output_file, torch.tensor(out["wav"]).unsqueeze(0).to("cpu"), 24000)
|
99 |
return output_file
|
100 |
except Exception as e:
|
|
|
71 |
raise ValueError(f"Ngôn ngữ {language} không được hỗ trợ.")
|
72 |
if len(text) < 2:
|
73 |
raise ValueError("Văn bản quá ngắn.")
|
|
|
74 |
try:
|
75 |
if normalize_text and language == "vi":
|
76 |
text = normalize_vietnamese_text(text)
|
|
|
77 |
with torch.no_grad():
|
78 |
with autocast(enabled=use_fp16):
|
79 |
gpt_cond_latent, speaker_embedding = MODEL.get_conditioning_latents(
|
|
|
91 |
temperature=0.75,
|
92 |
enable_text_splitting=True,
|
93 |
)
|
94 |
+
output_file = f"output_{os.urandom(4).hex()}.wav"
|
|
|
95 |
torchaudio.save(output_file, torch.tensor(out["wav"]).unsqueeze(0).to("cpu"), 24000)
|
96 |
return output_file
|
97 |
except Exception as e:
|