
    hJJj!                         d dl Z d dlZd dlZd dlZd dlZddlmZ ddlmZm	Z	 ddl
m
Z
 ddlmZ d Zd Zed	k(  r e        yy)
    N   )audio)	LANGUAGESTO_LANGUAGE_CODE)
transcribe)
get_writerc                  B   d } d }d }t        j                  t         j                        }|j                  ddd       |j                  d	d
t        d       |j                  dt        d d       |j                  ddt        dd       |j                  ddt        dg dd       |j                  d|dd       |j                  dt        dddgd        |j                  d!t        d t        t        j                               t        t        j                         D cg c]  }|j                          c}      z   d"       |j                  d#t        d$d%       |j                  d&| d'd(       |j                  d)t        d d*       |j                  d+t        d d,       |j                  d-t        d.d/       |j                  d0t        d d1       |j                  d2|dd3       |j                  d4|dd5       |j                  d6|d7d8       |j                  d9|d:d;       |j                  d<|d=d>       |j                  d?|d@dA       |j                  dBt        dCdD       |j                  dEt        dFdG       |j                  dH|d@dI       |j                  dJt        d dK       |j                  dLt        d dM       |j                  dNt        d dO       |j                  dP|dQR       |j                  dSt        dTdU       |S c c}w )VNc                 &    | dk(  rd S t        |       S NNone)intstrings    Y/Users/ahmed/devFolder/claude-voice/.venv/lib/python3.12/site-packages/mlx_whisper/cli.pyoptional_intz"build_parser.<locals>.optional_int   s    't8S[8    c                 &    | dk(  rd S t        |       S r   )floatr   s    r   optional_floatz$build_parser.<locals>.optional_float   s    't:U6]:r   c                 n    ddd}| |v r||    S t        dt        |j                                d|        )NTF)TrueFalsezExpected one of z, got )
ValueErrorsetkeys)r   str2vals     r   str2boolzbuild_parser.<locals>.str2bool   sC    %0W6?"/GLLN0C/DF6(STTr   )formatter_classr   +zAudio file(s) to transcribe)nargshelpz--modelzmlx-community/whisper-tinyz(The model directory or hugging face repo)defaulttyper!   z--output-namezTThe name of transcription/translation output files before --output-format extensions)r#   r"   r!   z--output-dirz-o.zDirectory to save the outputsz--output-formatz-ftxt)r%   vttsrttsvjsonallzFormat of the output file)r#   r"   choicesr!   z	--verboseTz0Whether to print out progress and debug messagesz--taskr   	translatezMPerform speech recognition ('transcribe') or speech translation ('translate')z
--languagez9Language spoken in the audio, specify None to auto-detectz--temperaturer   zTemperature for samplingz	--best-of   z<Number of candidates when sampling with non-zero temperaturez
--patiencezOptional patience value to use in beam decoding, as in https://arxiv.org/abs/2204.05424, the default (1.0) is equivalent to conventional beam searchz--length-penaltyzOptional token length penalty coefficient (alpha) as in https://arxiv.org/abs/1609.08144, uses simple length normalization by default.z--suppress-tokensz-1zComma-separated list of token ids to suppress during sampling; '-1' will suppress most special characters except common punctuationsz--initial-promptz:Optional text to provide as a prompt for the first window.z--condition-on-previous-textzIf True, provide the previous output of the model 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 loopz--fp16z$Whether to perform inference in fp16z--compression-ratio-thresholdg333333@zUif the gzip compression ratio is higher than this value, treat the decoding as failedz--logprob-thresholdg      zUIf the average log probability is lower than this value, treat the decoding as failedz--no-speech-thresholdg333333?zIf the probability of the token is higher than this value the decoding has failed due to `logprob_threshold`, consider the segment as silencez--word-timestampsFzBExtract word-level timestamps and refine the results based on themz--prepend-punctuationsu   "'“¿([{-zNIf word-timestamps is True, merge these punctuation symbols with the next wordz--append-punctuationsu   "'.。,，!！?？:：”)]}、zRIf word_timestamps is True, merge these punctuation symbols with the previous wordz--highlight-wordszT(requires --word_timestamps True) underline each word as it is spoken in srt and vttz--max-line-widthze(requires --word_timestamps True) the maximum number of characters in a line before breaking the linez--max-line-countzJ(requires --word_timestamps True) the maximum number of lines in a segmentz--max-words-per-linezk(requires --word_timestamps True, no effect with --max_line_width) the maximum number of words in a segmentz!--hallucination-silence-thresholdz(requires --word_timestamps True) skip silent periods longer than this threshold (in seconds) when a possible hallucination is detected)r#   r!   z--clip-timestamps0zComma-separated list start,end,start,end,... timestamps (in seconds) of clips to process, where the last end timestamp defaults to the end of the file)argparseArgumentParserArgumentDefaultsHelpFormatteradd_argumentstrsortedr   r   r   titler   r   )r   r   r   parserks        r   build_parserr8      s+   9;U $$ >>F s1NO
,7	   )   ,   ;(   ?	   {+\   y~~'(
%5%:%:%<=%<!'')%<=
>?H   eQ5O   K	    d	    V	    T	   I	   & _	   3	   'd	   d	    ]	   Q	    ]	   2a	   c	   t	   Y	   z	   + W  
  f	   Mo >s   %Lc                  8   t               } t        | j                               }|d   du rt        d|        |j	                  d      }|j	                  d      }|j	                  d      }|j	                  d      }t        j                  |d       t        ||      }g d	}|D ci c]  }||j	                  |       }	}|d
   sB|	j                         D ]/  \  }
}|s	|
j                  dd      }| j                  d| d       1 |	d   r|	d   st        j                  d       |	d   r|	d   rt        j                  d       |j	                  d      D ]`  }|dk(  rt        j                  d      }|xs d}n#|xs t        j                   |      j"                  }	 t%        |fd|i|} |||fi |	 b y c c}w # t&        $ rN}t)        j*                          t        d| dt-        |      j.                   dt1        |              Y d }~d }~ww xY w)NverboseTzArgs: model
output_diroutput_formatoutput_name)exist_ok)highlight_wordsmax_line_countmax_line_widthmax_words_per_lineword_timestamps_-z--z  requires --word-timestamps TruerA   rB   z7--max-line-count has no effect without --max-line-widthrC   z8--max-words-per-line has no effect with --max-line-widthr   )
from_stdincontentpath_or_hf_repoz	Skipping z due to z: )r8   vars
parse_argsprintpoposmakedirsr   itemsreplaceerrorwarningswarnr   
load_audiopathlibPathstemr   	Exception	traceback	print_excr#   __name__r3   )r6   argsrI   r<   r=   r>   writerword_optionsargwriter_argsr7   vargop	audio_objresultes                   r   mainrg      s   ^F!!#$DI$tfo88G,Ohh|,J/2Mxx.KKK
T*z2FL 2>>#3%K>!"%%'DAq		#s+r%(HIJ ( #$[9I-JOP'([9I-JPQXXg&	((D9I%2K%Ei)@)E)EK		O / F
 6;6+6 ' ?4  	O!Ii[a1A1A0B"SVHMNN	Os   (F="G	HAHH__main__)r/   rN   rV   rZ   rS    r   	tokenizerr   r   r   writersr   r8   rg   r\    r   r   <module>rm      sD     	     2 " {|/Od zF r   