+
    &jY                        ^ RI t ^ RIt^ RIHtHtHtHt ^ RIHt	 ^ RI
t^ RIt^RIHtHtHtHtHtHtHt ^RIHtHt ^RIHt ^RIHt ^RIHtHt R R	 ltR
 R lt  ! R R4      t!RRRRRR%RRRR&RRRRRRRRRRRRR R!R"R/R# R$ llt"R# )'    N)ListOptionalTupleUnion)FRAMES_PER_SECOND
HOP_LENGTHN_FRAMES	N_SAMPLESSAMPLE_RATElog_mel_spectrogrampad_or_trim)DecodingOptionsDecodingResult)
load_model)add_word_timestamps)	LANGUAGESget_tokenizerc                $    V ^8  d   QhR\         /# )   seconds)float)formats   "n/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/mlx_whisper/transcribe.py__annotate__r      s     K Ku K    c                    V ^ 8  g   Q R4       h\        V R,          4      pVR,          pWR,          ,          pVR,          pWR,          ,          pVR,          p WR,          ,          pV^ 8  d   VR R2MRpV VR RV R R	VR
 2# )r   znon-negative timestamp expectedg     @@i6 i`  i  02d: .03d)round)r   millisecondshoursminuteshours_markers   &    r   _format_timestampr'      s    a<:::<6)*LI%EI%%Lf$Gf$$Le#GeO#L&+aieC[?RL^GC='#aS7IJJr   c                \    V ^8  d   QhR\         \        ,          R\        \        ,          /# r   segmentsreturn)r   dictr   r   )r   s   "r   r   r   +   s"      tDz huo r   c                 r    \        R  \        V 4       4       V '       d   V R,          R,          4      # R4      # )c              3   d   "   T F&  p\        VR ,          4       F  q"R,          x  K  	  K(  	  R# 5i)wordsendN)reversed).0sws   &  r   	<genexpr>_get_end.<locals>.<genexpr>-   s(     L-ax'
7K!57K-s   .0r0   N)nextr1   r*   s   &r   _get_endr:   +   s7    L8H-L'U -1 r   c                   D   a  ] tR t^2t o RtRt]V 3R lR l4       tRtV t	R# )ModelHolderNc                :   < V ^8  d   QhRS[ RS[P                  /# )r   
model_pathdtype)strmxDtype)r   __classdict__s   "r   r   ModelHolder.__annotate__7   s      3 rxx r   c                    V P                   e   WP                  8w  d   \        WR7      V n         Wn        V P                   # )N)r?   )modelr>   r   )clsr>   r?   s   &&&r   	get_modelModelHolder.get_model6   s0    99
nn <":;CI'Nyyr    )
__name__
__module____qualname____firstlineno__rF   r>   classmethodrH   __static_attributes____classdictcell__)rC   s   @r   r<   r<   2   s!     EJ r   r<   path_or_hf_repozmlx-community/whisper-tinyverbosetemperature333333?compression_ratio_thresholdg333333@logprob_thresholdno_speech_thresholdcondition_on_previous_textTinitial_promptword_timestampsFprepend_punctuationsu   "'“¿([{-append_punctuationsu   "'.。,，!！?？:：”)]}、clip_timestamps0hallucination_silence_thresholdc                   V ^8  d   QhR\         \        \        P                  \        P
                  3,          R\        R\        \        ,          R\         \        \        \        R3,          3,          R\        \        ,          R\        \        ,          R\        \        ,          R	\        R
\        \        ,          R\        R\        R\        R\         \        \        \        ,          3,          R\        \        ,          /# )r   audiorR   rS   rT   .rV   rW   rX   rY   rZ   r[   r\   r]   r^   r`   )r   r@   npndarrayrA   arrayr   boolr   r   r   )r   s   "r   r   r   >   s     a abjj"((*+a a d^	a
 ueE3J//0a "*%a  a "%a !%a SMa a a a 3U+,a &.e_ar   c               0  aaaaaaRaSaTaUaVaW SP                  RR4      '       d   \        P                  M\        P                  p\        P                  W4      oR\        V SRP                  P                  \        R7      pVP                  R8,          \        ,
          p\        V\        ,          \        ,          4      pV'       d'   \        P                   ! 4       oUSUR8w  d   VU3R lpMR pSP                  RR4      f   SRP"                  '       g   R	SR&   MV'       d   \%        R
