o "e @sxdZddlmZddlmZddeeDZddeeDZddZd d Z dd lm Z d d Z ddZ ddZ dS)z+ from https://github.com/keithito/tacotron )cleaners)symbolscCi|]\}}||qSr.0isrr%/workspace/OpenVoice/text/__init__.py r cCsi|]\}}||qSrrrrrr r r cCszg}ddt|D}t||}t|tdt||D]}||vr(q||}||g7}qtdt||S)a*Converts a string of text to a sequence of IDs corresponding to the symbols in the text. Args: text: string to convert to a sequence cleaner_names: names of the cleaner functions to run the text through Returns: List of integers corresponding to the symbols in the text cSrrrrrrr r r z$text_to_sequence..z length:) enumerate _clean_textprintlenkeys)textr cleaner_namessequence symbol_to_id clean_textsymbol symbol_idrrr text_to_sequence s   rcs(ddt|Dfdd|D}|S)zConverts a string of text to a sequence of IDs corresponding to the symbols in the text. Args: text: string to convert to a sequence Returns: List of integers corresponding to the symbols in the text cSrrrrrrr r (r z,cleaned_text_to_sequence..cs g|] }|vr|qSr)rrrrrr )s z,cleaned_text_to_sequence..)r ) cleaned_textrrrrr cleaned_text_to_sequence!sr)language_tone_start_mapcstddt|Dddt|D}fdd|D}t|fdd|D}||fdd|D}|||fS)zConverts a string of text to a sequence of IDs corresponding to the symbols in the text. Args: text: string to convert to a sequence Returns: List of integers corresponding to the symbols in the text cSrrrrrrr r 6r z2cleaned_text_to_sequence_vits2..cSrrrrrrr r 7r csg|]}|qSrrrrrr r8z2cleaned_text_to_sequence_vits2..csg|]}|qSrrrr) tone_startrr r:r csg|]}qSrrr!)lang_idrr r<s)r r)rZtoneslanguager languagesZlanguage_id_mapZphoneslang_idsr)r#rr"r cleaned_text_to_sequence_vits2/s r'cCs"d}|D] }t|}||7}q|S)z+Converts a sequence of IDs back to a string) _id_to_symbol)rresultrr rrr sequence_to_text@s  r+cCs0|D]}tt|}|std|||}q|S)NzUnknown cleaner: %s)getattrr Exception)rrnameZcleanerrrr rIs    rN)__doc__rrZ text.symbolsrr Z _symbol_to_idr)rrrr'r+rrrrr s