From 25fad7d8ddc4dc185998c67f353eaf46082529b9 Mon Sep 17 00:00:00 2001 From: Caojunwei <97785943+dvdcjw@users.noreply.github.com> Date: Thu, 22 Feb 2024 18:42:31 +0800 Subject: [PATCH] Add files via upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当 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 --- api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api.py b/api.py index 754f0769..771d9290 100644 --- a/api.py +++ b/api.py @@ -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: