o
    ¡¿¯iÇ  ã                   @   s†   d Z ddlZddlmZ ddlmZ dd„ eeƒD ƒZdd„ eeƒD ƒZe d	¡Z	d
d„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )z+ from https://github.com/keithito/tacotron é    Né   )Úcleaners©Úsymbolsc                 C   s   i | ]\}}||“qS © r   ©Ú.0ÚiÚsr   r   úM/home/ubuntu/.local/lib/python3.10/site-packages/tacotron_cleaner/__init__.pyÚ
<dictcomp>
   ó    r   c                 C   s   i | ]\}}||“qS r   r   r   r   r   r   r      r   z(.*?)\{(.+?)\}(.*)c                 C   s|   g }t | ƒr5t | ¡}|s|tt| |ƒƒ7 }n|tt| d¡|ƒƒ7 }|t| d¡ƒ7 }| d¡} t | ƒs| td ¡ |S )aÆ  Converts a string of text to a sequence of IDs corresponding to the symbols in the text.

    The text can optionally have ARPAbet sequences enclosed in curly braces embedded
    in it. For example, "Turn left on {HH AW1 S S T AH0 N} Street."

    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
  r   é   é   ú~)	ÚlenÚ	_curly_reÚmatchÚ_symbols_to_sequenceÚ_clean_textÚgroupÚ_arpabet_to_sequenceÚappendÚ_symbol_to_id)ÚtextÚcleaner_namesÚsequenceÚmr   r   r   Útext_to_sequence   s   

ù
r   c                 C   sZ   d}| D ]"}|t v r&t | }t|ƒdkr"|d dkr"d|dd…  }||7 }q| dd¡S )	z+Converts a sequence of IDs back to a stringÚ r   r   ú@z{%s}Nz}{ú )Ú_id_to_symbolr   Úreplace)r   ÚresultÚ	symbol_idr
   r   r   r   Úsequence_to_text/   s   €r&   c                 C   s0   |D ]}t t|ƒ}|std| ƒ‚|| ƒ} q| S )NzUnknown cleaner: %s)Úgetattrr   Ú	Exception)r   r   ÚnameÚcleanerr   r   r   r   <   s   

r   c                 C   s   dd„ | D ƒS )Nc                 S   s   g | ]
}t |ƒrt| ‘qS r   )Ú_should_keep_symbolr   ©r   r
   r   r   r   Ú
<listcomp>F   s    z(_symbols_to_sequence.<locals>.<listcomp>r   r   r   r   r   r   E   s   r   c                 C   s   t dd„ |  ¡ D ƒƒS )Nc                 S   s   g | ]}d | ‘qS )r    r   r,   r   r   r   r-   J   s    z(_arpabet_to_sequence.<locals>.<listcomp>)r   Úsplit)r   r   r   r   r   I   s   r   c                 C   s   | t v o| duo| duS )NÚ_r   )r   )r
   r   r   r   r+   M   s   r+   )Ú__doc__Úrer   r   r   Ú	enumerater   r"   Úcompiler   r   r&   r   r   r   r+   r   r   r   r   Ú<module>   s    
	