4       \'        V\        R8R7      P)                  V4      pSRP+                  V4      w  pp\-        VVP                   R7      SR&   Ve/   \%        R\.        SR,          ,          P1                  4        24       SR,          pSP                  RR4      p\3        SRP"                  SRP4                  VVR7      oV\7        V\8        4      '       d4   V'       d   VP;                  R4      M.  Uu. uF  p\        V4      NK  	  ppV Uu. uF  p\=        V\>        ,          4      NK  	  pp\A        V4      ^ 8X  d   VPC                  ^ 4       \A        V4      ^,          ^8X  d   VPC                  V4       M\E        VVR9,          4      VR9&   \G        \I        VR,          VR,          4      4      pRoSV	'       d   VR8X  d   \J        PL                  ! R4       R VVVVRVV3R llp^ pVV,          ^ ,          oT\        SRP                  PN                  ,          pV\        ,          \        ,          p. p . p!^ p"Ve9   SVPQ                  RVPS                  4       ,           4      p#V PU                  V#4       M. p#R VTVV3R llp$\V        PV                  ! VRVRJR7      ;_uu_ 4       p%Rp&V EFh  w  p'p(STV(8  g   K  \        ST\        ,          \        ,          4      p)\        ST\        ,           \        ,          \        ,          4      p*\E        \        VST,
          V(ST,
          4      p+VSTSTV+,            pV+\        ,          \        ,          p,\'        V\        R8R7      P)                  V4      pV V"R SR &   V! V4      p-\X        PZ                  ! V-P\                  4      p.Se;   V-P^                  S8  p/Se   V-P`                  S8  d   Rp/V/'       d   STV+,          oTEK(  STp0. p1R! R" loWR# VSVW3R$ llp2R% R& lp3V.SVPb                  8  p4V4R8R Pe                  4       RR.8H  p5\X        Pf                  ! \X        Ph                  ! V4RR9 V4R',          4      4      ^ ,          p6V6^,          p6\A        V64      ^ 8  Ed   V6Pe                  4       p7V5'       d   V7PC                  \A        V.4      4       ^ p8V7 F  p9V.V8V9 p:V:^ ,          Pk                  4       SVPb                  ,
          p;V:R9,          Pk                  4       SVPb                  ,
          p<V1PC                  V$! V)V;V,          ,           V)V<V,          ,           V:V-R(7      4       T9p8K  	  V5'       d   STV+,          oTMV.V8^,
          ,          Pk                  4       SVPb                  ,
          p=STV=V,          ,          oTMT,p>V.V4Pm                  4       ^ ,          ,          p?\A        V?4      ^ 8  dX   V?R9,          Pk                  4       SVPb                  8w  d2   V?R9,          Pk                  4       SVPb                  ,
          p=V=V,          p>V1PC                  V$! V)V)V>,           V.V-R(7      4       STV+,          oTV	'       Edc   \o        V1SRSVVV+V
VV&R)7       V5'       g-   \q        V14      p@V@e   X@V)8  d   \=        X@\>        ,          4      oTVEe   TpAV5'       gG   \q        V14      p@V@e8   X@V)8  d1   V*X@,
          pBVBXA8  d   \=        X@\>        ,          4      oTM	V0V+,           oTV3! V14      pCVCeF   V2! XC4      '       d8   XCR*,          V),
          pDVDXA8  d!   V0\=        XD\>        ,          4      ,           oTEK  T&pE\s        \A        V14      4       EFI  pFV1VF,          pGVGR+,          '       g   K  V2! XG4      '       Ed   V3! V1XF^,           R 4      pHVHe   XHR+,          ^ ,          R*,          pIM	V)V,,           pIXGR*,          XE,
          XA8  ;'       g(    XGR*,          XA8  ;'       g    XGR*,          V),
          R,8  pJXIXGR-,          ,
          XA8  ;'       g$    V2! XH4      ;'       g    V*XGR-,          ,
          R,8  pKXJ'       dU   XK'       dM   \=        \-        V)^,           XGR*,          4      \>        ,          4      oTVVGR-,          ,
          XA8  d   VoT. V1XFR%  MXGR-,          pEEKL  	  \q        V14      p@V@e   X@p&V'       dS   V1 FL  pGVGR*,          VGR-,          VGR.,          pNpMpLR/\u        VL4       R0\u        VM4       R1VN 2pO\%        X! VO4      4       KN  	  \w        V14       FH  w  pPpGVGR*,          VGR-,          8X  g   XGR.,          PS                  4       R28X  g   K9  R2XGR.&   . VGR3&   . VGR+&   KJ  	  T!PU                  \w        V1\A        V!4      R47       UPUGu. uF  w  pPpGR5VP/VGCNK  	  upGpP4       T PU                  V1 UGUQu. uF  pGVGR3,           F  pQVQNK  	  K  	  upQpG4       V'       d   V-Px                  R68  d   \A        V 4      p"V%P{                  \E        VST4      V0,
          4       EKd  	  RRR4       \}        SVP                  V \A        V#4      R 4      V!VR77      # u upi u upi u upGpPi u upQpGi   + '       g   i     LO; i):a
  
