From 798179652357711796aa937e9a4b17a813c60afd Mon Sep 17 00:00:00 2001 From: "lyuxiang.lx" Date: Tue, 9 Jul 2024 23:37:54 +0800 Subject: [PATCH] add WeTextProcessing --- README.md | 6 ++++-- cosyvoice/cli/frontend.py | 14 +++++++------- cosyvoice/dataset/processor.py | 1 - requirements.txt | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 69438e3..3b4783a 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,8 @@ git submodule update --init --recursive ``` sh conda create -n cosyvoice python=3.8 conda activate cosyvoice +# pynini is required by WeTextProcessing, use conda to install it as it can be executed on all platform. +conda install -y -c conda-forge pynini==2.1.5 pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host=mirrors.aliyun.com # If you encounter sox compatibility issues @@ -55,9 +57,9 @@ git clone https://www.modelscope.cn/iic/CosyVoice-300M-Instruct.git pretrained_m git clone https://www.modelscope.cn/iic/CosyVoice-ttsfrd.git pretrained_models/CosyVoice-ttsfrd ``` -Optionaly, you can unzip `ttsfrd` resouce and install `ttsfrd` package. +Optionaly, you can unzip `ttsfrd` resouce and install `ttsfrd` package for better text normalization performance. -Notice that this step is not necessary. If you do not install `ttsfrd` package, you need to normalize input text manually. +Notice that this step is not necessary. If you do not install `ttsfrd` package, we will use WeTextProcessing by default. ``` sh cd pretrained_models/CosyVoice-ttsfrd/ diff --git a/cosyvoice/cli/frontend.py b/cosyvoice/cli/frontend.py index c30135a..d2983b7 100644 --- a/cosyvoice/cli/frontend.py +++ b/cosyvoice/cli/frontend.py @@ -21,13 +21,13 @@ 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 -except: - print("failed to import ttsfrd, please normalize input text manually") +except ImportError: + print("failed to import ttsfrd, use WeTextProcessing instead") + from tn.chinese.normalizer import Normalizer as ZhNormalizer + from tn.english.normalizer import Normalizer as EnNormalizer use_ttsfrd = False from cosyvoice.utils.frontend_utils import contains_chinese, replace_blank, replace_corner_mark, remove_bracket, spell_out_number, split_paragraph @@ -64,8 +64,8 @@ class CosyVoiceFrontEnd: 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() + 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) @@ -103,7 +103,7 @@ class CosyVoiceFrontEnd: if self.use_ttsfrd: text = self.frd.get_frd_extra_info(text, 'input') else: - text = self.zh_tn_model.normalize(text) + text = self.zh_tn_model.normalize(text) text = text.replace("\n", "") text = replace_blank(text) text = replace_corner_mark(text) diff --git a/cosyvoice/dataset/processor.py b/cosyvoice/dataset/processor.py index fa8b339..9477d02 100644 --- a/cosyvoice/dataset/processor.py +++ b/cosyvoice/dataset/processor.py @@ -22,7 +22,6 @@ from torch.nn.utils.rnn import pad_sequence import torch.nn.functional as F torchaudio.set_audio_backend('soundfile') -torchaudio.utils.sox_utils.set_buffer_size(16500) AUDIO_FORMAT_SETS = set(['flac', 'mp3', 'm4a', 'ogg', 'opus', 'wav', 'wma']) diff --git a/requirements.txt b/requirements.txt index 24639f2..46df823 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,4 +26,4 @@ tensorboard==2.14.0 torch==2.0.1 torchaudio==2.0.2 wget==3.2 -WeTextProcessing +WeTextProcessing==1.0.3