From 0dd1d38c86a600d7a56e17fbf61dea9f41c48313 Mon Sep 17 00:00:00 2001 From: jmaple12 <93472187+jmaple12@users.noreply.github.com> Date: Thu, 11 Apr 2024 22:18:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9pre=5Fseg=5Ftext=E4=B8=AD?= =?UTF-8?q?=E5=BC=80=E5=A4=B4=E4=BB=A5=E5=8F=8A=E5=AF=B9=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=E7=AC=A6=E7=9A=84=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在text = text.strip("\n") 后面加入判断,防止text为空字符串。 使用正则式来替换原来将\n\n换为\n的式子 --- GPT_SoVITS/TTS_infer_pack/TextPreprocessor.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/GPT_SoVITS/TTS_infer_pack/TextPreprocessor.py b/GPT_SoVITS/TTS_infer_pack/TextPreprocessor.py index 58b2678..f04a63d 100644 --- a/GPT_SoVITS/TTS_infer_pack/TextPreprocessor.py +++ b/GPT_SoVITS/TTS_infer_pack/TextPreprocessor.py @@ -71,22 +71,24 @@ class TextPreprocessor: def pre_seg_text(self, text:str, lang:str, text_split_method:str): text = text.strip("\n") - if (text[0] not in splits and len(get_first(text)) < 4): - text = "。" + text if lang != "en" else "." + text + #防止text成为空字符串 + if text: + if (text[0] not in splits and len(get_first(text)) < 4): + text = text + "。" if lang != "en" else text + "." print(i18n("实际输入的目标文本:")) print(text) seg_method = get_seg_method(text_split_method) text = seg_method(text) - while "\n\n" in text: - text = text.replace("\n\n", "\n") + # while "\n\n" in text: + # text = text.replace("\n\n", "\n") + text = re.sub(r'\n+','\n', text) _texts = text.split("\n") _texts = merge_short_text_in_array(_texts, 5) texts = [] - for text in _texts: # 解决输入目标文本的空行导致报错的问题 if (len(text.strip()) == 0): @@ -98,7 +100,7 @@ class TextPreprocessor: texts.extend(split_big_text(text)) else: texts.append(text) - + print(i18n("实际输入的目标文本(切句后):")) print(texts) return texts