Files
AIFSH-FireRedTTS-ComfyUI/fireredtts/modules/text_normalizer/utils.py
T
2024-10-15 10:59:18 +08:00

122 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from fireredtts.modules.text_normalizer.regex_common import *
def contains_chinese(text):
return bool(chinese_regex.search(text))
def strip_kaomoji(text):
return kaomoji_regex.sub(" ", text)
def is_chinese(char):
return chinese_char_regex.match(char)
def is_eng_and_digit(char):
return eng_and_digit_char_regex.match(char)
def is_upper_eng_and_digit(text):
return upper_eng_and_digit_regex.match(text)
def is_valid_char(char):
return valid_char_regex.match(char)
def is_digit(text):
return digit_regex.match(text)
def contains_chinese(text):
return bool(chinese_regex.search(text))
def f2b(ustr, exemption="。,:"):
half = []
for u in ustr:
num = ord(u)
if num == 0x3000:
half.append(" ")
elif u in exemption: # exemption
half.append(u)
elif 0xFF01 <= num <= 0xFF5E:
num -= 0xFEE0
half.append(chr(num))
else:
half.append(u)
return "".join(half)
symbol_reduction = {
"「": '"',
"」": '"',
"`": '"',
"〝": '"',
"〞": '"',
"‟": '"',
"„": '"',
"{": "(",
"}": ")",
"【": "(",
"】": ")",
"〖": "(",
"〗": ")",
"〔": "(",
"〕": ")",
"〘": "(",
"〙": ")",
"《": "(",
"》": ")",
"⦅": "(",
"⦆": ")",
"〚": "(",
"〛": ")",
"『": '"',
"』": '"',
"「": '"',
"」": '"',
"{": "(",
"}": ")",
"〈": "(",
"〉": ")",
"•": "·",
"‧": "·",
"〰": "…",
"﹏": "…",
"〜": "~",
"~": "~",
"+": "+",
"、": "、",
"。": "。",
"︐": ",",
"﹐": ",",
"︑": "、",
"﹑": "、",
"︒": "。",
"︓": ":",
"﹕": ":",
"︔": ";",
"﹔": ";",
"︕": "!",
"﹗": "!",
"︖": "?",
"﹖": "?",
"﹙": "(",
"﹚": ")",
"﹪": "%",
"﹠": "&",
">": ">",
"|": "、",
"=": "=",
"‐": "-",
"‑": "-",
"‒": "-",
"–": "-",
"—": "-",
"―": "-",
"%": "%",
"μ": "u",
}