+
    œ°³j²B  ã                   ó¼   € R t ^ RIt^RIHt ^RIHtHtHt ^RI	H
t
 ^RIHt ^RIHtHt ]! 4       '       d   ^ RIt]P"                  ! ]4      t ! R R]
4      tR.tR# )	z%
Feature extractor class for Whisper
N)Úis_torch_available)Úmel_filter_bankÚspectrogramÚwindow_function)ÚSequenceFeatureExtractor)ÚBatchFeature)Ú
TensorTypeÚloggingc                   óž   a a€ ] tR t^!t oRtR.tRV 3R lltV3R lR ltRV3R lR llt]	RV3R lR	 ll4       t
RV3R
 lR lltRtVtV ;t# )ÚWhisperFeatureExtractora/  
Constructs a Whisper 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.
    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 400):
        Size of the Fourier transform.
    padding_value (`float`, *optional*, defaults to 0.0):
        Padding value used to pad the audio. Should correspond to silences.
    dither (`float`, *optional*, defaults to 0.0):
        Adds dithering. In other words, adds a small Gaussian noise to each frame.
        E.g. use 0.0001 to add dithering with a normal distribution centered
        around 0.0 with standard deviation 0.0001 (assuming [-1,+1] range of raw_speech).
        The value 0.0 means no dithering.
        Dithering has similar effect as `spectrogram(mel_floor=...)`. It reduces
        the high log_mel_fbank values for signals with hard-zero sections,
        when VAD cutoff is present in the signal.
