Files
jarvis-models/tts/vits/text/ngu_dialect.py
2024-03-19 17:33:09 +08:00

31 lines
1.0 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.

import re
import opencc
dialects = {'SZ': 'suzhou', 'WX': 'wuxi', 'CZ': 'changzhou', 'HZ': 'hangzhou',
'SX': 'shaoxing', 'NB': 'ningbo', 'JJ': 'jingjiang', 'YX': 'yixing',
'JD': 'jiading', 'ZR': 'zhenru', 'PH': 'pinghu', 'TX': 'tongxiang',
'JS': 'jiashan', 'HN': 'xiashi', 'LP': 'linping', 'XS': 'xiaoshan',
'FY': 'fuyang', 'RA': 'ruao', 'CX': 'cixi', 'SM': 'sanmen',
'TT': 'tiantai', 'WZ': 'wenzhou', 'SC': 'suichang', 'YB': 'youbu'}
converters = {}
for dialect in dialects.values():
try:
converters[dialect] = opencc.OpenCC(dialect)
except:
pass
def ngu_dialect_to_ipa(text, dialect):
dialect = dialects[dialect]
text = converters[dialect].convert(text).replace('-','').replace('$',' ')
text = re.sub(r'[、;:]', '', text)
text = re.sub(r'\s*\s*', ', ', text)
text = re.sub(r'\s*。\s*', '. ', text)
text = re.sub(r'\s*\s*', '? ', text)
text = re.sub(r'\s*\s*', '! ', text)
text = re.sub(r'\s*$', '', text)
return text