Ë
    T^(h¬$  ã                   óÚ   — d Z ddlZddlZddlZddlmZmZmZmZm	Z	m
Z
 ddlmZ ddlmZmZmZ  e«       rddlZ e«       rddlZ ej(                  e«      ZddiZd	„ Z G d
„ de«      ZdgZy)zTokenization class for VITS.é    N)ÚAnyÚDictÚListÚOptionalÚTupleÚUnioné   )ÚPreTrainedTokenizer)Úis_phonemizer_availableÚis_uroman_availableÚloggingÚ
vocab_filez
vocab.jsonc                 óZ   — t        j                  d«      }|j                  | «      }|d u}|S )Nz[^\x00-\x7F])ÚreÚcompileÚsearch)Úinput_stringÚnon_roman_patternÚmatchÚhas_non_romans       úh/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/vits/tokenization_vits.pyÚhas_non_roman_charactersr   %   s3   € äŸ
™
 ?Ó3Ðð ×$Ñ$ \Ó2€EØ Ð%€MØÐó    c                   óþ   ‡ — e Zd ZdZeZddgZ	 	 	 	 	 	 	 d	 dˆ fd„Zed„ «       Z	d„ Z
d	„ Zd
„ Z	 ddededee   deeeeef   f   fd„Zdedee   fd„Zdee   defd„Zd„ Zd„ Zddedee   deee   df   fd„Zˆ xZS )ÚVitsTokenizeraÀ  
    Construct a VITS tokenizer. Also supports MMS-TTS.

    This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users should refer to
    this superclass for more information regarding those methods.

    Args:
        vocab_file (`str`):
            Path to the vocabulary file.
        language (`str`, *optional*):
            Language identifier.
        add_blank (`bool`, *optional*, defaults to `True`):
            Whether to insert token id 0 in between the other tokens.
        normalize (`bool`, *optional*, defaults to `True`):
            Whether to normalize the input text by removing all casing and punctuation.
        phonemize (`bool`, *optional*, defaults to `True`):
            Whether to convert the input text into phonemes.
        is_uroman (`bool`, *optional*, defaults to `False`):
            Whether the `uroman` Romanizer needs to be applied to the input text prior to tokenizing.
    Ú	input_idsÚattention_maskNÚreturnc	                 ód  •— t        |d¬«      5 }
t        j                  |
«      | _        d d d «       | j                  j	                  «       D ��ci c]  \  }}||“Œ
 c}}| _        || _        || _        || _        || _	        || _
        t        ‰| �0  d|||||||dœ|	¤Ž y # 1 sw Y   ŒwxY wc c}}w )Núutf-8©Úencoding)Ú	pad_tokenÚ	unk_tokenÚlanguageÚ	add_blankÚ	normalizeÚ	phonemizeÚ	is_uroman© )ÚopenÚjsonÚloadÚencoderÚitemsÚdecoderr%   r&   r'   r(   r)   ÚsuperÚ__init__)Úselfr   r#   r$   r%   r&   r'   r(   r)   ÚkwargsÚvocab_handleÚkÚvÚ	__class__s                €r   r2   zVitsTokenizer.__init__H   s·   ø€ ô �* wÔ/ð 	3°<ÜŸ9™9 \Ó2ˆDŒL÷	3ð *.¯©×);Ñ);Ó)=×>¡  A˜˜1™Ó>ˆŒØ ˆŒØ"ˆŒØ"ˆŒØ"ˆŒà"ˆŒä‰Ñð 		