Úinput_featuresc	                ó  <€ \         S
V `  ! R	R VRVRVRV/V	B  WPn        W0n        W@n        WB,          V n        V P
                  V,          V n        W n        Wpn        \        ^V^,          ,           VRRVRRR7      V n
        R# )
Úfeature_sizeÚsampling_rateÚpadding_valueÚreturn_attention_maskç        g     @¿@Úslaney)Únum_frequency_binsÚnum_mel_filtersÚmin_frequencyÚmax_frequencyr   ÚnormÚ	mel_scaleN© )ÚsuperÚ__init__Ún_fftÚ
hop_lengthÚchunk_lengthÚ	n_samplesÚnb_max_framesr   Úditherr   Úmel_filters)Úselfr   r   r   r   r   r   r"   r   ÚkwargsÚ	__class__s   &&&&&&&&&,€Úw/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/whisper/feature_extraction_whisper.pyr   Ú WhisperFeatureExtractor.__init__E   s¢   ø€ ô 	‰Òñ 	
Ø%ð	
à'ð	
ð (ð	
ð #8ð		
ð
 ò	
ð Œ
Ø$ŒØ(ÔØ%Õ5ˆŒØ!Ÿ^™^¨zÕ9ˆÔØ*ÔØŒÜ*Ø  5¨A¥:�~Ø(ØØ Ø'ØØô
ˆÖó    c                óT   <€ V ^8„  d   QhRS[ P                  RS[RS[ P                  /# )é   Úwaveform_batchÚdeviceÚreturn©ÚnpÚndarrayÚstr)ÚformatÚ__classdict__s   "€r'   Ú__annotate__Ú$WhisperFeatureExtractor.__annotate__i   s-   ø€ ÷ ñ ¹¿¹ð ÉSð ÑUW×U_ÑU_ñ r)   c                óÄ  € VR8w  d   \        RV R24      h. pV F«  p\        V\        V P                  R4      V P                  V P                  RV P
                  V P                  RR7      pVRR	R13,          p\        P                  ! WUP                  4       R
,
          4      pVR,           R,          pVP                  V4       K­  	  \        P                  ! V4      pV# )zŽ
Compute the log-mel spectrogram of the provided audio, gives similar results to Whisper's original torch
implementation with 1e-5 tolerance.
ÚcpuzGot device `zñ` for feature extraction, but feature extraction on CUDA accelerator devices requires torch, which is not installed. Either set `device='cpu'`, or install torch according to the official instructions: https://pytorch.org/get-started/locally/Úhanng       @Úlog10)Úframe_lengthr   Úpowerr"   r#   Úlog_melºNNNNç       @ç      @éÿÿÿÿ)Ú
ValueErrorr   r   r   r   r"   r#   r0   ÚmaximumÚmaxÚappendÚarray)r$   r,   r-   Úlog_spec_batchÚwaveformÚlog_specs   &&&   r'   Ú_np_extract_fbank_featuresÚ2WhisperFeatureExtractor._np_extract_fbank_featuresi   sÚ   € ð
 �UŒ?ÜØ˜v˜hð 'qð qóð ð
 ˆÛ&ˆHÜ"ØÜ §
¡
¨FÓ3Ø!ŸZ™ZØŸ?™?ØØ—{‘{Ø ×,Ñ,Øô	ˆHð    3 B 3 Õ'ˆHÜ—z’z (¯L©L«N¸SÕ,@ÓAˆHØ  3�¨#Õ-ˆHØ×!Ñ! (Ö+ñ 'ô Ÿš .Ó1ˆØÐr)   c                óT   <€ V ^8„  d   QhRS[ P                  RS[RS[ P                  /# )r+   rH   r-   r.   r/   )r3   r4   s   "€r'   r5   r6   ‡   s-   ø€ ÷ ! ñ ! ±b·j±jð ! É#ð ! ÑZ\×ZdÑZdñ ! r)   c                óÀ  € \         P                  ! V4      P                  V\         P                  4      p\         P                  ! V P
                  VR7      pV P                  R8w  dO   WP                  \         P                  ! VP                  VP                  VP                  R7      ,          ,          p\         P                  ! WP
                  V P                  VRR7      pVRRR13,          P                  4       ^,          P                  4       p\         P                  ! V P                  4      P                  V\         P                  4      pVP                   V,          p\         P"                  ! VRR	7      P%                  4       pVP'                  4       ^8X  dQ   VP)                  ^RR
7      ^ ,          P)                  ^RR
7      ^ ,          p	\         P*                  ! W‰R,
          4      pM+\         P*                  ! WˆP)                  4       R,
          4      pVR,           R,          pVR8w  d   VP-                  4       P/                  4       pVP1                  4       # )z°
Compute the log-mel spectrogram of the audio using PyTorch's GPU-accelerated STFT implementation with batching,
yielding results similar to cpu computing with 1e-5 tolerance.
)r-   r   )Údtyper-   T)ÚwindowÚreturn_complex.Ng»½×Ùß|Û=)Úmin)ÚdimÚkeepdimr?   r@   r8   rA   )ÚtorchÚ
from_numpyÚtoÚfloat32Úhann_windowr   r"   ÚrandnÚshaperN   r-   Ústftr   ÚabsÚ
contiguousr#   ÚTÚclampr:   rR   rD   rC   Údetachr8   Únumpy)
r$   rH   r-   rO   r[   Ú
magnitudesr#   Úmel_specrI   Úmax_vals
   &&&       r'   Ú_torch_extract_fbank_featuresÚ5WhisperFeatureExtractor._torch_extract_fbank_features‡   s¨  € ô
 ×#Ò# HÓ-×0Ñ0°¼¿¹ÓGˆÜ×"Ò" 4§:¡:°fÔ=ˆð
 �;‰;˜#ÔØŸ™¤e§k¢k°(·.±.ÈÏÉÐ_g×_nÑ_nÔ&oÕoÕoˆHä�zŠz˜(§J¡J°·±ÈÐ_cÔdˆð
 ˜3   ˜8•n×(Ñ(Ó*¨aÕ/×;Ñ;Ó=ˆ
ä×&Ò& t×'7Ñ'7Ó8×;Ñ;¸FÄEÇMÁMÓRˆØ—=‘= :Õ-ˆä—;’;˜x¨UÔ3×9Ñ9Ó;ˆØ�<‰<‹>˜QÔØ—l‘l q°$�lÓ7¸Õ:×>Ñ>À1ÈdÐ>ÓSÐTUÕVˆGÜ—}’} X¸­}Ó=‰Hä—}’} X¯|©|«~ÀÕ/CÓDˆHØ˜s•N cÕ)ˆØ�UŒ?Ø—‘Ó(×,Ñ,Ó.ˆHØ�~‰~ÓÐr)   c          	      óž   <€ V ^8„  d   QhRS[ S[P                  ,          RS[ S[P                  ,          RS[RS[ S[P                  ,          /# )r+   Úinput_valuesÚattention_maskr   r.   )Úlistr0   r1   Úfloat)r3   r4   s   "€r'   r5   r6   ¬   sH   ø€ ÷ #ñ #Ù™2Ÿ:™:Õ&ð#Ù8<¹R¿Z¹ZÕ8Hð#ÙY^ð#á	‰b�j‰jÕ	ñ#r)   c                óJ  € VeÅ   \         P                  ! V\         P                  4      p. p\        WP	                  R4      4       F}  w  rEWDRV P                  4       ,
          \         P                  ! VRV P                  4       R,           4      ,          pWVP                  ^ ,          8  d   W&VR% VP                  V4       K  	  V# V  Uu. uFI  qwVP                  4       ,
          \         P                  ! VP                  4       R,           4      ,          NKK  	  ppV# u upi )zK
Every array in the list is normalized to have zero mean and unit variance
NgH¯¼šò×z>rA   )
r0   rF   Úint32ÚzipÚsumÚmeanÚsqrtÚvarrZ   rE   )rh   ri   r   Únormed_input_valuesÚvectorÚlengthÚnormed_sliceÚxs   &&&     r'   Úzero_mean_unit_var_normÚ/WhisperFeatureExtractor.zero_mean_unit_var_normª   sù   € ð Ò%ÜŸXšX n´b·h±hÓ?ˆNØ"$Ðä"% l×4FÑ4FÀrÓ4JÖ"K‘�Ø &°°¨×)=Ñ)=Ó)?Õ ?Ä2Ç7Â7È6ÐRYÐSYÈ?×K^ÑK^ÓK`ÐcgÕKgÓChÕh�Ø×.Ñ.¨qÕ1Ô1Ø,9  Ð)à#×*Ñ*¨<Ö8ñ #Lð #Ð"ñ VbÓ"bÑUaÐPQ¨¯©«¥L´B·G²G¸A¿E¹E»GÀd½NÓ4K×#KÐ#KÑUaÐÐ"bà"Ð"ùò #cs   ÃAD c                ót  <€ V ^8„  d   QhRS[ P                  S[S[,          ,          S[S[ P                  ,          ,          S[S[S[,          ,          ,          RS[RS[R,          RS[S[,          R,          RS[R,          RS[R,          RS[R,          R	S[R,          R
S[R,          RS[R,          RS[/# )r+   Ú
raw_speechÚ
truncationÚpad_to_multiple_ofNÚreturn_tensorsr   ÚpaddingÚ
max_lengthr   Údo_normalizer-   r.   )	r0   r1   rj   rk   ÚboolÚintr2   r   r   )r3   r4   s   "€r'   r5   r6   Á   sÕ   ø€ ÷ Yñ Yá—J‘J¡¡e¥Õ,©t±B·J±JÕ/?Õ?Á$ÁtÉEÅ{ÕBSÕSðYñ ðYñ   $�Jð	Yñ
 ™jÕ(¨4Õ/ðYñ  $ d�{ðYñ �t•ðYñ ˜$•JðYñ ˜T•zðYñ ˜T•kðYñ �d•
ðYñ 
ñYr)   c                óž  € VeR   W€P                   8w  dA   \        RV P                  P                   RV P                    RV P                    RV R2	4      hM-\        P                  RV P                  P                   R24       \        V\        P                  4      ;'       d    \        VP                  4      ^8„  pV'       d)   \        VP                  4      ^8”  d   \        R	V  24      hT;'       gK    \        V\        \        34      ;'       d-    \        V^ ,          \        P                  \        \        34      pV'       dB   V Uu. uF4  p\        P                  ! V.\        P                  R
7      P                  NK6  	  ppMÀV'       gH   \        V\        P                  4      '       g(   \        P                  ! V\        P                  R
7      pMq\        V\        P                  4      '       dR   VP                   \        P                   ! \        P"                  4      J d    VP%                  \        P                  4      pV'       g#   \        P                  ! V.4      P                  .p\'        RV/4      pT P)                  TTV'       d   TMV P*                  TTT;'       g    T	R7      pV	'       dR   V P-                  VR,          VR,          V P.                  R7      VR&   \        P0                  ! VR,          ^ R7      VR&   VP3                  R4      P5                  ^^ ^4      p\7        4       '       d   V P8                  MV P:                  pV! V^ ,          V
4      p\        V^ ,          \        4      '       d;   V Uu. uF)  p\        P                  ! V\        P                  R
7      NK+  	  upVR&   MVVR&   V'       db   VR,          RRRV P<                  13,          pVR,          P                  ^,          V P<                  ,          ^ 8w  d   VRRR13,          pVVR&   Ve   VP?                  V4      pV# u upi u upi )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_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.
    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 Whisper models, `attention_mask` should always be passed for batched inference, to avoid subtle
        bugs.

        </Tip>
    padding (`str` or [`~utils.PaddingStrategy`], *optional*, defaults to `'max_length'`):
        Activates and controls padding. Accepts the following values:

        - `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single sequence is
          provided).
        - `'max_length'` (default): 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.
        - `'do_not_pad'`: No padding (i.e., can output a batch with sequences of different lengths).
    max_length (`int`, *optional*):
        Controls the maximum length to use by one of the truncation/padding parameters.

        If left unset or set to `None`, this will use the predefined model maximum length if a maximum length
        is required by one of the truncation/padding parameters. If the model has no specific maximum input
        length (like XLNet) truncation/padding to a maximum length will be deactivated.
    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.
    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")
    **kwargs: Not supported by WhisperFeatureExtractor.__call__() and ignored.
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.z2Only mono-channel audio is supported for input to )rN   r   )r   r€   r|   r}   r   ri   )ri   r   )Úaxisr>   rA   ) r   rB   r&   Ú__name__ÚloggerÚwarningÚ
isinstancer0   r1   ÚlenrZ   rj   ÚtupleÚasarrayrW   r^   rN   Úfloat64Úastyper   Úpadr    rx   r   ÚstackÚgetÚ	transposer   re   rJ   r   Úconvert_to_tensors)r$   r{   r|   r}   r~   r   r   r€   r   r�   r-   r%   Úis_batched_numpyÚ
is_batchedÚspeechÚbatched_speechÚpadded_inputsr   Úextract_fbank_featuresÚfeatureÚrescaled_attention_masks   &&&&&&&&&&&,         r'   Ú__call__Ú WhisperFeatureExtractor.__call__Á   sÃ  € ðP Ò$Ø× 2Ñ 2Ô2Ü ØIÈ$Ï.É.×JaÑJaÐIbð c)Ø)-×);Ñ);Ð(<ð =)Ø)-×);Ñ);Ð(<¸IÀmÀ_ÐTUðWóð ð 3ô �N‰NØVÐW[×WeÑWe×WnÑWnÐVoð p\ð \ôô
 & j´"·*±*Ó=×[Ð[Ä#Àj×FVÑFVÓBWÐZ[ÑB[Ðß¤ J×$4Ñ$4Ó 5¸Ô 9ÜÐQÐRVÐQWÐXÓYÐYØ%÷ 
ð 
Ü�z¤D¬% =Ó1×lÐl´zÀ*ÈQÅ-ÔRT×R\ÑR\Ô^cÔeiÐQjÓ7kð 	÷ ÙQ[Ó\ÑQ[Àvœ"Ÿ*š* f X´R·Z±ZÔ@×BÔBÑQ[ˆJÐ\ˆJß¤J¨z¼2¿:¹:×$FÒ$FÜŸš J´b·j±jÔA‰JÜ˜
¤B§J¡J×/Ò/°J×4DÑ4DÌÏÊÔQS×Q[ÑQ[ÓH\Ó4\Ø#×*Ñ*¬2¯:©:Ó6ˆJ÷ ÜŸ*š* j \Ó2×4Ñ4Ð5ˆJä%Ð'7¸Ð&DÓEˆð Ÿ™ØØß%/‘z°T·^±^Ø!Ø1Ø"7×"GÐ"G¸<ð !ó 
ˆ÷ Ø.2×.JÑ.JØÐ.Õ/Ø,Ð-=Õ>Ø"×0Ñ0ð /Kó /ˆMÐ*Ñ+ô
 /1¯hªh°}ÐEUÕ7VÐ]^Ô._ˆMÐ*Ñ+ð '×*Ñ*Ð+;Ó<×FÑFÀqÈ!ÈQÓOˆô 3E×2FÒ2FˆD×.Ò.ÈD×LkÑLkð 	ñ 0°¸qÕ0AÀ6ÓJˆä�n QÕ'¬×.Ò.ÙdrÓ.sÑdrÐY`¬r¯zªz¸'ÌÏÉ×/TÑdrÑ.sˆMÐ*Ò+ð /=ˆMÐ*Ñ+ç à&3Ð4DÕ&EÀaÑI[ÈDÏOÉOÐI[ÐF[Õ&\Ð#ð
 Ð-Õ.×4Ñ4°QÕ7¸$¿/¹/ÕIÈQÔNØ*AÀ!ÀSÀbÀSÀ&Õ*IÐ'Ø.EˆMÐ*Ñ+àÒ%Ø)×<Ñ<¸^ÓLˆMàÐùòy ]ùòR /ts   Å:QÎ
/Q
)r   r"   r   r#   r   r    r!   r   )éP   i€>  é    é   i�  r   r   F)r8   )r   )	TNNNr€   NNNr8   )r‡   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Úmodel_input_namesr   rJ   re   Ústaticmethodrx   r�   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r&   r4   s   @@r'   r   r   !   s\   ù‡ € ñðB *Ð*Ð÷"
÷Hð ÷<! ò ! ðF ÷#ñ #ó ð#÷*Y÷ Yò Yr)   r   )r¥   ra   r0   Ú r   Úaudio_utilsr   r   r   Ú!feature_extraction_sequence_utilsr   Úfeature_extraction_utilsr   Úutilsr   r	   rT   Ú
get_loggerr‡   rˆ   r   Ú__all__r   r)   r'   Ú<module>r²      sY   ðñó å "ß HÑ HÝ IÝ 4ß (ñ ×ÒÛà	×	Ò	˜HÓ	%€ôyÐ6ô yðx	 %Ð
%‚r)   