
    τi                        d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	m
Z
 erd dlZd dlZd dlmZ d dlmZ  G d d	ed
      Z G d ded
      Z G d de      Z G d d      Z	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZy)    )annotations)TYPE_CHECKINGLiteral	TypedDict)	AudioData)TranscribeOutputBaseWhisperCompatibleRecognizerN)Unpack)Whisperc                  ,    e Zd ZU ded<   ded<   ded<   y)LoadModelOptionalParameterszstr | torch.devicedevicestrdownload_rootbool	in_memoryN__name__
__module____qualname____annotations__     ~/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/speech_recognition/recognizers/whisper_local/whisper.pyr   r      s    Or   r   F)totalc                  :    e Zd ZU dZded<   ded<   ded<   ded	<   y
)TranscribeOptionalParametersz<Transcribe optional parameters & DecodingOptions parameters.zfloat | tuple[float, ...]temperaturez"Literal['transcribe', 'translate']taskr   languager   fp16N)r   r   r   __doc__r   r   r   r   r   r      s    F +* -,M
Jr   r   c                  r    e Zd ZU ded<   ded<   ded<   ded<   ded<   d	ed
<   ded<   ded<   ded<   ded<   y)Segmentintidseekfloatstartendr   textz	list[int]tokensr   avg_logprobcompression_rationo_speech_probNr   r   r   r   r$   r$   &   s9    G
IL	J
Ir   r$   c                  $    e Zd ZddZ	 	 	 	 ddZy)TranscribableAdapterc                    || _         y )N)model)selfr3   s     r   __init__zTranscribableAdapter.__init__4   s	    
r   c                    d|vr!dd l }|j                  j                         |d<    | j                  j                  |fi |S )Nr!   r   )torchcudais_availabler3   
transcribe)r4   audio_arraykwargsr7   s       r   r:   zTranscribableAdapter.transcribe7   sA     "ZZ446F6N$tzz$$[;F;;r   N)r3   r   returnNone)r;   z
np.ndarrayr=   zTranscribeOutputBase[Segment])r   r   r   r5   r:   r   r   r   r1   r1   3   s    <%<	&<r   r1   c                    ddl } |j                  |fi |xs i }t        t        |            } |j                  |fd|i|S )a  Performs speech recognition on ``audio_data`` (an ``AudioData`` instance), using Whisper.

    Pick ``model`` from output of :command:`python -c 'import whisper; print(whisper.available_models())'`.
    See also https://github.com/openai/whisper?tab=readme-ov-file#available-models-and-languages.

    If ``show_dict`` is true, returns the full dict response from Whisper, including the detected language. Otherwise returns only the transcription.

    You can specify:

        * ``language``: recognition language, an uncapitalized full language name like "english" or "chinese". See the full language list at https://github.com/openai/whisper/blob/main/whisper/tokenizer.py

            * If not set, Whisper will automatically detect the language.

        * ``task``

            * If you want transcribe + **translate** to english, set ``task="translate"``.

    Other values are passed directly to whisper. See https://github.com/openai/whisper/blob/main/whisper/transcribe.py for all options.
    r   N	show_dict)whisper
load_modelr	   r1   	recognize)	
recognizer
audio_datar3   r@   load_optionstranscribe_optionsrA   whisper_modelwhisper_recognizers	            r   rC   rC   B   sa    8 &G&&uC0BCM4]+ ('''+= r   )baseFN)rE   r   r3   r   r@   r   rF   z"LoadModelOptionalParameters | NonerG   z$Unpack[TranscribeOptionalParameters]r=   z#str | TranscribeOutputBase[Segment])
__future__r   typingr   r   r   speech_recognition.audior   1speech_recognition.recognizers.whisper_local.baser   r	   numpynpr7   typing_extensionsr
   rA   r   r   r   r$   r1   rC   r   r   r   <module>rR      s    " 4 4 . ()5 
9E 

i 
< <$ 7;$$ $ 	$
 5$ ?$ )$r   