Spaces:
Running
on
Zero
Running
on
Zero
Update GPT_SoVITS/text/cleaner.py
Browse files- GPT_SoVITS/text/cleaner.py +73 -75
GPT_SoVITS/text/cleaner.py
CHANGED
@@ -1,75 +1,73 @@
|
|
1 |
-
from text import japanese, cleaned_text_to_sequence
|
2 |
-
print(japanese.__file__)
|
3 |
-
import os
|
4 |
-
if os.environ.get("version","v1")=="v1":
|
5 |
-
from text import
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
(
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
text
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
norm_text
|
31 |
-
|
32 |
-
norm_text
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
"""
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
new_ph.append(
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
if __name__ == "__main__":
|
75 |
-
print(clean_text("你好%啊啊啊额、还是到付红四方。", "zh"))
|
|
|
1 |
+
from text import japanese, cleaned_text_to_sequence
|
2 |
+
print(japanese.__file__)
|
3 |
+
import os
|
4 |
+
if os.environ.get("version","v1")=="v1":
|
5 |
+
from text.symbols import symbols
|
6 |
+
else:
|
7 |
+
from text.symbols2 import symbols
|
8 |
+
print("THIS IS IN CLEANER.py")
|
9 |
+
language_module_map = { "ja": japanese}
|
10 |
+
special = [
|
11 |
+
# ("%", "zh", "SP"),
|
12 |
+
("¥", "zh", "SP2"),
|
13 |
+
("^", "zh", "SP3"),
|
14 |
+
# ('@', 'zh', "SP4")#不搞鬼畜了,和第二版保持一致吧
|
15 |
+
]
|
16 |
+
|
17 |
+
|
18 |
+
def clean_text(text, language):
|
19 |
+
print('this is clean_text')
|
20 |
+
if(language not in language_module_map):
|
21 |
+
language="en"
|
22 |
+
text=" "
|
23 |
+
for special_s, special_l, target_symbol in special:
|
24 |
+
if special_s in text and language == special_l:
|
25 |
+
return clean_special(text, language, special_s, target_symbol)
|
26 |
+
language_module = language_module_map[language]
|
27 |
+
if hasattr(language_module,"text_normalize"):
|
28 |
+
norm_text = language_module.text_normalize(text)
|
29 |
+
else:
|
30 |
+
norm_text=text
|
31 |
+
if language == "zh" or language=="yue":##########
|
32 |
+
phones, word2ph = language_module.g2p(norm_text)
|
33 |
+
assert len(phones) == sum(word2ph)
|
34 |
+
assert len(norm_text) == len(word2ph)
|
35 |
+
elif language == "en":
|
36 |
+
phones = language_module.g2p(norm_text)
|
37 |
+
if len(phones) < 4:
|
38 |
+
phones = [','] * (4 - len(phones)) + phones
|
39 |
+
word2ph = None
|
40 |
+
else:
|
41 |
+
phones = language_module.g2p(norm_text)
|
42 |
+
word2ph = None
|
43 |
+
|
44 |
+
for ph in phones:
|
45 |
+
assert ph in symbols, ph
|
46 |
+
return phones, word2ph, norm_text
|
47 |
+
|
48 |
+
|
49 |
+
def clean_special(text, language, special_s, target_symbol):
|
50 |
+
"""
|
51 |
+
特殊静音段sp符号处理
|
52 |
+
"""
|
53 |
+
text = text.replace(special_s, ",")
|
54 |
+
language_module = language_module_map[language]
|
55 |
+
norm_text = language_module.text_normalize(text)
|
56 |
+
phones = language_module.g2p(norm_text)
|
57 |
+
new_ph = []
|
58 |
+
for ph in phones[0]:
|
59 |
+
assert ph in symbols
|
60 |
+
if ph == ",":
|
61 |
+
new_ph.append(target_symbol)
|
62 |
+
else:
|
63 |
+
new_ph.append(ph)
|
64 |
+
return new_ph, phones[1], norm_text
|
65 |
+
|
66 |
+
|
67 |
+
def text_to_sequence(text, language):
|
68 |
+
phones = clean_text(text)
|
69 |
+
return cleaned_text_to_sequence(phones)
|
70 |
+
|
71 |
+
|
72 |
+
if __name__ == "__main__":
|
73 |
+
print(clean_text("你好%啊啊啊额、还是到付红四方。", "zh"))
|
|
|
|