Ë
    ÜÓ^j3  ã                   óÂ   — d dl Zd dlZddlmZ ddlmZ ddlmZm	Z	m
Z
 ddlm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y)é    Né   )ÚSequenceFeatureExtractor)ÚBatchFeature)Ú
TensorTypeÚis_librosa_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_maskc                 ó"  •— t        ‰
| �  d|||dœ|¤Ž || _        || _        || _        || _        t        j                  j                  |||d|dz  d¬«      }	t        j                  |	«      j                  t        j                  «      | _        y )N)Úfeature_sizeÚsampling_rateÚpadding_valueç        é   Ú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   Úkwargsr)   Ú	__class__s             €úƒ/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/parakeet/feature_extraction_parakeet.pyr    z!ParakeetFeatureExtractor.__init__A   s�   ø€ ô 	‰ÑÐw lÀ-Ð_lÑwÐpvÒwà$ˆŒØˆŒ
Ø$ˆŒØ&ˆÔô —o‘o×)Ñ)Ø E°,ÀSÈ}Ð_`ÑO`Ðgoð *ó 
ˆô !×+Ñ+¨KÓ8×;Ñ;¼E¿M¹MÓJˆÕó    c           	      ó  — t        j                  | j                  d|¬«      }t        j                  || j                  | j
                  | j                  |dd¬«      }t        j                  |«      }t        j                  |j                  d«      j                  d«      «      }|j                  d«      }| j                  j                  |«      }||z  }t        j                  |t        z   «      }|j                  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Úsumr)   r'   ÚlogÚLOG_ZERO_GUARD_VALUEÚpermute)r*   Úwaveformr1   r3   r9   Ú
magnitudesr)   Úmel_specs           r-   Ú_torch_extract_fbank_featuresz6ParakeetFeatureExtractor._torch_extract_fbank_featuresc   sÜ   € ä×"Ñ" 4§?¡?¸UÈ6ÔRˆÜ�z‰zØØ�J‰JØ—‘Ø—‘ØØØô
ˆô ×'Ñ'¨Ó-ˆ
Ü—Z‘Z 
§¡¨qÓ 1× 5Ñ 5°bÓ 9Ó:ˆ
Ø—^‘^ AÓ&ˆ
ð ×&Ñ&×)Ñ)¨&Ó1ˆØ Ñ+ˆÜ—9‘9˜XÔ(<Ñ<Ó=ˆð ×#Ñ# A q¨!Ó,ˆàˆr.   NÚ
raw_speechÚ
truncationÚpad_to_multiple_ofÚreturn_tensorsÚreturn_attention_maskÚpaddingÚ
max_lengthr   Údo_normalizer1   Úreturn_token_timestampsÚreturnc                 ó¸	  — |�O|| j                   k7  rmt        d| j                  j                  › d| j                   › d| j                   › d|› d�	«      ‚t        j                  d| j                  j                  › d�«       t        |t        j                  «      rt        j                  |«      }nUt        |t        t        f«      r?t        |d	   t        j                  «      r"|D �cg c]  }t        j                  |«      ‘Œ }}t        |t        j                  «      xr t        |j                  «      d
kD  }|rVt        |j                  «      dkD  r>t        j                  d| j                  j                  › d�«       |j!                  d«      }t        |t        t        f«      }|r^|D ]Y  }t        |j                  «      d
kD  sŒt        j                  d| j                  j                  › d�«       |j!                  d«      }Œ[ |s|r4|D �cg c](  }|dd…df   j#                  t        j$                  «      ‘Œ* }}n'|dd…df   j#                  t        j$                  «      g}|D �cg c]  }t        |«      ‘Œ }}t'        ||dœ«      }| j)                  |||||d¬«      }|j*                  j-                  d«      }| j.                  �°t        j0                  |j                  d
   |j2                  ¬«      j5                  d	«      |j6                  j5                  d
«      k  }t        j8                  |dd…dd
…f   |dd…d
d…f   | j.                  |dd…dd…f   z  z
  gd
¬«      }|j;                  | d«      }| j=                  ||
«      }t        j>                  |j6                  | j@                  dz  dz  z   | j@                  z
  | jB                  «      }t        j0                  |j                  d
   |
¬«      ddd…f   |dd…df   k  }|j5                  d«      }||z  }|jE                  d
¬«      |j5                  d«      z  }|j5                  d
«      }||z
  dz  |z  jE                  d
¬«      |d
z
  j5                  d«      z  }t        jF                  |«      j5                  d
«      }||z
  |tH        z   z  }||z  }t'        ||dœ|¬«      S c c}w c c}w c c}w )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   r7   r   z2Only mono-channel audio is supported for input to z;. We will take the mean of the channels to convert to mono.r6   )r   Úaudio_lengthsÚpt)rJ   rK   rF   rG   rH   )r1   )Údimr   )r   r   )ÚdataÚtensor_type)%r   Ú
ValueErrorr,   Ú__name__ÚloggerÚwarningÚ
isinstanceÚnpÚndarrayr
   ÚtensorÚlistÚtupleÚTensorÚlenÚshapeÚmeanr'   r(   r   Úpadr   Úsqueezer#   Úaranger1   Ú	unsqueezerQ   ÚcatÚmasked_fillrD   Úfloor_divider   r!   r=   r;   ÚEPSILON)r*   rE   rF   rG   rH   rI   rJ   rK   r   rL   r1   rM   r+   ÚspeechÚis_batched_torchÚis_batched_sequencerQ   Úbatched_speechÚpadded_inputsr   ÚtimemaskÚfeatures_lengthsr   ÚmaskÚinput_features_maskedrc   ÚvarianceÚstds                               r-   Ú__call__z!ParakeetFeatureExtractor.__call__   sÇ  € ðH Ð$Ø × 2Ñ 2Ò2Ü ØIÈ$Ï.É.×JaÑJaÐIbð c)Ø)-×);Ñ);Ð(<ð =)Ø)-×);Ñ);Ð(<¸IÀmÀ_ÐTUðWóð ô �N‰NØVÐW[×WeÑWe×WnÑWnÐVoð p\ð \ôô �j¤"§*¡*Ô-ÜŸ™ jÓ1‰JÜ˜
¤T¬5 MÔ2´zÀ*ÈQÁ-ÔQS×Q[ÑQ[Ô7\Ø=GÖH°6œ%Ÿ,™, vÕ.ÐHˆJÐHä% j´%·,±,Ó?Ò]ÄCÈ
×HXÑHXÓDYÐ\]ÑD]ÐÙ¤ J×$4Ñ$4Ó 5¸Ò 9Ü�N‰NØDÀTÇ^Á^×E\ÑE\ÐD]ð ^Lð Lôð $Ÿ™¨Ó,ˆJä(¨´d¼E°]ÓCÐÙØ$ò -�Ü�v—|‘|Ó$ qÓ(Ü—N‘NØLÈTÏ^É^×MdÑMdÐLeð fTð Tôð $Ÿ[™[¨›_‘Fð-ñ Ñ2ØJTÖUÀ˜&¢ D ™/×,Ñ,¬U¯]©]Õ;ÐUˆJÑUà$¢Q¨ WÑ-×0Ñ0´·±Ó?Ð@ˆJà3=Ö>¨œ˜V�Ð>ˆÐ>Ü%¸ÐVcÑ&dÓeˆàŸ™ØØØ!Ø!Ø1Øð !ó 
ˆð '×5Ñ5×=Ñ=¸bÓAˆð ×ÑÐ'Ü—|‘| N×$8Ñ$8¸Ñ$;ÀN×DYÑDYÔZ×dÑdØóà×+Ñ+×5Ñ5°aÓ8ñ9ˆHô #ŸY™YØ¢ 2 A 2 Ñ&¨²q¸!¹"°uÑ(=À×@PÑ@PÐSaÒbcÐehÐfhÐehÐbhÑSiÑ@iÑ(iÐjÐpqôˆNð ,×7Ñ7¸¸	À3ÓGˆNà×;Ñ;¸NÈFÓSˆÜ ×-Ñ-Ø×'Ñ'¨$¯*©*¸©/¸AÑ*=Ñ=ÀÇ
Á
ÑJÈDÏOÉOó
Ðô Ÿ™ n×&:Ñ&:¸1Ñ&=ÀfÔMÈdÒTUÈgÑVÐYiÒjkÐmqÐjqÑYrÑrˆð ×'Ñ'¨Ó+ˆØ .°Ñ 5ÐØ$×(Ñ(¨QÐ(Ó/Ð2B×2LÑ2LÈRÓ2PÑPˆØ�~‰~˜aÓ ˆØ*¨TÑ1°aÑ7¸$Ñ>×CÑCÈÐCÓJÐN^ÐabÑNb×MmÑMmÐnpÓMqÑqˆÜ�j‰j˜Ó"×,Ñ,¨QÓ/ˆØ(¨4Ñ/°C¼'±MÑBˆØ˜$Ñˆäà"0Ø"0ñð 'ô
ð 	
ùòA Iùò* Vùò ?s   Ã&SÈ-SÉ)S)éP   i€>  é    i   i�  g
×£p=
ï?r   )Úcpu)
FNNNÚlongestNNNrz   N)rW   Ú
__module__Ú__qualname__Ú__doc__Úmodel_input_namesr    rD   r[   r\   r^   ÚfloatÚboolÚintÚstrr   r   rw   Ú__classcell__)r,   s   @r-   r   r   #   s4  ø„ ñð4 *Ð+;Ð<Ðð ØØØØØØõ KóDð> !Ø)-Ø26Ø-1Ø'Ø!%Ø$(Ø$(Ø"Ø/3ñ[
à—J‘J  e¡Ñ,¨t°B·J±JÑ/?Ñ?À$ÀtÈEÁ{ÑBSÑSð[
ð ð[
ð   $™Jð	[
ð
 ˜jÑ(¨4Ñ/ð[
ð  $ d™{ð[
ð �t‘ð[
ð ˜$‘Jð[
ð ˜T‘zð[
ð ˜T‘kð[
ð �d‘
ð[
ð "&¨¡ð[
ð 
÷[
r.   r   )Únumpyr[   r
   Ú!feature_extraction_sequence_utilsr   Úfeature_extraction_utilsr   Úutilsr   r   r   Úutils.import_utilsr	   r   rk   r?   Ú
get_loggerrW   rX   r   Ú__all__r   r.   r-   ú<module>rŒ      sx   ðó Û å IÝ 4ß >Ñ >Ý *ñ ÔÛð €ØÐ ð 
ˆ×	Ñ	˜HÓ	%€ñ 
Ð'Ô(ôv
Ð7ó v
ó )ðv
ðr &Ð
&�r.   