ØØØØØØØñ		
ð ó		
÷	3ð 	3üó ?s   �B ÁB,Â B)c                 ó,   — t        | j                  «      S ©N)Úlenr.   )r3   s    r   Ú
vocab_sizezVitsTokenizer.vocab_sizej   s   € ä�4—<‘<Ó Ð r   c                 óª   — t        | j                  «      D �ci c]  }| j                  |«      |“Œ }}|j                  | j                  «       |S c c}w r:   )Úranger<   Úconvert_ids_to_tokensÚupdateÚadded_tokens_encoder)r3   ÚiÚvocabs      r   Ú	get_vocabzVitsTokenizer.get_vocabn   sK   € Ü;@ÀÇÁÓ;QÖR°a�×+Ñ+¨AÓ.°Ñ1ÐRˆÐRØ�‰�T×.Ñ.Ô/Øˆùò Ss   ˜Ac                 óx  — t        | j                  j                  «       «      t        | j                  j                  «       «      z   }d}d}|t	        |«      k  r`d}|D ]-  }|||t	        |«      z    |k(  sŒ||z  }|t	        |«      z  }d} n |s|||   j                  «       z  }|dz  }|t	        |«      k  rŒ`|S )zfLowercase the input string, respecting any special token ids that may be part or entirely upper-cased.Ú r   FTé   )Úlistr.   ÚkeysrA   r;   Úlower)r3   r   Úall_vocabularyÚfiltered_textrB   Úfound_matchÚwords          r   Únormalize_textzVitsTokenizer.normalize_texts   sÏ   € ä˜dŸl™l×/Ñ/Ó1Ó2´T¸$×:SÑ:S×:XÑ:XÓ:ZÓ5[Ñ[ˆØˆàˆØ”#�lÓ#Ò#ØˆKØ&ò �Ø  A¬¨D«	¡MÐ2°dÓ:Ø! TÑ)�MØœ˜T›‘N�AØ"&�KÙðñ Ø ¨a¡×!6Ñ!6Ó!8Ñ8�Ø�Q‘�ð ”#�lÓ#Ó#ð Ðr   c                 óH   — | j                   dk(  r|j                  dd«      }|S )z4Special treatment of characters in certain languagesÚronu   È›u   Å£)r%   Úreplace)r3   Útexts     r   Ú_preprocess_charzVitsTokenizer._preprocess_charˆ   s#   € à�=‰=˜EÒ!Ø—<‘<  dÓ+ˆDØˆr   rS   Úis_split_into_wordsr'   c                 óH  ‡ — |�|n‰ j                   }|r‰ j                  |«      }‰ j                  |«      }t        |«      rQ‰ j                  rEt        «       st        j                  d«       n%t        j                  «       }|j                  |«      }‰ j                  rKt        «       st        d«      ‚t        j                  |ddddd¬«      }t        j                   dd|«      }||fS |r5d	j#                  t%        t'        ˆ fd
„|«      «      «      j)                  «       }||fS )a  
        Performs any necessary transformations before tokenization.

        This method should pop the arguments from kwargs and return the remaining `kwargs` as well. We test the
        `kwargs` at the end of the encoding process to be sure all the arguments have been used.

        Args:
            text (`str`):
                The text to prepare.
            is_split_into_words (`bool`, *optional*, defaults to `False`):
                Whether or not the input is already pre-tokenized (e.g., split into words). If set to `True`, the
                tokenizer assumes the input is already split into words (for instance, by splitting it on whitespace)
                which it will tokenize.
            normalize (`bool`, *optional*, defaults to `None`):
                Whether or not to apply punctuation and casing normalization to the text inputs. Typically, VITS is
                trained on lower-cased and un-punctuated text. Hence, normalization is used to ensure that the input
                text consists only of lower-case characters.
            kwargs (`Dict[str, Any]`, *optional*):
                Keyword arguments to use for the tokenization.

        Returns:
            `Tuple[str, Dict[str, Any]]`: The prepared text and the unused kwargs.
        aC  Text to the tokenizer contains non-Roman characters. To apply the `uroman` pre-processing step automatically, ensure the `uroman` Romanizer is installed with: `pip install uroman` Note `uroman` requires python version >= 3.10Otherwise, apply the Romanizer manually as per the instructions: https://github.com/isi-nlp/uromanzEPlease install the `phonemizer` Python package to use this tokenizer.zen-usÚespeakT)r%   ÚbackendÚstripÚpreserve_punctuationÚwith_stressz\s+ú rF   c                 ó    •— | ‰j                   v S r:   )r.   )Úcharr3   s    €r   ú<lambda>z8VitsTokenizer.prepare_for_tokenization.<locals>.<lambda>Ë   s   ø€ ¸TÀTÇ\Á\Ð=Q€ r   )r'   rO   rT   r   r)   r   ÚloggerÚwarningÚurÚUromanÚromanize_stringr(   r   ÚImportErrorÚ
