Spaces:
Running
on
Zero
Running
on
Zero
compatible when ttsfrd is not avaliable
Browse files- README.md +4 -1
- cosyvoice/cli/frontend.py +17 -8
README.md
CHANGED
@@ -55,7 +55,10 @@ 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 |
-
|
|
|
|
|
|
|
59 |
``` sh
|
60 |
cd pretrained_models/CosyVoice-ttsfrd/
|
61 |
unzip resource.zip -d .
|
|
|
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/
|
64 |
unzip resource.zip -d .
|
cosyvoice/cli/frontend.py
CHANGED
@@ -21,7 +21,12 @@ import torchaudio.compliance.kaldi as kaldi
|
|
21 |
import torchaudio
|
22 |
import os
|
23 |
import inflect
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
from cosyvoice.utils.frontend_utils import contains_chinese, replace_blank, replace_corner_mark, remove_bracket, spell_out_number, split_paragraph
|
26 |
|
27 |
|
@@ -48,12 +53,14 @@ class CosyVoiceFrontEnd:
|
|
48 |
self.instruct = instruct
|
49 |
self.allowed_special = allowed_special
|
50 |
self.inflect_parser = inflect.engine()
|
51 |
-
self.
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
57 |
|
58 |
def _extract_text_token(self, text):
|
59 |
text_token = self.tokenizer.encode(text, allowed_special=self.allowed_special)
|
@@ -88,7 +95,9 @@ class CosyVoiceFrontEnd:
|
|
88 |
def text_normalize(self, text, split=True):
|
89 |
text = text.strip()
|
90 |
if contains_chinese(text):
|
91 |
-
|
|
|
|
|
92 |
text = replace_blank(text)
|
93 |
text = replace_corner_mark(text)
|
94 |
text = text.replace(".", "、")
|
|
|
21 |
import torchaudio
|
22 |
import os
|
23 |
import inflect
|
24 |
+
try:
|
25 |
+
import ttsfrd
|
26 |
+
use_ttsfrd = True
|
27 |
+
except:
|
28 |
+
print("failed to import ttsfrd, please normalize input text manually")
|
29 |
+
use_ttsfrd = False
|
30 |
from cosyvoice.utils.frontend_utils import contains_chinese, replace_blank, replace_corner_mark, remove_bracket, spell_out_number, split_paragraph
|
31 |
|
32 |
|
|
|
53 |
self.instruct = instruct
|
54 |
self.allowed_special = allowed_special
|
55 |
self.inflect_parser = inflect.engine()
|
56 |
+
self.use_ttsfrd = use_ttsfrd
|
57 |
+
if self.use_ttsfrd:
|
58 |
+
self.frd = ttsfrd.TtsFrontendEngine()
|
59 |
+
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
60 |
+
assert self.frd.initialize('{}/../../pretrained_models/CosyVoice-ttsfrd/resource'.format(ROOT_DIR)) is True, 'failed to initialize ttsfrd resource'
|
61 |
+
self.frd.set_lang_type('pinyin')
|
62 |
+
self.frd.enable_pinyin_mix(True)
|
63 |
+
self.frd.set_breakmodel_index(1)
|
64 |
|
65 |
def _extract_text_token(self, text):
|
66 |
text_token = self.tokenizer.encode(text, allowed_special=self.allowed_special)
|
|
|
95 |
def text_normalize(self, text, split=True):
|
96 |
text = text.strip()
|
97 |
if contains_chinese(text):
|
98 |
+
if self.use_ttsfrd:
|
99 |
+
text = self.frd.get_frd_extra_info(text, 'input')
|
100 |
+
text = text.replace("\n", "")
|
101 |
text = replace_blank(text)
|
102 |
text = replace_corner_mark(text)
|
103 |
text = text.replace(".", "、")
|