CosyVoice commited on
Commit
7981796
1 Parent(s): 5e97398

add WeTextProcessing

Browse files
README.md CHANGED
@@ -22,6 +22,8 @@ git submodule update --init --recursive
22
  ``` sh
23
  conda create -n cosyvoice python=3.8
24
  conda activate cosyvoice
 
 
25
  pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com
26
 
27
  # If you encounter sox compatibility issues
@@ -55,9 +57,9 @@ git clone https://www.modelscope.cn/iic/CosyVoice-300M-Instruct.git pretrained_m
55
  git clone https://www.modelscope.cn/iic/CosyVoice-ttsfrd.git pretrained_models/CosyVoice-ttsfrd
56
  ```
57
 
58
- Optionaly, you can unzip `ttsfrd` resouce and install `ttsfrd` package.
59
 
60
- Notice that this step is not necessary. If you do not install `ttsfrd` package, you need to normalize input text manually.
61
 
62
  ``` sh
63
  cd pretrained_models/CosyVoice-ttsfrd/
 
22
  ``` sh
23
  conda create -n cosyvoice python=3.8
24
  conda activate cosyvoice
25
+ # pynini is required by WeTextProcessing, use conda to install it as it can be executed on all platform.
26
+ conda install -y -c conda-forge pynini==2.1.5
27
  pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com
28
 
29
  # If you encounter sox compatibility issues
 
57
  git clone https://www.modelscope.cn/iic/CosyVoice-ttsfrd.git pretrained_models/CosyVoice-ttsfrd
58
  ```
59
 
60
+ Optionaly, you can unzip `ttsfrd` resouce and install `ttsfrd` package for better text normalization performance.
61
 
62
+ Notice that this step is not necessary. If you do not install `ttsfrd` package, we will use WeTextProcessing by default.
63
 
64
  ``` sh
65
  cd pretrained_models/CosyVoice-ttsfrd/
cosyvoice/cli/frontend.py CHANGED
@@ -21,13 +21,13 @@ import torchaudio.compliance.kaldi as kaldi
21
  import torchaudio
22
  import os
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
 
@@ -64,8 +64,8 @@ class CosyVoiceFrontEnd:
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)
@@ -103,7 +103,7 @@ class CosyVoiceFrontEnd:
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)
 
21
  import torchaudio
22
  import os
23
  import inflect
 
 
24
  try:
25
  import ttsfrd
26
  use_ttsfrd = True
27
+ except ImportError:
28
+ print("failed to import ttsfrd, use WeTextProcessing instead")
29
+ from tn.chinese.normalizer import Normalizer as ZhNormalizer
30
+ from tn.english.normalizer import Normalizer as EnNormalizer
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
 
 
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)
 
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)
cosyvoice/dataset/processor.py CHANGED
@@ -22,7 +22,6 @@ from torch.nn.utils.rnn import pad_sequence
22
  import torch.nn.functional as F
23
 
24
  torchaudio.set_audio_backend('soundfile')
25
- torchaudio.utils.sox_utils.set_buffer_size(16500)
26
 
27
  AUDIO_FORMAT_SETS = set(['flac', 'mp3', 'm4a', 'ogg', 'opus', 'wav', 'wma'])
28
 
 
22
  import torch.nn.functional as F
23
 
24
  torchaudio.set_audio_backend('soundfile')
 
25
 
26
  AUDIO_FORMAT_SETS = set(['flac', 'mp3', 'm4a', 'ogg', 'opus', 'wav', 'wma'])
27
 
requirements.txt CHANGED
@@ -26,4 +26,4 @@ tensorboard==2.14.0
26
  torch==2.0.1
27
  torchaudio==2.0.2
28
  wget==3.2
29
- WeTextProcessing
 
26
  torch==2.0.1
27
  torchaudio==2.0.2
28
  wget==3.2
29
+ WeTextProcessing==1.0.3