Add files via upload

当 API 接收到的 text 输入参数包含两个或两个以上的连续换行符 '\n' 时,使用 split('\n') 方法拆分字符串会在结果列表中产生空字符串元素 ('')。这会进一步导致在使用 torch.cat() 方法时抛出 RuntimeError,因为 torch.cat() 预期接收到的是一个非空的张量列表。

错误示例:

python
texts = "这是第一行\n\n这是第三行"
texts_split = texts.split('\n')
# texts_split 结果是 ['这是第一行', '', '这是第三行']
# 其中的 '' 会导致后续的 torch.cat() 操作失败
错误信息:
...
RuntimeError: torch.cat(): expected a non-empty list of Tensors
This commit is contained in:
Caojunwei 2024-02-22 18:42:31 +08:00 committed by GitHub
parent 939971afe3
commit 25fad7d8dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

3
api.py
View File

@ -378,7 +378,8 @@ def get_tts_wav(ref_wav_path, prompt_text, prompt_language, text, text_language)
text_language = dict_language[text_language]
phones1, word2ph1, norm_text1 = clean_text(prompt_text, prompt_language)
phones1 = cleaned_text_to_sequence(phones1)
texts = text.split("\n")
_ = text.split("\n")
texts = [t for t in _ if t != '']
audio_opt = []
for text in texts: