ó
    ˆŽ¡j‚*  ã                   ó  • S SK r S SKJr  SSKJrJr  SSKJr  SSKJ	r	  SSK
JrJrJr  SSKJrJrJr  \" 5       (       a  S SKrS SKJs  Jr  \" 5       (       a  S SKr\R0                  " \5      r\" S	S
9 " S S\5      5       rS/rg)é    N)ÚAnyé   )Ú
AudioInputÚmake_list_of_audio)ÚSequenceFeatureExtractor)ÚBatchFeature)ÚPaddingStrategyÚ
TensorTypeÚlogging)Úis_torch_availableÚis_torchaudio_availableÚrequires)Ú
torchaudio)Úbackendsc                   ó¶   ^ • \ rS rSrSr/ SQr    SU 4S jjr      SS\S\\	-  \
-  S\S-  S	\S
\	\-  S-  S\S-  S\	S\4S jjrS\\	\4   4S jrSrU =r$ )ÚXcodec2FeatureExtractoré$   a¼  
Constructs a Xcodec2 feature extractor, which computes mel-filter bank features for the semantic encoder and padded
audio for the acoustic encoder.

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

Args:
    feature_size (`int`, *optional*, defaults to 80):
        The feature dimension of the extracted features.
    sampling_rate (`int`, *optional*, defaults to 16000):
        The sample rate at which the audio files should be digitalized expressed in hertz (Hz).
    padding_value (`float`, *optional*, defaults to 1.0):
        The value that is used to fill the padding vectors for the mel spectrogram.
    hop_length (`int`, *optional*, defaults to 320):
        Number of audio samples encoded per frame. Equivalent to product of downsampling ratios.
        Needed for acoustic encoder input padding.
)Úinput_featuresÚinput_valuesÚpadding_maskÚinput_features_maskc                 ó¶   >• [         TU ]  " S
XUS.UD6  X@l        [        SUSS9U l        SS/U R                  l        SU l        SU l        SU l        S	U l	        g )N)Úfeature_sizeÚsampling_rateÚpadding_valueé   ç        Úaudior   é   éP   i�  é    © )
ÚsuperÚ__init__Ú
hop_lengthr   Úacoustic_encoder_padderÚmodel_input_namesÚstrideÚnum_mel_binsÚframe_lengthÚframe_shift)Úselfr   r   r   r%   ÚkwargsÚ	__class__s         €ÚÄC:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\transformers/models/xcodec2/feature_extraction_xcodec2.pyr$   Ú Xcodec2FeatureExtractor.__init__;   sr   ø€ ô 	‰ÒÐw lÐ_lÑwÐpvÒwð %ŒÜ'?ØØ'Øñ(
ˆÔ$ð
 ;BÀ>Ð9Rˆ×$Ñ$Ô6ð ˆŒØˆÔØˆÔØˆÕó    Nr   ÚpaddingÚ
max_lengthÚ
truncationÚreturn_tensorsr   ÚdeviceÚreturnc                 ó&  • Ub<  X`R                   :w  a,  [        SU  SU R                    SU R                    SU S3	5      eO-[        R                  SU R                  R
                   S35        [        U5      nU H+  n	U	R                  S	:”  d  M  [        S
U	R                   35      e   [        U5      n
U Vs/ s H-  n[        R                  " [        R                  " U5      SSS9PM/     nnU R                  R                  [        SU05      UUUUU R                   SS9nUR#                  S5      nUS   SS2SSS24   n/ n[%        U
5       GH­  nUb*  ['        UU   R)                  5       R+                  5       5      OUR                  S   nUU R                   -   S-
  U R                   -  U R                   -  n[-        UUR                  S   5      nUUSS2SU24   n[        R                  " UU R                   S	-  U R                   S	-  4SS9nUR/                  U5      n[0        R2                  R4                  R7                  US-  U R8                  U R:                  U R                   -  S-  U R<                  U R                   -  S-  U R                   SSSSSSSSU R                   S	-  S9nUUR?                  S5      -
  [        R@                  " URC                  SSS9S-   5      -  nURE                  U5        GM°     [        SU05      nU R                  UUUUU RF                  USS 9nUS   nURI                  S5      nUR                  S   UR                  S   U RF                  -  -
  nUSS2SU2SS24   RK                  U
UU RF                  -  U R8                  U RF                  -  5      nUbJ  USS2SU24   RK                  U
UU RF                  -  U RF                  5      R-                  SS!9RL                  n[        UUUUS".US#9$ s  snf )$aÌ  
Args:
    audio (`np.ndarray`, `torch.Tensor`, `list[np.ndarray]`, `list[torch.Tensor]`):
        Numpy array or torch tensor with shape (num_channels, sequence_length). A list of such arrays or
        tensors can also be provided for a batch of inputs.
    padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `True`):
        Select a strategy to pad the returned sequences (according to the model's padding side and padding
        index) among:

        - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
          sequence if provided).
        - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
          acceptable input length for the model if that argument is not provided.
        - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
          lengths).
    max_length (`int`, *optional*):
        Maximum length of the returned list and optionally padding length (see above).
    truncation (`bool`):
        Activates truncation to cut input sequences longer than *max_length* to *max_length*.
    return_tensors (`str` or [`~utils.TensorType`], *optional*):
        If set, will return tensors instead of list of python integers. Acceptable values are:

        - `'tf'`: Return TensorFlow `tf.constant` objects.
        - `'pt'`: Return PyTorch `torch.Tensor` objects.
        - `'np'`: Return Numpy `np.ndarray` objects.
    sampling_rate (`int`, *optional*):
        The sample rate at which the `audio` input was sampled. It is strongly recommended to pass
        `sampling_rate` at the forward call to prevent silent errors.
    device (`str`, *optional*, defaults to `"cpu"`):
        Device for PyTorch tensors during mel-filter bank feature extraction.
    kwargs (*optional*):
        Remaining dictionary of keyword arguments that will be passed to the tokenizer or the feature
        extractor.
Nz3The model corresponding to this feature extractor: z& was trained using a sampling rate of zD. Please make sure that the provided `audio` input was sampled with z	 and not Ú.zDIt is strongly recommended to pass the `sampling_rate` argument to `zN()`. Failing to do so can result in silent errors that might be hard to debug.r   z6Expected input shape (channels, length) but got shape )r   r   r   )Úvaluer   Úpt)r3   r4   r2   Úreturn_attention_maskÚpad_to_multiple_ofr5   Úattention_maskéÿÿÿÿr   i €  iè  Úpoveyg
×£p=
ï?TFé   )r)   r*   r+   Úsample_frequencyÚwindow_typeÚpreemphasis_coefficientÚremove_dc_offsetÚuse_log_fbankÚ
use_energyÚditherÚ
snip_edgesÚlow_freqÚ	high_freqr   )ÚunbiasedgH¯¼šò×z>r   )r2   r3   r4   r=   r<   r5   )Údim)r   r   r   r   )Útensor_type)'r   Ú
ValueErrorÚloggerÚwarningr.   Ú__name__r   ÚndimÚshapeÚlenÚFÚpadÚtorchÚ	as_tensorr&   r   r%   ÚpopÚrangeÚintÚsumÚitemÚminÚtor   Ú
complianceÚkaldiÚfbankr)   r*   r+   ÚmeanÚsqrtÚvarÚappendr(   ÚgetÚreshapeÚvalues)r,   r   r2   r3   r4   r5   r   r6   r-   ÚexampleÚ
batch_sizeÚaÚpadded_inputsr   Úpadded_audioÚmel_featuresÚiÚorig_lenÚper_sample_lenÚ	valid_lenÚwaveformÚfeaturesÚencoded_inputsÚ
padded_melÚaudio_spectrogramÚspectrogram_maskÚtrimmed_framess                              r/   Ú__call__Ú Xcodec2FeatureExtractor.__call__U   sZ  € ðZ Ñ$Ø× 2Ñ 2Ó2Ü ØIÈ$Èð PØ×*Ñ*Ð+ð ,Ø×*Ñ*Ð+¨9°]°OÀ1ðFóð ð 3ô �N‰NØVÐW[×WeÑWe×WnÑWnÐVoð p\ð \ôô
 # 5Ó)ˆÛˆGØ�|‰|˜aÕÜ Ð#YÐZa×ZgÑZgÐYhÐ!iÓjÐjñ ô ˜“Zˆ
ñ HMÓMÂuÀ!”—’”u—’ qÓ)¨6¸Ô=ÁuˆÐMØ×4Ñ4×8Ñ8Ü˜' 5Ð)Ó*Ø!Ø!ØØ")Ø#Ÿ™Øð 9ð 
ˆð %×(Ñ(Ð)9Ó:ˆØ$ WÑ-ªa°²q¨jÑ9ˆð
 ˆÜ�z×"ˆAØ<HÑ<T”s˜<¨™?×.Ñ.Ó0×5Ñ5Ó7Ô8ÐZf×ZlÑZlÐmoÑZpˆHØ'¨$¯/©/Ñ9¸AÑ=À$Ç/Á/ÑQÐUY×UdÑUdÑdˆNÜ˜N¨L×,>Ñ,>¸rÑ,BÓCˆIØ# A¢q¨*¨9¨*Ð$4Ñ5ˆHÜ—u’u˜X¨¯©¸1Ñ(<¸d¿o¹oÐQRÑ>RÐ'SÐ[^Ñ_ˆHØ—{‘{ 6Ó*ˆHÜ!×,Ñ,×2Ñ2×8Ñ8Ø˜EÑ"Ø!×.Ñ.Ø!×.Ñ.°×1CÑ1CÑCÀdÑJØ ×,Ñ,¨t×/AÑ/AÑAÀDÑHØ!%×!3Ñ!3Ø#Ø(,Ø!%Ø"Ø ØØØØ×,Ñ,°Ñ1ð 9ð ˆHð  ! 8§=¡=°Ó#3Ñ3´u·z²zÀ(Ç,Á,ÈqÐ[_À,ÐB`ÐcgÑBgÓ7hÑhˆHØ×Ñ ×)ñ1 #ô2 &Ð'7¸Ð&FÓGˆØ—X‘XØØØ!Ø!Ø#Ÿ{™{Ø")Øð ð 
