passerbya commited on
Commit
95b8866
1 Parent(s): 39afb98

优先使用ttsfrd,ttsfrd不存在时使用WeTextProcessing

Browse files
Files changed (1) hide show
  1. cosyvoice/cli/frontend.py +21 -4
cosyvoice/cli/frontend.py CHANGED
@@ -23,7 +23,12 @@ import os
23
  import inflect
24
  from tn.chinese.normalizer import Normalizer as ZhNormalizer
25
  from tn.english.normalizer import Normalizer as EnNormalizer
26
-
 
 
 
 
 
27
  from cosyvoice.utils.frontend_utils import contains_chinese, replace_blank, replace_corner_mark, remove_bracket, spell_out_number, split_paragraph
28
 
29
 
@@ -50,8 +55,17 @@ class CosyVoiceFrontEnd:
50
  self.instruct = instruct
51
  self.allowed_special = allowed_special
52
  self.inflect_parser = inflect.engine()
53
- self.zh_tn_model = ZhNormalizer(remove_erhua=False,full_to_half=False)
54
- self.en_tn_model = EnNormalizer()
 
 
 
 
 
 
 
 
 
55
 
56
  def _extract_text_token(self, text):
57
  text_token = self.tokenizer.encode(text, allowed_special=self.allowed_special)
@@ -86,7 +100,10 @@ class CosyVoiceFrontEnd:
86
  def text_normalize(self, text, split=True):
87
  text = text.strip()
88
  if contains_chinese(text):
89
- text = self.zh_tn_model.normalize(text)
 
 
 
90
  text = text.replace("\n", "")
91
  text = replace_blank(text)
92
  text = replace_corner_mark(text)
 
23
  import inflect
24
  from tn.chinese.normalizer import Normalizer as ZhNormalizer
25
  from tn.english.normalizer import Normalizer as EnNormalizer
26
+ try:
27
+ import ttsfrd
28
+ use_ttsfrd = True
29
+ except:
30
+ print("failed to import ttsfrd, please normalize input text manually")
31
+ use_ttsfrd = False
32
  from cosyvoice.utils.frontend_utils import contains_chinese, replace_blank, replace_corner_mark, remove_bracket, spell_out_number, split_paragraph
33
 
34
 
 
55
  self.instruct = instruct
56
  self.allowed_special = allowed_special
57
  self.inflect_parser = inflect.engine()
58
+ self.use_ttsfrd = use_ttsfrd
59
+ if self.use_ttsfrd:
60
+ self.frd = ttsfrd.TtsFrontendEngine()
61
+ ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
62
+ assert self.frd.initialize('{}/../../pretrained_models/CosyVoice-ttsfrd/resource'.format(ROOT_DIR)) is True, 'failed to initialize ttsfrd resource'
63
+ self.frd.set_lang_type('pinyin')
64
+ self.frd.enable_pinyin_mix(True)
65
+ self.frd.set_breakmodel_index(1)
66
+ else:
67
+ self.zh_tn_model = ZhNormalizer(remove_erhua=False,full_to_half=False)
68
+ self.en_tn_model = EnNormalizer()
69
 
70
  def _extract_text_token(self, text):
71
  text_token = self.tokenizer.encode(text, allowed_special=self.allowed_special)
 
100
  def text_normalize(self, text, split=True):
101
  text = text.strip()
102
  if contains_chinese(text):
103
+ if self.use_ttsfrd:
104
+ text = self.frd.get_frd_extra_info(text, 'input')
105
+ else:
106
+ text = self.zh_tn_model.normalize(text)
107
  text = text.replace("\n", "")
108
  text = replace_blank(text)
109
  text = replace_corner_mark(text)