Kafke/Code-Realize-TTS
0
1import re2import opencc3 4 5dialects = {'SZ': 'suzhou', 'WX': 'wuxi', 'CZ': 'changzhou', 'HZ': 'hangzhou',6 'SX': 'shaoxing', 'NB': 'ningbo', 'JJ': 'jingjiang', 'YX': 'yixing',7 'JD': 'jiading', 'ZR': 'zhenru', 'PH': 'pinghu', 'TX': 'tongxiang',8 'JS': 'jiashan', 'HN': 'xiashi', 'LP': 'linping', 'XS': 'xiaoshan',9 'FY': 'fuyang', 'RA': 'ruao', 'CX': 'cixi', 'SM': 'sanmen',10 'TT': 'tiantai', 'WZ': 'wenzhou', 'SC': 'suichang', 'YB': 'youbu'}11 12converters = {}13 14for dialect in dialects.values():15 try:16 converters[dialect] = opencc.OpenCC(dialect)17 except:18 pass19 20 21def ngu_dialect_to_ipa(text, dialect):22 dialect = dialects[dialect]23 text = converters[dialect].convert(text).replace('-','').replace('$',' ')24 text = re.sub(r'[、;:]', ',', text)25 text = re.sub(r'\s*,\s*', ', ', text)26 text = re.sub(r'\s*。\s*', '. ', text)27 text = re.sub(r'\s*?\s*', '? ', text)28 text = re.sub(r'\s*!\s*', '! ', text)29 text = re.sub(r'\s*$', '', text)30 return text31 