Commit ยท
00bfabc
1
Parent(s): dd205e4
add front end
Browse filesFiles changed (3)
- indextts/infer.py+5-8
- indextts/utils/front.pyAdded+96
- requirements.txt+2-1
5 unmodified lines6789101129 unmodified lines414243444546474849505152535455565 unmodified linesfrom omegaconf import OmegaConfimport sentencepiece as spmfrom utils.common import tokenize_by_CJK_charfrom utils.feature_extractors import MelSpectrogramFeaturesfrom indextts.vqvae.xtts_dvae import DiscreteVAE29 unmodified linesself.bigvgan = self.bigvgan.to(self.device)self.bigvgan.eval()print(">> bigvgan weights restored from:", self.bigvgan_path)def preprocess_text(self, text):chinese_punctuation = "๏ผใ๏ผ๏ผ๏ผ๏ผโโโโ๏ผ๏ผใใใใ"english_punctuation = ",.!?;:\"\"''()[]<>"# ๅๅปบไธไธชๆ ๅฐๅญๅ ธpunctuation_map = str.maketrans(chinese_punctuation, english_punctuation)# ไฝฟ็จtranslateๆนๆณๆฟๆขๆ ็น็ฌฆๅทreturn text.translate(punctuation_map)def infer(self, audio_prompt, text, output_path):text = self.preprocess_text(text)5 unmodified lines678910111229 unmodified lines4243444546474849505152535 unmodified linesfrom omegaconf import OmegaConfimport sentencepiece as spmfrom indextts.utils.front import TextNormalizerfrom utils.common import tokenize_by_CJK_charfrom utils.feature_extractors import MelSpectrogramFeaturesfrom indextts.vqvae.xtts_dvae import DiscreteVAE29 unmodified linesself.bigvgan = self.bigvgan.to(self.device)self.bigvgan.eval()print(">> bigvgan weights restored from:", self.bigvgan_path)self.normalizer = TextNormalizer()self.normalizer.load()print(">> TextNormalizer loaded")def preprocess_text(self, text):return self.normalizer.infer(text)def infer(self, audio_prompt, text, output_path):text = self.preprocess_text(text)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596# -*- coding: utf-8 -*-import tracebackimport osimport sysimport reimport re
class TextNormalizer: def __init__(self): # self.normalizer = Normalizer(cache_dir="textprocessing/tn") self.zh_normalizer = None self.en_normalizer = None self.char_rep_map = { "๏ผ": ",", "๏ผ": ",", ";": ",", "๏ผ": ",", "ใ": ".", "๏ผ": "!", "๏ผ": "?", "\n": ".", "ยท": ",", "ใ": ",", "...": "โฆ", "โฆโฆ": "โฆ", "$": ".", "โ": "'", "โ": "'", '"': "'", "โ": "'", "โ": "'", "๏ผ": "'", "๏ผ": "'", "(": "'", ")": "'", "ใ": "'", "ใ": "'", "ใ": "'", "ใ": "'", "[": "'", "]": "'", "โ": "-", "๏ฝ": "-", "~": "-", "ใ": "'", "ใ": "'", ":": ",", }
def match_email(self, email): # ๆญฃๅ่กจ่พพๅผๅน้
้ฎ็ฎฑๆ ผๅผ๏ผๆฐๅญ่ฑๆ@ๆฐๅญ่ฑๆ.่ฑๆ pattern = r'^[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]+$' return re.match(pattern, email) is not None
def use_chinese(self, s): has_chinese = bool(re.search(r'[\u4e00-\u9fff]', s)) has_digit = bool(re.search(r'\d', s)) has_alpha = bool(re.search(r'[a-zA-Z]', s)) is_email = self.match_email(s) if has_chinese or not has_alpha or is_email: return True else: return False
def load(self): # print(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) # sys.path.append(model_dir)
from tn.chinese.normalizer import Normalizer as NormalizerZh from tn.english.normalizer import Normalizer as NormalizerEn
self.zh_normalizer = NormalizerZh(remove_interjections=False, remove_erhua=False) self.en_normalizer = NormalizerEn()
def infer(self, text): pattern = re.compile("|".join(re.escape(p) for p in self.char_rep_map.keys())) replaced_text = pattern.sub(lambda x: self.char_rep_map[x.group()], text) if not self.zh_normalizer or not self.en_normalizer: print("Error, text normalizer is not initialized !!!") return "" try: normalizer = self.zh_normalizer if self.use_chinese(text) else self.en_normalizer result = normalizer.normalize(text) except Exception: result = "" print(traceback.format_exc()) return result
if __name__ == '__main__': # ๆต่ฏ็จๅบ text_normalizer = TextNormalizer() print(text_normalizer.infer("2.5ๅนณๆน็ต็บฟ"))19 unmodified lines2021222319 unmodified linespypinyinlibrosagradiotqdm19 unmodified lines202122232419 unmodified linespypinyinlibrosagradiotqdmWeTextProcessing
indextts/infer.py+5-8
indextts/utils/front.pyAdded+96
requirements.txt+2-1