Refactor: Format Code with Ruff and Update Deprecated G2PW Link (#2255)
* ruff check --fix * ruff format --line-length 120 --target-version py39 * Change the link for G2PW Model * update pytorch version and colab
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
# reference: https://huggingface.co/spaces/Naozumi0512/Bert-VITS2-Cantonese-Yue/blob/main/text/chinese.py
|
||||
|
||||
import sys
|
||||
import re
|
||||
import cn2an
|
||||
import ToJyutping
|
||||
@@ -99,9 +98,7 @@ def replace_punctuation(text):
|
||||
|
||||
replaced_text = pattern.sub(lambda x: rep_map[x.group()], text)
|
||||
|
||||
replaced_text = re.sub(
|
||||
r"[^\u4e00-\u9fa5" + "".join(punctuation) + r"]+", "", replaced_text
|
||||
)
|
||||
replaced_text = re.sub(r"[^\u4e00-\u9fa5" + "".join(punctuation) + r"]+", "", replaced_text)
|
||||
|
||||
return replaced_text
|
||||
|
||||
@@ -115,7 +112,9 @@ def text_normalize(text):
|
||||
return dest_text
|
||||
|
||||
|
||||
punctuation_set=set(punctuation)
|
||||
punctuation_set = set(punctuation)
|
||||
|
||||
|
||||
def jyuping_to_initials_finals_tones(jyuping_syllables):
|
||||
initials_finals = []
|
||||
tones = []
|
||||
@@ -160,12 +159,14 @@ def jyuping_to_initials_finals_tones(jyuping_syllables):
|
||||
assert len(initials_finals) == len(tones)
|
||||
|
||||
###魔改为辅音+带音调的元音
|
||||
phones=[]
|
||||
for a,b in zip(initials_finals,tones):
|
||||
if(b not in [-1,0]):###防止粤语和普通话重合开头加Y,如果是标点,不加。
|
||||
todo="%s%s"%(a,b)
|
||||
else:todo=a
|
||||
if(todo not in punctuation_set):todo="Y%s"%todo
|
||||
phones = []
|
||||
for a, b in zip(initials_finals, tones):
|
||||
if b not in [-1, 0]: ###防止粤语和普通话重合开头加Y,如果是标点,不加。
|
||||
todo = "%s%s" % (a, b)
|
||||
else:
|
||||
todo = a
|
||||
if todo not in punctuation_set:
|
||||
todo = "Y%s" % todo
|
||||
phones.append(todo)
|
||||
|
||||
# return initials_finals, tones, word2ph
|
||||
@@ -218,4 +219,4 @@ if __name__ == "__main__":
|
||||
# phones, tones, word2ph = g2p(text)
|
||||
phones, word2ph = g2p(text)
|
||||
# print(phones, tones, word2ph)
|
||||
print(phones, word2ph)
|
||||
print(phones, word2ph)
|
||||
|
||||
Reference in New Issue
Block a user