Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre_seg_text开头加入判断是否全是特殊字符,并防止text为空字符,更改多个换行符的替换的代码 #962

Open
wants to merge 2 commits into
base: fast_inference_
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions GPT_SoVITS/TTS_infer_pack/TextPreprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,27 @@ def preprocess(self, text:str, lang:str, text_split_method:str)->List[Dict]:

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 not re.sub('\W','', 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):
Expand All @@ -98,7 +103,7 @@ def pre_seg_text(self, text:str, lang:str, text_split_method:str):
texts.extend(split_big_text(text))
else:
texts.append(text)

print(i18n("实际输入的目标文本(切句后):"))
print(texts)
return texts
Expand Down