§
    9²¸jc*  ã                   ó�   — d Z ddlZddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZmZ  ej        e¦  «        Z G d„ d	e¦  «        Zd	gZdS )
z"
Feature extractor class for CLVP
é    Né   )Úmel_filter_bankÚspectrogramÚwindow_function)ÚSequenceFeatureExtractor)ÚBatchFeature)Ú
TensorTypeÚloggingc                   ó  ‡ — e Zd ZdZddgZ	 	 	 	 	 	 	 	 	 dˆ fd„	Zdej        dej        fd„Z	 	 	 	 	 	 	 ddej        e	e
         z  e	ej                 z  e	e	e
                  z  ded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fd„Zˆ xZS )ÚClvpFeatureExtractora!  
    Constructs a CLVP 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 log-mel-spectrogram 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 22050):
            The sampling rate at which the audio files should be digitalized expressed in hertz (Hz).
        default_audio_length (`int`, *optional*, defaults to 6):
            The default length of raw audio in seconds. If `max_length` is not set during `__call__` then it will
            automatically be set to default_audio_length * `self.sampling_rate`.
        hop_length (`int`, *optional*, defaults to 256):
            Length of the overlapping windows for the STFT used to obtain the Mel Frequency coefficients.
        chunk_length (`int`, *optional*, defaults to 30):
            The maximum number of chunks of `sampling_rate` samples used to trim and pad longer or shorter audio
            sequences.
        n_fft (`int`, *optional*, defaults to 1024):
            Size of the Fourier transform.
        padding_value (`float`, *optional*, defaults to 0.0):
            Padding value used to pad the audio. Should correspond to silences.
        mel_norms (`list` of length `feature_size`, *optional*):
            If `mel_norms` is provided then it will be used to normalize the log-mel spectrograms along each
            mel-filter.
        return_attention_mask (`bool`, *optional*, defaults to `False`):
            Whether to return the attention mask. If left to the default, it will return the attention mask.

            [What are attention masks?](../glossary#attention-mask)
    Úinput_featuresÚattention_maskéP   é"V  é   é   é   é   ç        NFc
           	      ó  •—  t          ¦   «         j        d	||||	dœ|
¤Ž || _        || _        || _        ||z  | _        | j        |z  | _        || _        || _        || _	        t          d|dz  z   |dd|dd¬¦  «        | _        d S )
N)Úfeature_sizeÚsampling_rateÚpadding_valueÚreturn_attention_maské   é   r   g     @¿@ÚslaneyÚhtk)Únum_frequency_binsÚnum_mel_filtersÚmin_frequencyÚmax_frequencyr   ÚnormÚ	mel_scale© )ÚsuperÚ__init__Ún_fftÚ
hop_lengthÚchunk_lengthÚ	n_samplesÚnb_max_framesr   Údefault_audio_lengthÚ	mel_normsr   Úmel_filters)Úselfr   r   r-   r)   r*   r(   r   r.   r   ÚkwargsÚ	__class__s              €ú€/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/transformers/models/clvp/feature_extraction_clvp.pyr'   zClvpFeatureExtractor.__init__D   sÅ   ø€ ð 	�‰ŒÔð 	
Ø%Ø'Ø'Ø"7ð		
ð 	
ð
 ð	
ð 	
ð 	
ð ˆŒ
Ø$ˆŒØ(ˆÔØ%¨Ñ5ˆŒØ!œ^¨zÑ9ˆÔØ*ˆÔØ$8ˆÔ!Ø"ˆŒÝ*Ø  E¨Q¡JÑ/Ø(ØØ Ø'ØØð
ñ 
ô 
ˆÔÐÐó    ÚwaveformÚreturnc           	      ó"  — t          |t          | j        d¦  «        | j        | j        d| j        d¬¦  «        }t          j        t          j        |dd¬¦  «        ¦  «        }| j        �&|t          j	        | j        ¦  «        dd…df         z  }|S )z¸
        This method first computes the log-mel spectrogram of the provided audio then applies normalization along the
        each mel-filterbank, if `mel_norms` is provided.
        Úhanng       @N)Úframe_lengthr)   Úpowerr/   Úlog_melgñhãˆµøä>)Úa_minÚa_max)