Transcribe an audio file using Whisper

Parameters
----------
audio: Union[str, np.ndarray, mx.array]
    The path to the audio file to open, or the audio waveform

path_or_hf_repo: str
    The localpath to the Whisper model or HF Hub repo with the MLX converted weights.

verbose: bool
    Whether to display the text being decoded to the console. If True, displays all the details,
    If False, displays minimal details. If None, does not display anything

temperature: Union[float, Tuple[float, ...]]
    Temperature for sampling. It can be a tuple of temperatures, which will be successively used
    upon failures according to either `compression_ratio_threshold` or `logprob_threshold`.

compression_ratio_threshold: float
    If the gzip compression ratio is above this value, treat as failed

logprob_threshold: float
    If the average log probability over sampled tokens is below this value, treat as failed

no_speech_threshold: float
    If the no_speech probability is higher than this value AND the average log probability
    over sampled tokens is below `logprob_threshold`, consider the segment as silent

condition_on_previous_text: bool
    if True, the previous output of the model is provided as a prompt for the next window;
    disabling may make the text inconsistent across windows, but the model becomes less prone to
    getting stuck in a failure loop, such as repetition looping or timestamps going out of sync.

word_timestamps: bool
    Extract word-level timestamps using the cross-attention pattern and dynamic time warping,
    and include the timestamps for each word in each segment.

prepend_punctuations: str
    If word_timestamps is True, merge these punctuation symbols with the next word

append_punctuations: str
    If word_timestamps is True, merge these punctuation symbols with the previous word

initial_prompt: Optional[str]
    Optional text to provide as a prompt for the first window. This can be used to provide, or
    "prompt-engineer" a context for transcription, e.g. custom vocabularies or proper nouns
    to make it more likely to predict those word correctly.

decode_options: dict
    Keyword arguments to construct `DecodingOptions` instances

clip_timestamps: Union[str, List[float]]
    Comma-separated list start,end,start,end,... timestamps (in seconds) of clips to process.
    The last end timestamp defaults to the end of the file.

hallucination_silence_threshold: Optional[float]
    When word_timestamps is True, skip silent periods longer than this threshold (in seconds)
    when a possible hallucination is detected

Returns
-------
A dictionary containing the resulting text ("text") and segment-level details ("segments"), and
the spoken language ("language"), which is detected when `decode_options["language"]` is None.
fp16T)n_melspaddingzutf-8c                 H   < V P                  SR R7      P                  S4      # )replace)errors)encodedecode)xsystem_encodings   &r   <lambda>transcribe.<locals>.<lambda>   s     !((?9("M"T"T#r   c                     V # NrJ   )rp   s   &r   rr   rs      s    !r   languageNenzoDetecting language using up to the first 30 seconds. Use the `language` decoding option to specify the language)axis)keyzDetected language: task
transcribe)num_languagesrv   rz   ,:NNr   :   Nr   u*   "'“¿([{-"'.。,，!！?？:：”)]}、	translatez:Word-level timestamps on translations may not be reliable.c                D    V ^8  d   QhR\         P                  R\        /# r   segmentr+   )rA   re   r   )r   s   "r   r    transcribe.<locals>.__annotate__   s     & &bhh &> &r   c                   < \        S\        \        34      '       d   S.MSpR pV F  p/ SCpV^ 8  d&   VP                  RR 4       VP                  RR 4       MVP                  RR 4       \	        R/ VBRV/B pS
P                  W4      pRpSe   VP                  S8  d   RpS	e   VP                  S	8  d   RpSe   VP                  S8  d   RpV'       d   K   V# 	  V# )N	beam_sizepatiencebest_ofrT   FTrJ   )	
isinstanceintr   popr   ro   compression_ratioavg_logprobno_speech_prob)r   temperaturesdecode_resulttkwargsoptionsneeds_fallbackrV   decode_optionsrW   rF   rX   rT   s   &      r   decode_with_fallback(transcribe.<locals>.decode_with_fallback   s    'c5\BB[M 	 A''F1u

;-

:t, 

9d+%>>A>G!LL:M"N+7!336QQ!%!-!--0AA!%#/!003FF!&!>A @ r    c                \    V ^8  d   QhR\         R\         R\        P                  R\        /# )r   startr0   tokensresult)r   rA   re   r   )r   s   "r   r   r     s0     
 

#
-/XX
?M
r   c                 
  < VP                  4       pV Uu. uF  qDSP                  8  g   K  VNK  	  ppR SRV RVRSP                  V4      RVRVP                  RVP                  RVP
                  RVP                  /	# u upi )	seekr   r0   textr   rT   r   r   r   )tolisteotro   rT   r   r   r   )r   r0   r   r   tokentext_tokensr   	tokenizers   $$$$  r   new_segmenttranscribe.<locals>.new_segment  s     *0J&IMM4Iuu&JDU3I$$[1f6--6--!9!9f33

 
	
 Ks
   B B framesF)totalunitdisable        promptc                0    V ^8  d   QhR\         R\        /# )r   wordr+   )r,   r   )r   s   "r   r   r   A  s     
! 
!T 
!e 
!r   c                     V P                  R R4      pV R,          V R,          ,
          pRpVR8  d
   VR,          pVR8  d   VRV,
          ^,          ,          pVR8  d   W2R,
          ,          pV# )probabilityr   r0   r   g333333?      ?g/$?       @)get)r   r   durationscores   &   r   word_anomaly_score&transcribe.<locals>.word_anomaly_scoreA  sn    "&((=#">K#E{T']:HE"T)%'%("2b!88#~C/ Lr   c                F    V ^8  d   QhR\         \        ,          R\        /# r   )r   r,   rf   )r   s   "r   r   r   M  s"     D D D4 Dr   c                   < V e   V R,          '       g   R# V R,           Uu. uF  qR,          S9  g   K  VNK  	  ppVR,          p\        V3R lV 4       4      pV^8  ;'       g    VR,           \        V4      8  # u upi )Nr/   Fr   :N   Nc              3   4   <"   T F  pS! V4      x  K  	  R # 5iru   rJ   )r2   r4   r   s   & r   r5   9transcribe.<locals>.is_segment_anomaly.<locals>.<genexpr>T  s     Eu! 21 5 5us   g{Gz?)sumlen)r   r4   r/   r   punctuationr   s   &   r   is_segment_anomaly&transcribe.<locals>.is_segment_anomalyM  s    gg.>.>$#*7#3#3ay7S#3   ""IEEuEEE A:CCU)CCs
   A>A>c                \    V ^8  d   QhR\         \        ,          R\        \        ,          /# r)   )r   r,   r   )r   s   "r   r   r   W  s&     K Kd K Kr   c                 (    \        R  V  4       R4      # )c              3   F   "   T F  qR ,          '       g   K  Vx  K  	  R# 5i)r/   NrJ   )r2   r3   s   & r   r5   9transcribe.<locals>.next_words_segment.<locals>.<genexpr>X  s      CHq'

Hs   !
!N)r8   r9   s   &r   next_words_segment&transcribe.<locals>.next_words_segmentW  s     CH CTJJr   :r~   NN)r   r0   r   r   )r*   rF   r   mel
num_framesr\   r]   last_speech_timestampr   r/   r   r0   r   [z --> z] r   r   )r   idg      ?)r   r*   rv   r7   )@r   rA   float16float32r<   rH   r   dimsri   r
   shaper	   r   r   r   sysgetdefaultencodingis_multilingualprintr   astypedetect_languagemaxr   titler   r|   r   r@   splitr"   r   r   appendminlistzipwarningswarnn_audio_ctxrn   stripextendtqdmrc   re   r   r   r   timestamp_beginr   wherelogical_anditemnonzeror   r:   ranger'   	enumeraterT   updater,   ro   )Xrb   rR   rS   rT   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r`   r   r?   r   content_framescontent_duration	make_safemel_segment_probsrv   rz   tsseek_points
