+
    &j                     R   ^ RI t ^ RIHt ^ RIHtHt ^ RIHtHt ^ RI	H
t ^ RItRtRt^t^t]],          t]],          t]^,          t]],          t]],          t]],          ]R3R R	 llt]3R
R/R R lllt]! RR7      R R l4       t]! RR7      R 4       tRR ltRR R lltR# )    N)	lru_cache)CalledProcessErrorrun)OptionalUnioni>  i  Fc                0    V ^8  d   QhR\         R\        /# )   filesr)strint)formats   "i/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/mlx_whisper/audio.py__annotate__r      s     'Y 'YS 'Yc 'Y    c                   V'       d   . ROpMRRRV .pVP                  RRRRRR	R
RR\        V4      R.4        \        VRRR7      P                  p\        P                  ! \        P                  ! T\        P                  4      4      P                  4       P                  \        P                  4      R,          #   \         d-   p\        RTP                  P                  4        24      ThRp?ii ; i)a  
Open an audio file and read as mono waveform, resampling as necessary

Parameters
----------
file: str
    The audio file to open

sr: int
    The sample rate to resample the audio if necessary

Returns
-------
A NumPy array containing the audio waveform, in float32 dtype.
ffmpeg-iz-nostdinz-threads0z-fs16lez-ac1z-acodec	pcm_s16lez-ar-T)capture_outputcheckzFailed to load audio: Ng      @)r   r   zpipe:0)extendr   r   stdoutr   RuntimeErrorstderrdecodemxarraynp
frombufferint16flattenastypefloat32)r
   r   
from_stdincmdoutes   &&&   r   
load_audior-      s    & (T40 JJCgs;s2w P#d$7>> 88BMM#rxx0199;BB2::NQXXX  P3AHHOO4E3FGHaOPs   B= =C4'C//C4axisc                0    V ^8  d   QhR\         R\         /# )r	   lengthr.   )r   )r   s   "r   r   r   B   s      s  r   c               n   V P                   V,          V8  d>   \        R4      .V P                  ,          p\        ^ V4      W2&   V \        V4      ,          p V P                   V,          V8  dH   R.V P                  ,          p^ WP                   V,          ,
          3WB&   \        P
                  ! W4      p V # )zG
Pad or trim the audio array to N_SAMPLES, as expected by the encoder.
N)r   r   )shapeslicendimtupler!   pad)r"   r0   r.   sl
pad_widthss   &&$  r   pad_or_trimr9   B   s     {{46!Dk]UZZ'F#eBi {{46!X

*
vD(99:
u)Lr   )maxsizec                D    V ^8  d   QhR\         R\        P                  /# )r	   n_melsreturn)r   r!   r"   )r   s   "r   r   r   T   s     . . . .r   c                    V R9   g   Q RV  24       h\         P                  P                  \         P                  P                  \        4      RR4      p\
        P                  ! V4      RV  2,          # )aD  
load the mel filterbank matrix for projecting STFT into a Mel spectrogram.
Allows decoupling librosa dependency; saved using:

    np.savez_compressed(
        "mel_filters.npz",
        mel_80=librosa.filters.mel(sr=16000, n_fft=400, n_mels=80),
        mel_128=librosa.filters.mel(sr=16000, n_fft=400, n_mels=128),
    )
zUnsupported n_mels: assetszmel_filters.npzmel_>   P      )ospathjoindirname__file__r!   load)r<   filenames   & r   mel_filtersrJ   S   s]     Y?"6vh ??ww||BGGOOH5xARSH778tF8_--r   c                 j    \         P                  ! \        P                  ! V ^,           4      RR 4      # )   N)r!   r"   r#   hanning)sizes   &r   rN   rN   e   s%    88BJJtax("-..r   c                     Vf   TpVf
   V^,          pRR lpV^,          pV! WV4      p V^.p	V P                   V,
          V,           V,          p
W.p\        P                  ! WV	R7      p \        P                  P	                  W,          4      # )Nc                     VR 8X  d   \         P                  ! WV3.4      # VR8X  dE   V ^V^,            RRR1,          pW^,           ) R RRR1,          p\         P                  ! W0V.4      # \        RV 24      h)constantreflectNzInvalid pad_mode rM   )r!   r6   concatenate
ValueError)xpaddingpad_modeprefixsuffixs   &&&  r   _padstft.<locals>._padp   s    z!66!0122"q7Q;'"-F1~+DbD1F>>6f"5660
;<<r   )r2   strides)rR   )rO   r!   
as_stridedfftrfft)rV   windownpersegnoverlapnfftr.   rX   r[   rW   r]   tr2   s   &&&&&&&     r   stftrf   j   s    |19= lGQ"AmG	
'	H	$1AIE
ag6A66;;qz""r   c                r    V ^8  d   QhR\         \        \        P                  3,          R\        R\        /# )r	   audior<   rW   )r   r   r#   ndarrayr   )r   s   "r   r   r      s3     ) )bjj!)) )r   c                   \        V \        4      '       d   \        V 4      p M6\        V \        P                  4      '       g   \        P                  ! V 4      p V^ 8  d   \        P
                  ! V ^ V34      p \        \        4      p\        W\        \        R7      pVRR1R3,          P                  4       P                  4       p\        V4      pWVP                  ,          p\        P                  ! VR4      P                  4       p\        P                  ! WP!                  4       R,
          4      pVR,           R,          pV# )a  
Compute the log-Mel spectrogram of

Parameters
----------
audio: Union[str, np.ndarray, mx.array], shape = (*)
    The path to audio or either a NumPy or mlx array containing the audio waveform in 16 kHz

n_mels: int
    The number of Mel-frequency filters, only 80 is supported

padding: int
    Number of zero samples to pad to the right

Returns
-------
mx.array, shape = (80, n_frames)
    An  array that contains the Mel spectrogram
)rb   rc   N:NNNg|=g       @g      @rM   )
isinstancer   r-   r!   r"   r6   rN   N_FFTrf   
HOP_LENGTHabssquarerJ   Tmaximumlog10max)	rh   r<   rW   ra   freqs
magnitudesfiltersmel_speclog_specs	   &&&      r   log_mel_spectrogramry      s    0 %5!rxx(({uq'l+U^F
CEssAv""$++-J&!GII%Hzz(E*002Hzz(LLNS$89H3#%HOr   rM   )   NNrM   rS   )rA   r   )rC   	functoolsr   
subprocessr   r   typingr   r   mlx.corecorer!   numpyr#   SAMPLE_RATErl   rm   CHUNK_LENGTH	N_SAMPLESN_FRAMESN_SAMPLES_PER_TOKENFRAMES_PER_SECONDTOKENS_PER_SECONDr   r-   r9   rJ   rN   rf   ry    r   r   <module>r      s    
  . "   
;&	
" 1n :- #66  $C=KE 'YT &/ r  " 4. ." 4/ /#4) )r   