phonemizerr   ÚsubÚjoinrH   ÚfilterrY   )r3   rS   rU   r'   r4   rL   Úuromans   `      r   Úprepare_for_tokenizationz&VitsTokenizer.prepare_for_tokenizationŽ   s  ø€ ð4 "+Ð!6‘I¸D¿N¹Nˆ	áà×&Ñ& tÓ,ˆDà×-Ñ-¨dÓ3ˆä# MÔ2°t·~²~Ü&Ô(Ü—‘ðyõô Ÿ™›�Ø &× 6Ñ 6°}Ó E�à�>Š>Ü*Ô,Ü!Ð"iÓjÐjä&×0Ñ0ØØ Ø ØØ%)Ø ôˆMô ŸF™F 6¨3°Ó>ˆMð
 ˜fÐ$Ð$ñ	 àŸG™G¤D¬Ó0QÐS`Ó)aÓ$bÓc×iÑiÓkˆMà˜fÐ$Ð$r   c                 ó�   — t        |«      }| j                  r.| j                  d«      gt        |«      dz  dz   z  }||ddd…<   |}|S )z]Tokenize a string by inserting the `<pad>` token at the boundary between adjacent characters.r   é   rG   N)rH   r&   Ú_convert_id_to_tokenr;   )r3   rS   ÚtokensÚintersperseds       r   Ú	_tokenizezVitsTokenizer._tokenizeÏ   sQ   € ä�d“ˆà�>Š>Ø ×5Ñ5°aÓ8Ð9¼SÀ»[È1¹_ÈqÑ=PÑQˆLØ!'ˆL˜˜˜A˜ÑØ!ˆFàˆr   ro   c                 óh   — | j                   rt        |«      dkD  r|dd d…   }dj                  |«      S )NrG   rm   rF   )r&   r;   rh   )r3   ro   s     r   Úconvert_tokens_to_stringz&VitsTokenizer.convert_tokens_to_stringÚ   s0   € Ø�>Š>œc &›k¨AšoØ˜A˜D˜q˜D‘\ˆFØ�w‰w�v‹Ðr   c                 ó€   — | j                   j                  || j                   j                  | j                  «      «      S )z0Converts a token (str) in an id using the vocab.)r.   Úgetr$   )r3   Útokens     r   Ú_convert_token_to_idz"VitsTokenizer._convert_token_to_idß   s,   € à�|‰|×Ñ  t§|¡|×'7Ñ'7¸¿¹Ó'GÓHÐHr   c                 ó8   — | j                   j                  |«      S )z=Converts an index (integer) in a token (str) using the vocab.)r0   ru   )r3   Úindexs     r   rn   z"VitsTokenizer._convert_id_to_tokenã   s   € à�|‰|×Ñ Ó&Ð&r   Úsave_directoryÚfilename_prefixc           	      ó�  — t         j                  j                  |«      st        j	                  d|› d�«       y t         j                  j                  ||r|dz   ndt        d   z   «      }t        |dd¬«      5 }|j                  t        j                  | j                  d	d
d¬«      dz   «       d d d «       |fS # 1 sw Y   |fS xY w)NzVocabulary path (z) should be a directoryú-rF   r   Úwr    r!   rm   TF)ÚindentÚ	sort_keysÚensure_asciiú
)ÚosÚpathÚisdirr`   Úerrorrh   ÚVOCAB_FILES_NAMESr+   Úwriter,   Údumpsr.   )r3   rz   r{   r   Úfs        r   Úsave_vocabularyzVitsTokenizer.save_vocabularyç   s¶   € Ü�w‰w�}‰}˜^Ô,Ü�L‰LÐ,¨^Ð,<Ð<SÐTÔUØä—W‘W—\‘\Ø±o˜_¨sÒ2È2ÔQbÐcoÑQpÑpó
ˆ
ô �*˜c¨GÔ4ð 	c¸Ø�G‰G”D—J‘J˜tŸ|™|°AÀÐTYÔZÐ]aÑaÔb÷	cð ˆ}Ð÷	cð ˆ}Ðús   Á96B:Â:C)z<pad>z<unk>NTTTF)r   N)FNr:   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r‡   Úvocab_files_namesÚmodel_input_namesr2   Úpropertyr<   rD   rO   rT   ÚstrÚboolr   r   r   r   rk   r   rq   rs   rw   rn   r   r‹   Ú__classcell__)r8   s   @r   r   r   /   s  ø„ ñð* *ÐØ$Ð&6Ð7Ðð
 ØØØØØØð 
ð 
õ 
ðD ñ!ó ð!òò
ò*ð Y]ñ?%Øð?%Ø.2ð?%ØGOÐPTÁ~ð?%à	ˆs�D˜˜c˜‘NÐ"Ñ	#ó?%ðB	˜cð 	 d¨3¡ió 	ð¨t°C©yð ¸Só ò
Iò'ñ¨cð ÀHÈSÁMð Ð]bÐchÐilÑcmÐosÐcsÑ]t÷ r   r   )r�   r,   rƒ   r   Útypingr   r   r   r   r   r   Útokenization_utilsr
   Úutilsr   r   r   rf   rj   rb   Ú
get_loggerrŒ   r`   r‡   r   r   Ú__all__r*   r   r   ú<module>r›      sr   ðñ #ã Û 	Û 	ß :× :å 5ß JÑ Jñ ÔÛáÔÛà	ˆ×	Ñ	˜HÓ	%€à! <Ð0Ð òôDÐ'ô DðN Ð
�r   