r   r   r(   r)   r/   ÚnpÚlogÚclipr.   Úarray)r0   r5   Úlog_specs      r3   Ú_np_extract_fbank_featuresz/ClvpFeatureExtractor._np_extract_fbank_featuresj   s’   € õ
 ØÝ˜DœJ¨Ñ/Ô/ØœØ”ØØÔ(Øð
ñ 
ô 
ˆõ ”6�"œ' (°$¸dÐCÑCÔCÑDÔDˆàŒ>Ð%Ø¥"¤(¨4¬>Ñ":Ô":¸1¸1¸1¸d¸7Ô"CÑCˆHàˆr4   TÚ
max_lengthÚ
raw_speechr   Ú
truncationÚpad_to_multiple_ofÚreturn_tensorsr   Úpaddingc	                 ó4  ‡ — |�<|‰ j         k    r0t          d‰ j        j        › d‰ j         › d‰ j         › d|› d�	¦  «        ‚n(t                               d‰ j        j        › d�¦  «         t          |t          j        ¦  «        ot          |j
        ¦  «        d	k    }
|
r*t          |j
        ¦  «        d
k    rt          d‰ › �¦  «        ‚|
pHt          |t          t          f¦  «        o,t          |d         t          j        t          t          f¦  «        }|rd„ |D ¦   «         }n›|s;t          |t          j        ¦  «        s!t          j        |t          j        ¬¦  «        }n^t          |t          j        ¦  «        rD|j        t          j        t          j        ¦  «        u r|                     t          j        ¦  «        }|st          j        |g¦  «        j        g}t'          d|i¦  «        }|€‰ j        ‰ j         z  n|}‰                      ||||||¬¦  «        }|                     d¦  «                             d
dd	¦  «        }ˆ fd„|d         D ¦   «         }t          |d         t          ¦  «        rd„ |D ¦   «         |d<   n||d<   |                     |¦  «        S )a±	  
        `ClvpFeatureExtractor` is used to extract various voice specific properties such as the pitch and tone of the
        voice, speaking speed, and even speaking defects like a lisp or stuttering from a sample voice or `raw_speech`.

        First the voice is padded or truncated in a way such that it becomes a waveform of `self.default_audio_length`
        seconds long and then the log-mel spectrogram is extracted from it.

        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.
            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.
            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*):
                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*, defaults to `True`):
                Whether to return the attention mask. If left to the default, it will return the attention mask.

                [What are attention masks?](../glossary#attention-mask)
            return_tensors (`str` or [`~utils.TensorType`], *optional*):
                If set, will return tensors instead of list of python integers. Acceptable values are:

                - `'pt'`: Return PyTorch `torch.Tensor` objects.
                - `'np'`: Return Numpy `np.ndarray` objects.
            padding_value (`float`, *optional*, defaults to 0.0):
                The value that is used to fill the padding values / vectors.
            max_length (`int`, *optional*):
                The maximum input length of the inputs.
        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   r   z2Only mono-channel audio is supported for input to r   c                 óZ   — g | ](}t          j        |gt           j        ¬ ¦  «        j        ‘Œ)S )©Údtype)r>   ÚasarrayÚfloat32ÚT)Ú.0Úspeechs     r3   ú
