§
    9²¸j63  ã                   óð   — d dl ZddlmZ ddlmZ ddlmZmZm	Z	m
Z
 ddlmZ  e	¦   «         rd dlZ e¦   «         rd dlZdZdZ e
j        e¦  «        Z ed	¬
¦  «         G d„ de¦  «        ¦   «         ZdgZdS )é    Né   )ÚSequenceFeatureExtractor)ÚBatchFeature)Ú
TensorTypeÚis_librosa_availableÚis_torch_availableÚlogging)Úrequiresgñhãˆµøä>g      p>)ÚtorchÚlibrosa)Úbackendsc                   ó"  ‡ — e Zd ZdZddgZ	 	 	 	 	 	 	 dˆ fd„	Zdd„Z	 	 	 	 	 	 	 	 	 	 d dej        e	e
         z  e	ej                 z  e	e	e
                  z  dededz  deez  dz  dedz  dedz  dedz  dedz  dedz  dedz  dedz  defd„Zˆ xZS )!ÚParakeetFeatureExtractora–  
    Constructs a Parakeet feature extractor.

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

    This class extracts mel-filter bank features from raw speech using a custom numpy implementation of the `Short Time
    Fourier Transform` which should match pytorch's `torch.stft` equivalent.

    Args:
        feature_size (`int`, *optional*, defaults to 80):
            The feature dimension of the extracted features.
        sampling_rate (`int`, *optional*, defaults to 16000):
            The sampling rate at which the audio files should be digitalized expressed in hertz (Hz).
        hop_length (`int`, *optional*, defaults to 160):
            Length of the overlapping windows for the STFT used to obtain the Mel Frequency coefficients.
        n_fft (`int`, *optional*, defaults to 512):
            Size of the Fourier transform.
        win_length (`int`, *optional*, defaults to 400):
            The window length for the STFT computation.
        preemphasis (`float`, *optional*, defaults to 0.97):
            A preemphasis filter coefficient. 0.0 means no preemphasis filter.
        padding_value (`float`, *optional*, defaults to 0.0):
            Padding value used to pad the audio. Should correspond to silences.
    Úinput_featuresÚattention_maskéP   é€>  é    é   é�  ç
×£p=
ï?ç        c                 ó6  •—  t          ¦   «         j        d|||dœ|¤Ž || _        || _        || _        || _        t          j                             |||d|dz  d¬¦  «        }	t          j
        |	¦  «                             t          j        ¦  «        | _        d S )N)Úfeature_sizeÚsampling_rateÚpadding_valuer   é   Úslaney)ÚsrÚn_fftÚn_melsÚfminÚfmaxÚnorm© )ÚsuperÚ__init__Ú
hop_lengthr    Ú
win_lengthÚpreemphasisr   ÚfiltersÚmelr   Ú
from_numpyÚtoÚfloat32Úmel_filters)Úselfr   r   r(   r    r)   r*   r   Úkwargsr0   Ú	__class__s             €úˆ/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/transformers/models/parakeet/feature_extraction_parakeet.pyr'   z!ParakeetFeatureExtractor.__init__C   s§   ø€ ð 	�‰ŒÔÐw lÀ-Ð_lÐwÐwÐpvÐwÐwÐwà$ˆŒØˆŒ
Ø$ˆŒØ&ˆÔõ ”o×)Ò)Ø E°,ÀSÈ}Ð_`ÑO`Ðgoð *ñ 
ô 
ˆõ !Ô+¨KÑ8Ô8×;Ò;½E¼MÑJÔJˆÔÐÐó    Úcpuc           	      óü  — t          j        | j        d|¬¦  «        }t          j        || j        | j        | j        |dd¬¦  «        }t          j        |¦  «        }t          j        |                     d¦  «         	                    d¦  «        ¦  «        }|                     d¦  «        }| j
                             |¦  «        }||z  }t          j        |t          z   ¦  «        }|                     ddd	¦  «        }|S )
