Refactor: moved text/cleaner.py to style_bert_vits2/text_processing/
This commit is contained in:
@@ -168,7 +168,7 @@ def _g2p(segments):
|
||||
return phones_list, tones_list, word2ph
|
||||
|
||||
|
||||
def text_normalize(text):
|
||||
def normalize_text(text):
|
||||
numbers = re.findall(r"\d+(?:\.?\d+)?", text)
|
||||
for number in numbers:
|
||||
text = text.replace(number, cn2an.an2cn(number), 1)
|
||||
@@ -186,7 +186,7 @@ if __name__ == "__main__":
|
||||
from text.chinese_bert import get_bert_feature
|
||||
|
||||
text = "啊!但是《原神》是由,米哈\游自主, [研发]的一款全.新开放世界.冒险游戏"
|
||||
text = text_normalize(text)
|
||||
text = normalize_text(text)
|
||||
print(text)
|
||||
phones, tones, word2ph = g2p(text)
|
||||
bert = get_bert_feature(text, word2ph)
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
def clean_text(text, language, use_jp_extra=True, raise_yomi_error=False):
|
||||
# Changed to import inside if condition to avoid unnecessary import
|
||||
if language == "ZH":
|
||||
from . import chinese as language_module
|
||||
|
||||
norm_text = language_module.text_normalize(text)
|
||||
phones, tones, word2ph = language_module.g2p(norm_text)
|
||||
elif language == "EN":
|
||||
from . import english as language_module
|
||||
|
||||
norm_text = language_module.text_normalize(text)
|
||||
phones, tones, word2ph = language_module.g2p(norm_text)
|
||||
elif language == "JP":
|
||||
from . import japanese as language_module
|
||||
|
||||
norm_text = language_module.text_normalize(text)
|
||||
phones, tones, word2ph = language_module.g2p(
|
||||
norm_text, use_jp_extra, raise_yomi_error=raise_yomi_error
|
||||
)
|
||||
else:
|
||||
raise ValueError(f"Language {language} not supported")
|
||||
return norm_text, phones, tones, word2ph
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
@@ -369,7 +369,7 @@ def normalize_numbers(text):
|
||||
return text
|
||||
|
||||
|
||||
def text_normalize(text):
|
||||
def normalize_text(text):
|
||||
text = normalize_numbers(text)
|
||||
text = replace_punctuation(text)
|
||||
text = re.sub(r"([,;.\?\!])([\w])", r"\1 \2", text)
|
||||
|
||||
@@ -96,7 +96,7 @@ rep_map = {
|
||||
}
|
||||
|
||||
|
||||
def text_normalize(text):
|
||||
def normalize_text(text):
|
||||
"""
|
||||
日本語のテキストを正規化する。
|
||||
結果は、ちょうど次の文字のみからなる:
|
||||
@@ -177,7 +177,7 @@ def g2p(
|
||||
norm_text: str, use_jp_extra: bool = True, raise_yomi_error: bool = False
|
||||
) -> tuple[list[str], list[int], list[int]]:
|
||||
"""
|
||||
他で使われるメインの関数。`text_normalize()`で正規化された`norm_text`を受け取り、
|
||||
他で使われるメインの関数。`normalize_text()`で正規化された`norm_text`を受け取り、
|
||||
- phones: 音素のリスト(ただし`!`や`,`や`.`等punctuationが含まれうる)
|
||||
- tones: アクセントのリスト、0(低)と1(高)からなり、phonesと同じ長さ
|
||||
- word2ph: 元のテキストの各文字に音素が何個割り当てられるかを表すリスト
|
||||
@@ -350,7 +350,7 @@ def text2sep_kata(
|
||||
norm_text: str, raise_yomi_error: bool = False
|
||||
) -> tuple[list[str], list[str]]:
|
||||
"""
|
||||
`text_normalize`で正規化済みの`norm_text`を受け取り、それを単語分割し、
|
||||
`normalize_text()`で正規化済みの`norm_text`を受け取り、それを単語分割し、
|
||||
分割された単語リストとその読み(カタカナor記号1文字)のリストのタプルを返す。
|
||||
単語分割結果は、`g2p()`の`word2ph`で1文字あたりに割り振る音素記号の数を決めるために使う。
|
||||
例:
|
||||
@@ -634,7 +634,7 @@ if __name__ == "__main__":
|
||||
text = "こんにちは、世界。"
|
||||
from text.japanese_bert import get_bert_feature
|
||||
|
||||
text = text_normalize(text)
|
||||
text = normalize_text(text)
|
||||
|
||||
phones, tones, word2ph = g2p(text)
|
||||
bert = get_bert_feature(text, word2ph)
|
||||
|
||||
Reference in New Issue
Block a user