MRiwu/Collection
1
1""" from https://github.com/keithito/tacotron """2from text import cleaners3 4 5def text_to_sequence(text, symbols, cleaner_names):6 '''Converts a string of text to a sequence of IDs corresponding to the symbols in the text.7 Args:8 text: string to convert to a sequence9 cleaner_names: names of the cleaner functions to run the text through10 Returns:11 List of integers corresponding to the symbols in the text12 '''13 _symbol_to_id = {s: i for i, s in enumerate(symbols)}14 15 sequence = []16 17 clean_text = _clean_text(text, cleaner_names)18 for symbol in clean_text:19 if symbol not in _symbol_to_id.keys():20 continue21 symbol_id = _symbol_to_id[symbol]22 sequence += [symbol_id]23 return sequence24 25 26def _clean_text(text, cleaner_names):27 for name in cleaner_names:28 cleaner = getattr(cleaners, name)29 if not cleaner:30 raise Exception('Unknown cleaner: %s' % name)31 text = cleaner(text)32 return text33 