
    Nj
                         d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlmZ  e j                  e
      Z G d d      ZdZdZd	efd
Z G d de      Zy)    N)nn)BaseConditionerTokenizedText)download_if_necessaryc                   4    e Zd ZdZdededdfdZdedefdZy)	SentencePieceTokenizera  This tokenizer should be used for natural language descriptions.
    For example:
    ["he didn't, know he's going home.", 'shorter sentence'] =>
    [[78, 62, 31,  4, 78, 25, 19, 34],
    [59, 77, PAD, PAD, PAD, PAD, PAD, PAD]]

    Args:
        n_bins (int): should be equal to the number of elements in the sentencepiece tokenizer.
        tokenizer_path (str): path to the sentencepiece tokenizer model.

    nbinstokenizer_pathreturnNc                    t         j                  d|       t        |      }t        j                  t        |            | _        || j                  j                         k(  s&J d| j                  j                          d| d       y )Nz'Loading sentencepiece tokenizer from %sz'sentencepiece tokenizer has vocab size=z but nbins=z was specified)loggerinfor   sentencepieceSentencePieceProcessorstrsp
vocab_size)selfr	   r
   s      m/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/pocket_tts/conditioners/text.py__init__zSentencePieceTokenizer.__init__   sw    =~N.~>66s>7JK**,, 	
5dgg6H6H6J5K;W\V]]kl	
,    textc                     t        t        j                  | j                  j	                  |t
                    d d d f         S )N)out_type)r   torchtensorr   encodeint)r   r   s     r   __call__zSentencePieceTokenizer.__call__"   s1    U\\$''...*LMdTUgVWWr   )	__name__
__module____qualname____doc__r   r   r   r   r    r   r   r   r      s7    

c 
3 
4 
XS X] Xr   r   i  zehf://kyutai/pocket-tts-without-voice-cloning/tokenizer.model@d4fdd22ae8c8e1cb3634e150ebeff1dab2d16df3r   c                  *    t        t        t              S )zReturn a SentencePieceTokenizer with the default model path and vocab size.

    Downloads the tokenizer model from HuggingFace on first use.
    )r   DEFAULT_TOKENIZER_N_BINSDEFAULT_TOKENIZER_PATHr$   r   r   get_default_tokenizerr(   -   s    
 "":<RSSr   c                   h     e Zd ZdZdedededef fdZdedefd	Zd
ede	j                  fdZ xZS )LUTConditioneraS  Lookup table TextConditioner.

    Args:
        n_bins (int): Number of bins.
        dim (int): Hidden dim of the model (text-encoder/LUT).
        output_dim (int): Output dim of the conditioner.
        tokenizer (str): Name of the tokenizer.
        possible_values (list[str] or None): list of possible values for the tokenizer.
    n_binsr
   dim
output_dimc                     t         |   ||       t        ||      | _        t	        j
                  |dz   | j                        | _        y )N)r,   r-      )superr   r   	tokenizerr   	Embeddingr,   embed)r   r+   r
   r,   r-   	__class__s        r   r   zLUTConditioner.__init__@   s=    SZ8/G\\&1*dhh7
r   xr   c                     | j                  |      }|d   j                  | j                  j                  j                        }t        |      S Nr   )r1   tor3   weightdevicer   )r   r5   tokenss      r   preparezLUTConditioner.prepareE   s=    "djj//667V$$r   inputsc                 .    | j                  |d         }|S r7   )r3   )r   r=   embedss      r   _get_conditionzLUTConditioner._get_conditionJ   s    F1I&r   )r    r!   r"   r#   r   r   r   r   r<   r   Tensorr@   __classcell__)r4   s   @r   r*   r*   5   sS    8s 8C 8c 8s 8
% % %
] u|| r   r*   )loggingr   r   r   pocket_tts.conditioners.baser   r   pocket_tts.utils.utilsr   	getLoggerr    r   r   r&   r'   r(   r*   r$   r   r   <module>rG      sb        G 8			8	$X X2   ? T5 T_ r   