<listcomp>z1ClvpFeatureExtractor.__call__.<locals>.<listcomp>Ç   s.   € Ð\Ð\Ð\Àv�"œ* f XµR´ZÐ@Ñ@Ô@ÔBÐ\Ð\Ð\r4   rM   r   )rI   rD   rF   rG   r   c                 ót   •— g | ]4}‰                      |¦  «                             t          j        ¦  «        ‘Œ5S r%   )rC   Úastyper>   rP   )rR   r5   r0   s     €r3   rT   z1ClvpFeatureExtractor.__call__.<locals>.<listcomp>á   sD   ø€ ð 
ð 
ð 
ØMUˆD×+Ò+¨HÑ5Ô5×<Ò<½R¼ZÑHÔHð
ð 
ð 
r4   c                 ó6   — g | ]}t          j        |¦  «        ‘ŒS r%   )r>   rO   )rR   Úfeatures     r3   rT   z1ClvpFeatureExtractor.__call__.<locals>.<listcomp>æ   s"   € Ð.aÐ.aÐ.aÀw­r¬z¸'Ñ/BÔ/BÐ.aÐ.aÐ.ar4   )r   Ú
ValueErrorr2   Ú__name__ÚloggerÚwarningÚ
isinstancer>   ÚndarrayÚlenÚshapeÚlistÚtuplerO   rP   rN   Úfloat64rV   rQ   r   r-   ÚpadÚgetÚ	transposeÚconvert_to_tensors)r0   rE   r   rF   rG   rH   r   rI   rD   r1   Úis_batched_numpyÚ
is_batchedÚbatched_speechÚpadded_inputsr   s   `              r3   Ú__call__zClvpFeatureExtractor.__call__€   s  ø€ ðd Ð$Ø Ô 2Ò2Ð2Ý ðWÈ$Ì.ÔJað Wð WØ)-Ô);ðWð Wà)-Ô);ðWð WàFSðWð Wð Wñô ð ð 3õ �NŠNð\ÐW[ÔWeÔWnð \ð \ð \ñô ð õ
 & jµ"´*Ñ=Ô=Ð[Å#ÀjÔFVÑBWÔBWÐZ[ÒB[ÐØð 	Z¥ JÔ$4Ñ 5Ô 5¸Ò 9Ð 9ÝÐXÐRVÐXÐXÑYÔYÐYØ%ð 
Ý�z¥D­% =Ñ1Ô1ÐlµzÀ*ÈQÄ-ÕRTÔR\Õ^cÕeiÐQjÑ7kÔ7kð 	ð ð 	7Ø\Ð\ÐQ[Ð\Ñ\Ô\ˆJˆJØð 	7¥J¨z½2¼:Ñ$FÔ$Fð 	7Ýœ Jµb´jÐAÑAÔAˆJˆJÝ˜
¥B¤JÑ/Ô/ð 	7°JÔ4DÍÌÕQSÔQ[ÑH\ÔH\Ð4\Ð4\Ø#×*Ò*­2¬:Ñ6Ô6ˆJð ð 	6Ýœ* j \Ñ2Ô2Ô4Ð5ˆJå%Ð'7¸Ð&DÑEÔEˆàGQÐGY�TÔ.°Ô1CÑCÐCÐ_iˆ
àŸšØØØ!Ø!Ø1Ø"7ð !ñ 
ô 
ˆð '×*Ò*Ð+;Ñ<Ô<×FÒFÀqÈ!ÈQÑOÔOˆð
ð 
ð 
ð 
ØYgÐhiÔYjð
ñ 
ô 
ˆõ �n QÔ'­Ñ.Ô.ð 	=Ø.aÐ.aÐR`Ð.aÑ.aÔ.aˆMÐ*Ñ+Ð+à.<ˆMÐ*Ñ+à×/Ò/°Ñ?Ô?Ð?r4   )	r   r   r   r   r   r   r   NF)NTNNTrD   N)rZ   Ú
__module__Ú__qualname__Ú__doc__Úmodel_input_namesr'   r>   r^   rC   ra   ÚfloatÚintÚboolÚstrr	   r   rl   Ú__classcell__)r2   s   @r3   r   r      s‰  ø€ € € € € ð!ð !ðF *Ð+;Ð<Ðð ØØØØØØØØ#ð$
ð $
ð $
ð $
ð $
ð $
ðL°2´:ð À"Ä*ð ð ð ð ð2 %)ØØ)-Ø26Ø-1Ø*Ø!%ðj@ð j@à”J  e¤Ñ,¨t°B´JÔ/?Ñ?À$ÀtÈEÄ{ÔBSÑSðj@ð ˜T‘zðj@ð ð	j@ð
   $™Jðj@ð ˜jÑ(¨4Ñ/ðj@ð  $ d™{ðj@ð �t‘ðj@ð ˜$‘Jðj@ð 
ðj@ð j@ð j@ð j@ð j@ð j@ð j@ð j@r4   r   )ro   Únumpyr>   Úaudio_utilsr   r   r   Ú!feature_extraction_sequence_utilsr   Úfeature_extraction_utilsr   Úutilsr	   r
   Ú
get_loggerrZ   r[   r   Ú__all__r%   r4   r3   ú<module>r}      sÕ   ððð ð Ð Ð Ð à HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HÐ HØ IÐ IÐ IÐ IÐ IÐ IØ 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (ð 
ˆÔ	˜HÑ	%Ô	%€ðL@ð L@ð L@ð L@ð L@Ð3ñ L@ô L@ð L@ð^ "Ð
"€€€r4   