NF)ÚperiodicÚdeviceTÚconstant)r(   r)   ÚwindowÚreturn_complexÚpad_moder   éÿÿÿÿr   é   )r   Úhann_windowr)   Ústftr    r(   Úview_as_realÚsqrtÚpowÚsumr0   r.   ÚlogÚLOG_ZERO_GUARD_VALUEÚpermute)r1   Úwaveformr9   r;   rA   Ú
magnitudesr0   Úmel_specs           r4   Ú_torch_extract_fbank_featuresz6ParakeetFeatureExtractor._torch_extract_fbank_featurese   sí   € åÔ" 4¤?¸UÈ6ÐRÑRÔRˆÝŒzØØŒJØ”Ø”ØØØð
ñ 
ô 
ˆõ Ô'¨Ñ-Ô-ˆ
Ý”Z 
§¢¨qÑ 1Ô 1× 5Ò 5°bÑ 9Ô 9Ñ:Ô:ˆ
Ø—^’^ AÑ&Ô&ˆ
ð Ô&×)Ò)¨&Ñ1Ô1ˆØ Ñ+ˆÝ”9˜XÕ(<Ñ<Ñ=Ô=ˆð ×#Ò# A q¨!Ñ,Ô,ˆàˆr5   FNÚlongestÚ
raw_speechÚ
truncationÚpad_to_multiple_ofÚreturn_tensorsÚreturn_attention_maskÚpaddingÚ
max_lengthr   Údo_normalizer9   Úreturn_token_timestampsÚreturnc                 ó	  — |�<|| j         k    r0t          d| j        j        › d| j         › d| j         › d|› d�	¦  «        ‚n(t                               d| j        j        › d�¦  «         t          |t          j        ¦  «        rt          j
        |¦  «        }nHt          |t          t          f¦  «        r,t          |d	         t          j        ¦  «        rd
„ |D ¦   «         }t          |t          j        ¦  «        ot          |j        ¦  «        dk    }|rUt          |j        ¦  «        dk    r=t                               d| j        j        › d�¦  «         |                     d¦  «        }t          |t          t          f¦  «        }|rZ|D ]W}t          |j        ¦  «        dk    r=t                               d| j        j        › d�¦  «         |                     d¦  «        }ŒX|s|rd„ |D ¦   «         }n*|dd…df                              t          j        ¦  «        g}d„ |D ¦   «         }t'          ||dœ¦  «        }|                      |||||d¬¦  «        }|j                             d¦  «        }| j        �³t          j        |j        d         |j        ¬¦  «                             d	¦  «        |j                             d¦  «        k     }t          j        |dd…dd…f         |dd…dd…f         | j        |dd…dd…f         z  z
  gd¬¦  «        }|                     | d¦  «        }|                      ||
¦  «        }t          j        |j        | j         dz  dz  z   | j         z
  | j!        ¦  «        }t          j        |j        d         |
¬¦  «        ddd…f         |dd…df         k     }|                     d¦  «        }||z  }| "                    d¬¦  «        |                     d¦  «        z  }|                     d¦  «        }||z
  dz  |z   "                    d¬¦  «        |dz
                       d¦  «        z  }t          j#        |¦  «                             d¦  «        }||z
  |tH          z   z  }||z  }t'          ||dœ|¬¦  «        S )aö  
        Main method to featurize and prepare for the model one or several sequence(s). Implementation uses PyTorch for
        the STFT computation if available, otherwise a slower NumPy based one.

        Args:
            raw_speech (`np.ndarray`, `list[float]`, `list[np.ndarray]`, `list[list[float]]`):
                The sequence or batch of sequences to be padded. Each sequence can be a numpy array, a list of float
                values, a list of numpy arrays or a list of list of float values. Must be mono channel audio, not
                stereo, i.e. single float per timestep.
            truncation (`bool`, *optional*, default to `True`):
                Activates truncation to cut input sequences longer than *max_length* to *max_length*.
            pad_to_multiple_of (`int`, *optional*, defaults to None):
                If set will pad the sequence to a multiple of the provided value.

                This is especially useful to enable the use of Tensor Cores on NVIDIA hardware with compute capability
                `>= 7.5` (Volta), or on TPUs which benefit from having sequence lengths be a multiple of 128.
            return_attention_mask (`bool`, *optional*):
                Whether to return the attention mask. If left to the default, will return the attention mask according
                to the specific feature_extractor's default.

                [What are attention masks?](../glossary#attention-mask)

                <Tip>

                For Parakeet models, `attention_mask` should always be passed for batched inference, to avoid subtle
                bugs.

                </Tip>

            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 sampling rate at which the `raw_speech` input was sampled. It is strongly recommended to pass
                `sampling_rate` at the forward call to prevent silent errors and allow automatic speech recognition
                pipeline.
            padding_value (`float`, *optional*, defaults to 0.0):
                The value that is used to fill the padding values / vectors.
            do_normalize (`bool`, *optional*, defaults to `False`):
                Whether or not to zero-mean unit-variance normalize the input. Normalizing can help to significantly
                improve the performance of the model.
            device (`str`, *optional*, defaults to `'cpu'`):
                Specifies the device for computation of the log-mel spectrogram of audio signals in the
                `_torch_extract_fbank_features` method. (e.g., "cpu", "cuda")
            return_token_timestamps (`bool`, *optional*, defaults to `None`):
                Deprecated. Use `return_attention_mask` instead from which the number of frames can be inferred.

                Whether or not to return the number of frames of the input raw_speech.
                These num_frames can be used by the model to compute word level timestamps.
        Nz3The model corresponding to this feature extractor: z& was trained using a sampling rate of zI. Please make sure that the provided `raw_speech` 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   c                 ó6   — g | ]}t          j        |¦  «        ‘ŒS r%   )r   Útensor©Ú.0Úspeechs     r4   ú