seek_clipsr   clip_idxinput_stridetime_precision
all_tokensall_segmentsprompt_reset_sinceinitial_prompt_tokensr   pbarr   seek_clip_startseek_clip_endtime_offsetwindow_end_timesegment_sizesegment_durationr   r   should_skipprevious_seekcurrent_segmentsr   r   timestamp_tokenssingle_timestamp_endingconsecutiveslices
last_slicecurrent_slicesliced_tokensstart_timestamp_posend_timestamp_poslast_timestamp_posr   
timestampslast_word_end	thresholdremaining_durationfirst_segmentgaphal_last_endsir   next_segmenthal_next_startsilence_beforesilence_afterr   r0   r   lineir   rF   r   r   rq   r   r   sX   &$$dddd$$$$$$$l                                                                   @@@@@@r   r{   r{   >   s   h ),,VT::BJJ

E!!/9E eEJJ,=,=y
QCYYr]X-N^j8;FG002g%I $I*d+3$$$)-N:&Q &c8"=DDUKK,,[9HAu),U		)BN:&"))N:4N*O*U*U*W)XY #:.H""6<8D))	I /3''?N!6!6s!;TV!V
!V"E"I!V 	 
 GVVoeB):$:;oKV
;11
;!q >*nk"o>B(,SS1A;tCT-U(VJ@K4;.RS& &P Hh"Duzz555Lz!K/  JL! ) 0 0~7K7K7M1M N/0 "
 
$ 
8WE5I
 
	 #.8*O]&#D:$5$CD"'J(F(T"U"nt3]T5I  "$)<=#/*#<{#J )+xbIPPQVW+56H6I+Jx()=k)J&--0&2"("7"7:M"MK)5"..1BB ',"( ! $#% 
!D DK $*Y-F-F#F *:23*?*F*F*HM +'
 !hhNN#3CR#8:J2:NO q {#a'(//1F.c&k2!"J)/(.z-(H)!,113i6O6OO , *"-224y7P7PP * )//'&1"5"F'G$/2Cn2T$T'4'- &3
# *0& /, #:>2779I<U<UU +  2\ AA/H!'(8(@(@(B1(E!FJJ!+&rN//1Y5N5NN 'rN//1I4M4MM + $6#F$++#"- +h 6#)#)	 L(D"?'!1#"+'#/-A,?.C	 3(01A(B(49T#(9J)J#KD 7B$C	6,45E,FM - 9$1K$?5D}5T 2#5	#A+0AR1R+SD+8<+GD );;K(L(49K): : #0"8;"FC"Y'4uSCT=T7U'U ( (="',<(=">B&6r&:G#*7#3#3 (1'::/A$4R!VX$>0" $0#;5A'5J15Mg5VN5@CS5SN$+G$4|$Ci$O %L %L'.w'7)'C%L %L'.w'7+'E'K !/ %3WU^$Ci$O %N %N'9,'G%N %N'6'G#'M !.
 $2m+0(+K!OWW=M(N*;)<,&D (8'%.'H9'T/=<>$4RS$9$)+25>L? #?B %--=$>M$00=-#3#G,#EN#FO %)s
 "##4U#;"<EBSTWBXAYY[\`[abio. $4 #,,<"=JAw(GEN:"6?002b8*,,.)+-( #> ## +4,C4E++JAw q,G,+ !! (8'7G%,X%6%6E %6 '7 2V5G5G#5M),Z& C5EFy /9	
D j-B)C)EFG {

 WH
i
 
s   m/7m4n!Dn4B:n/B:n*Dn/AnAn%A9nAn0n-n2nnn&A2nBn/7n&m98nm?+n;An9nn	)r   g?g?rU   g?r   g      )#r   r   typingr   r   r   r   mlx.corecorerA   numpyrc   r   rb   r   r   r	   r
   r   r   r   decodingr   r   load_modelsr   timingr   r   r   r   r'   r:   r<   r{   rJ   r   r   <module>r%     s      / /      6 # ' /K"	 	a 8a #	a
 4Ra 47a *.a ,/a (,a %)a "a !/a  Ba 03a 8<a ar   