o
    }o™iŸ  ã                   @   s<   d dl mZmZ d dlmZ d dlmZ G dd„ deƒZdS )é    )ÚABCÚabstractmethod)ÚOptional)Úloggingc                   @   sT   e Zd Zddd„ ddfdee fdd„Zededefd	d
„ƒZ	ddefdd„ZdS )ÚBaseG2pNc                 C   s   | S ©N© )Úxr   r   úX/home/ubuntu/.local/lib/python3.10/site-packages/nemo/collections/tts/g2p/models/base.pyÚ<lambda>   s    zBaseG2p.<lambda>Úmapping_filec                 C   s"   || _ || _|| _|| _d| _dS )a²  Abstract class for creating an arbitrary module to convert grapheme words
        to phoneme sequences, leave unchanged, or use apply_to_oov_word.
        Args:
            phoneme_dict: Arbitrary representation of dictionary (phoneme -> grapheme) for known words.
            word_tokenize_func: Function for tokenizing text to words.
            apply_to_oov_word: Function that will be applied to out of phoneme_dict word.
        N)Úphoneme_dictÚword_tokenize_funcÚapply_to_oov_wordr   Úheteronym_model)Úselfr   r   r   r   r   r   r
   Ú__init__   s
   
zBaseG2p.__init__ÚtextÚreturnc                 C   s   d S r   r   )r   r   r   r   r
   Ú__call__)   s   zBaseG2p.__call__úA../../../scripts/tts_dataset_files/wordid_to_ipa-0.7b_nv22.10.tsvÚwordid_to_phonemes_filec              
   C   s`   zddl m} || _| j |¡ W dS  ty/ } zt d¡ t |¡ W Y d}~dS d}~ww )a5  
        Add heteronym classification model to TTS preprocessing pipeline to disambiguate heteronyms.
            Heteronym model has a list of supported heteronyms but only heteronyms specified in
            wordid_to_phonemes_file will be converted to phoneme form during heteronym model inference;
            the rest will be left in grapheme form.

        Args:
            heteronym_model: Initialized HeteronymClassificationModel
            wordid_to_phonemes_file: Path to a file with mapping from wordid predicted by heteronym model to phonemes
        r   )ÚHeteronymClassificationModelz%Heteronym model setup will be skippedN)Ú8nemo.collections.tts.g2p.models.heteronym_classificationr   r   Úset_wordid_to_phonemesÚImportErrorr   ÚwarningÚerror)r   r   r   r   Úer   r   r
   Úsetup_heteronym_model.   s   
€þzBaseG2p.setup_heteronym_model)r   )	Ú__name__Ú
__module__Ú__qualname__r   Ústrr   r   r   r   r   r   r   r
   r      s    û
ûýýr   N)Úabcr   r   Útypingr   Ú
nemo.utilsr   r   r   r   r   r
   Ú<module>   s   