diff --git a/cosyvoice/cli/frontend.py b/cosyvoice/cli/frontend.py index 32e5539..c30135a 100644 --- a/cosyvoice/cli/frontend.py +++ b/cosyvoice/cli/frontend.py @@ -21,6 +21,8 @@ import torchaudio.compliance.kaldi as kaldi import torchaudio import os import inflect +from tn.chinese.normalizer import Normalizer as ZhNormalizer +from tn.english.normalizer import Normalizer as EnNormalizer try: import ttsfrd use_ttsfrd = True @@ -61,6 +63,9 @@ class CosyVoiceFrontEnd: self.frd.set_lang_type('pinyin') self.frd.enable_pinyin_mix(True) self.frd.set_breakmodel_index(1) + else: + self.zh_tn_model = ZhNormalizer(remove_erhua=False,full_to_half=False) + self.en_tn_model = EnNormalizer() def _extract_text_token(self, text): text_token = self.tokenizer.encode(text, allowed_special=self.allowed_special) @@ -97,6 +102,8 @@ class CosyVoiceFrontEnd: if contains_chinese(text): if self.use_ttsfrd: text = self.frd.get_frd_extra_info(text, 'input') + else: + text = self.zh_tn_model.normalize(text) text = text.replace("\n", "") text = replace_blank(text) text = replace_corner_mark(text) @@ -107,6 +114,7 @@ class CosyVoiceFrontEnd: token_min_n=60, merge_len=20, comma_split=False)] else: + text = self.en_tn_model.normalize(text) text = spell_out_number(text, self.inflect_parser) texts = [i for i in split_paragraph(text, partial(self.tokenizer.encode, allowed_special=self.allowed_special), "en", token_max_n=80, token_min_n=60, merge_len=20, diff --git a/cosyvoice/utils/frontend_utils.py b/cosyvoice/utils/frontend_utils.py index dee829f..59489a7 100644 --- a/cosyvoice/utils/frontend_utils.py +++ b/cosyvoice/utils/frontend_utils.py @@ -74,7 +74,7 @@ def split_paragraph(text: str, tokenize, lang="zh", token_max_n=80, token_min_n= return len(tokenize(_text)) < merge_len if lang == "zh": - pounc = ['。', '?', '!', ';', ':', '.', '?', '!', ';'] + pounc = ['。', '?', '!', ';', ':', '、', '.', '?', '!', ';'] else: pounc = ['.', '?', '!', ';', ':'] if comma_split: @@ -91,6 +91,11 @@ def split_paragraph(text: str, tokenize, lang="zh", token_max_n=80, token_min_n= st = i + 2 else: st = i + 1 + if len(utts) == 0: + if lang == "zh": + utts.append(text + '。') + else: + utts.append(text + '.') final_utts = [] cur_utt = "" for utt in utts: diff --git a/requirements.txt b/requirements.txt index 39e1374..24639f2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,4 +25,5 @@ soundfile==0.12.1 tensorboard==2.14.0 torch==2.0.1 torchaudio==2.0.2 -wget==3.2 \ No newline at end of file +wget==3.2 +WeTextProcessing