o
    
j                     @   s:   d dl Z d dlmZmZ d dlmZ G dd de jZdS )    N)ListTuple)Punctuationc                   @   s   e Zd ZdZe dfddZdd Zedd Z	e
ejd	d
 Zeejdd Zeejdd Ze
ejdd Zdd Zejdd Zdeee ef fddZdefddZd$dededefddZd%d!efd"d#ZdS )&BasePhonemizerav  Base phonemizer class

    Phonemization follows the following steps:
        1. Preprocessing:
            - remove empty lines
            - remove punctuation
            - keep track of punctuation marks

        2. Phonemization:
            - convert text to phonemes

        3. Postprocessing:
            - join phonemes
            - restore punctuation marks

    Args:
        language (str):
            Language used by the phonemizer.

        punctuations (List[str]):
            List of punctuation marks to be preserved.

        keep_puncs (bool):
            Whether to preserve punctuation marks or not.
    Fc                 C   s:   |   std|  | || _|| _t|| _d S )Nz{} not installed on your system)	is_availableRuntimeErrorformatname_init_language	_language_keep_puncsr   _punctuator)selflanguagepunctuations
keep_puncs r   V/home/kuhnn/.local/lib/python3.10/site-packages/TTS/tts/utils/text/phonemizers/base.py__init__"   s
   zBasePhonemizer.__init__c                 C   s(   |  |std| d|   d|S )zpLanguage initialization

        This method may be overloaded in child classes (see Segments backend)

        z
language "z" is not supported by the z backend)is_supported_languager   r	   r   r   r   r   r   r
   .   s   
zBasePhonemizer._init_languagec                 C   s   | j S )z9The language code configured to be used for phonemization)r   )r   r   r   r   r   8   s   zBasePhonemizer.languagec                   C      dS )zThe name of the backendNr   r   r   r   r   r	   =      zBasePhonemizer.namec                 C   r   )z9Returns True if the backend is installed, False otherwiseNr   clsr   r   r   r   C   r   zBasePhonemizer.is_availablec                 C   r   )z;Return the backend version as a tuple (major, minor, patch)Nr   r   r   r   r   versionI   r   zBasePhonemizer.versionc                   C   r   )z@Return a dict of language codes -> name supported by the backendNr   r   r   r   r   supported_languagesO   r   z"BasePhonemizer.supported_languagesc                 C   s   ||   v S )z6Returns True if `language` is supported by the backend)r   r   r   r   r   r   U   s   z$BasePhonemizer.is_supported_languagec                 C   r   )zThe main phonemization methodNr   )r   text	separatorr   r   r   
_phonemizeY   s    zBasePhonemizer._phonemizereturnc                 C   s,   |  }| jr| j|S | j |gg fS )zPreprocess the text before phonemization

        1. remove spaces
        2. remove punctuation

        Override this if you need a different behaviour
        )stripr   r   strip_to_restore)r   r   r   r   r   _phonemize_preprocess]   s   z$BasePhonemizer._phonemize_preprocessc                 C   s    | j r| j||d S |d S )zgPostprocess the raw phonemized output

        Override this if you need a different behaviour
        r   )r   r   restore)r   
phonemizedr   r   r   r   _phonemize_postprocessk   s   z%BasePhonemizer._phonemize_postprocess|Nr   r   c                 C   sB   |  |\}}g }|D ]}| ||}|| q| ||}|S )a&  Returns the `text` phonemized for the given language

        Args:
            text (str):
                Text to be phonemized.

            separator (str):
                string separator used between phonemes. Default to '_'.

        Returns:
            (str): Phonemized text
        )r#   r   appendr&   )r   r   r   r   r   r%   tpr   r   r   	phonemizet   s   zBasePhonemizer.phonemizer   levelc                 C   s6   d| }t | d| j  t | d|    d S )N	z| > phoneme language: z| > phoneme backend: )printr   r	   )r   r,   indentr   r   r   
print_logs   s   zBasePhonemizer.print_logs)r'   N)r   )__name__
__module____qualname____doc__r   default_puncsr   r
   propertyr   staticmethodabcabstractmethodr	   classmethodr   r   r   r   r   r   r   strr#   r&   r+   intr0   r   r   r   r   r      s2    


	r   )r8   typingr   r   TTS.tts.utils.text.punctuationr   ABCr   r   r   r   r   <module>   s    