ˆ
ð 'Ð'7Ñ8ÐØ%Ÿ>™>Ð*:Ó;ÐØ*×0Ñ0°Ñ3Ð7H×7NÑ7NÈqÑ7QÐTX×T_ÑT_Ñ7_Ñ`ˆØ-ªa°°.°Â!Ð.CÑD×LÑLØ˜¨$¯+©+Ñ5°t×7HÑ7HÈ4Ï;É;Ñ7Vó
Ðð Ñ'à ¢ O ^ OÐ!3Ñ4ß‘˜ ^°t·{±{Ñ%BÀDÇKÁKÓPß‘˜��ß‘ð	 ô à ,Ø ,Ø"3Ø'7ñ	ð 'ñ
ð 	
ùòE Ns   Â84Pc                 óœ   • [         R                  " U R                  5      nU R                  R                  US'   UR                  SS 5        U$ )NÚfeature_extractor_typer&   )ÚcopyÚdeepcopyÚ__dict__r.   rR   rZ   )r,   Úoutputs     r/   Úto_dictÚXcodec2FeatureExtractor.to_dictâ   s=   € Ü—’˜tŸ}™}Ó-ˆØ+/¯>©>×+BÑ+BˆÐ'Ñ(Ø�
‰
Ð,¨dÔ3Øˆr1   )r&   r*   r+   r%   r)   r(   )r    i€>  g      ð?i@  )TNFNNÚcpu)rR   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r'   r$   r   ÚboolÚstrr	   r\   r
   r   r|   Údictr   r„   Ú__static_attributes__Ú__classcell__)r.   s   @r/   r   r   $   sÉ   ø† ñò& bÐð ØØØ÷ð: 15Ø!%Ø Ø26Ø$(ØñK
àðK
ð ˜‘˜oÑ-ðK
ð ˜$‘Jð	K
ð
 ðK
ð ˜jÑ(¨4Ñ/ðK
ð ˜T‘zðK
ð ðK
ð 
õK
ðZ˜˜c 3˜h™÷ ò r1   r   )r€   Útypingr   Úaudio_utilsr   r   Ú!feature_extraction_sequence_utilsr   Úfeature_extraction_utilsr   Úutilsr	   r
   r   Úutils.import_utilsr   r   r   rX   Útorch.nn.functionalÚnnÚ
functionalrV   r   Ú
get_loggerrR   rP   r   Ú__all__r"   r1   r/   Ú<module>r›      sƒ   ðó Ý ç 9Ý IÝ 4ß 9Ñ 9ß WÑ Wñ ×ÑÛß#Ð#á×ÑÛð 
×	Ò	˜HÓ	%€ñ 
�?Ñ#ôAÐ6ó Aó $ðAðH %Ð
%�r1   