<listcomp>z5ParakeetFeatureExtractor.__call__.<locals>.<listcomp>Ö   s"   € ÐHÐHÐH°6�%œ, vÑ.Ô.ÐHÐHÐHr5   r?   r   z2Only mono-channel audio is supported for input to z;. We will take the mean of the channels to convert to mono.r>   c                 ó`   — g | ]+}|d d …d f                               t          j        ¦  «        ‘Œ,S )N)r.   r   r/   r\   s     r4   r_   z5ParakeetFeatureExtractor.__call__.<locals>.<listcomp>ë   s4   € ÐUÐUÐUÀ˜&    D œ/×,Ò,­U¬]Ñ;Ô;ÐUÐUÐUr5   c                 ó,   — g | ]}t          |¦  «        ‘ŒS r%   )Úlenr\   s     r4   r_   z5ParakeetFeatureExtractor.__call__.<locals>.<listcomp>ï   s   € Ð>Ð>Ð>¨�˜V™œÐ>Ð>Ð>r5   )r   Úaudio_lengthsÚpt)rS   rT   rO   rP   rQ   )r9   )Údimr   )r   r   )ÚdataÚtensor_type)%r   Ú
ValueErrorr3   Ú__name__ÚloggerÚwarningÚ
isinstanceÚnpÚndarrayr   r[   ÚlistÚtupleÚTensorrb   ÚshapeÚmeanr.   r/   r   Úpadr   Úsqueezer*   Úaranger9   Ú	unsqueezerc   ÚcatÚmasked_fillrL   Úfloor_divider    r(   rE   rC   ÚEPSILON)r1   rN   rO   rP   rQ   rR   rS   rT   r   rU   r9   rV   r2   Úis_batched_torchÚis_batched_sequencer^   rc   Úbatched_speechÚpadded_inputsr   ÚtimemaskÚfeatures_lengthsr   ÚmaskÚinput_features_maskedrs   ÚvarianceÚstds                               r4   Ú__call__z!ParakeetFeatureExtractor.__call__�   s\  € ðH Ð$Ø Ô 2Ò2Ð2Ý ðWÈ$Ì.ÔJað Wð WØ)-Ô);ðWð Wà)-Ô);ðWð WàFSðWð Wð Wñô ð ð 3õ �NŠNð\ÐW[ÔWeÔWnð \ð \ð \ñô ð õ �j¥"¤*Ñ-Ô-ð 	IÝœ jÑ1Ô1ˆJˆJÝ˜
¥T­5 MÑ2Ô2ð 	IµzÀ*ÈQÄ-ÕQSÔQ[Ñ7\Ô7\ð 	IØHÐH¸ZÐHÑHÔHˆJå% jµ%´,Ñ?Ô?Ð]ÅCÈ
ÔHXÑDYÔDYÐ\]ÒD]ÐØð 	-¥ JÔ$4Ñ 5Ô 5¸Ò 9Ð 9Ý�NŠNðLÀTÄ^ÔE\ð Lð Lð Lñô ð ð $Ÿš¨Ñ,Ô,ˆJå(¨µd½E°]ÑCÔCÐØð 	-Ø$ð -ð -�Ý�v”|Ñ$Ô$ qÒ(Ð(Ý—N’NðTÈTÌ^ÔMdð Tð Tð Tñô ð ð $Ÿ[š[¨™_œ_�Føàð 	AÐ2ð 	AØUÐUÈ*ÐUÑUÔUˆJˆJà$ Q Q Q¨ WÔ-×0Ò0µ´Ñ?Ô?Ð@ˆJà>Ð>°:Ð>Ñ>Ô>ˆÝ%¸ÐVcÐ&dÐ&dÑeÔeˆàŸšØØØ!Ø!Ø1Øð !ñ 
ô 
ˆð 'Ô5×=Ò=¸bÑAÔAˆð ÔÐ'Ý”| NÔ$8¸Ô$;ÀNÔDYÐZÑZÔZ×dÒdØñô àÔ+×5Ò5°aÑ8Ô8ò9ˆHõ #œYØ    2 A 2 Ô&¨°q°q°q¸!¸"¸"°uÔ(=ÀÔ@PÐSaÐbcÐbcÐbcÐehÐfhÐehÐbhÔSiÑ@iÑ(iÐjÐpqðñ ô ˆNð ,×7Ò7¸¸	À3ÑGÔGˆNà×;Ò;¸NÈFÑSÔSˆÝ Ô-ØÔ'¨$¬*¸©/¸AÑ*=Ñ=ÀÄ
ÑJÈDÌOñ
ô 
Ðõ œ nÔ&:¸1Ô&=ÀfÐMÑMÔMÈdÐTUÐTUÐTUÈgÔVÐYiÐjkÐjkÐjkÐmqÐjqÔYrÒrˆð ×'Ò'¨Ñ+Ô+ˆØ .°Ñ 5ÐØ$×(Ò(¨QÐ(Ñ/Ô/Ð2B×2LÒ2LÈRÑ2PÔ2PÑPˆØ�~Š~˜aÑ Ô ˆØ*¨TÑ1°aÑ7¸$Ñ>×CÒCÈÐCÑJÔJÐN^ÐabÑNb×MmÒMmÐnpÑMqÔMqÑqˆÝŒj˜Ñ"Ô"×,Ò,¨QÑ/Ô/ˆØ(¨4Ñ/°C½'±MÑBˆØ˜$Ñˆåà"0Ø"0ðð ð 'ð
ñ 
ô 
ð 	
r5   )r   r   r   r   r   r   r   )r6   )
FNNNrM   NNNr6   N)ri   Ú
__module__Ú__qualname__Ú__doc__Úmodel_input_namesr'   rL   rm   rn   ro   ÚfloatÚboolÚintÚstrr   r   r†   Ú__classcell__)r3   s   @r4   r   r   %   sš  ø€ € € € € ðð ð4 *Ð+;Ð<Ðð ØØØØØØð Kð  Kð  Kð  Kð  Kð  KðDð ð ð ð> !Ø)-Ø26Ø-1Ø'Ø!%Ø$(Ø$(Ø"Ø/3ð[
ð [
à”J  e¤Ñ,¨t°B´JÔ/?Ñ?À$ÀtÈEÄ{ÔBSÑSð[
ð ð[
ð   $™Jð	[
ð
 ˜jÑ(¨4Ñ/ð[
ð  $ d™{ð[
ð �t‘ð[
ð ˜$‘Jð[
ð ˜T‘zð[
ð ˜T‘kð[
ð �d‘
ð[
ð "&¨¡ð[
ð 
ð[
ð [
ð [
ð [
ð [
ð [
ð [
ð [
r5   r   )Únumpyrm   Ú!feature_extraction_sequence_utilsr   Úfeature_extraction_utilsr   Úutilsr   r   r   r	   Úutils.import_utilsr
   r   r   r{   rG   Ú
get_loggerri   rj   r   Ú__all__r%   r5   r4   ú<module>r—      s!  ðð Ð Ð Ð à IÐ IÐ IÐ IÐ IÐ IØ 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RØ *Ð *Ð *Ð *Ð *Ð *ð ÐÑÔð Ø€L€L€LàÐÑÔð Ø€N€N€Nð €ØÐ ð 
ˆÔ	˜HÑ	%Ô	%€ð 
€Ð'Ð(Ñ(Ô(ðv
ð v
ð v
ð v
ð v
Ð7ñ v
ô v
ñ )Ô(ðv
ðr &Ð
&€€€r5   