o
    Ö­jÛ  ã                   @  sÄ   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r4d dlZd dlZd dlmZ d dlmZ G dd	„ d	ed
d�ZG dd„ ded
d�ZG dd„ deƒZG dd„ dƒZ		
	d!d"dd „ZdS )#é    )Úannotations)ÚTYPE_CHECKINGÚLiteralÚ	TypedDict)Ú	AudioData)ÚTranscribeOutputBaseÚWhisperCompatibleRecognizerN)ÚUnpack)ÚWhisperc                   @  s&   e Zd ZU ded< ded< ded< dS )ÚLoadModelOptionalParameterszstr | torch.deviceÚdeviceÚstrÚdownload_rootÚboolÚ	in_memoryN©Ú__name__Ú
__module__Ú__qualname__Ú__annotations__© r   r   úq/var/www/html/CropPilot/venv/lib/python3.10/site-packages/speech_recognition/recognizers/whisper_local/whisper.pyr      s   
 r   F)Útotalc                   @  s2   e Zd ZU dZded< ded< ded< ded	< d
S )Ú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   
 r   c                   @  s^   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< dS )ÚSegmentÚintÚidÚseekÚfloatÚstartÚendr   Útextz	list[int]Útokensr   Úavg_logprobÚcompression_ratioÚno_speech_probNr   r   r   r   r   r   &   s   
 r   c                   @  s    e Zd Zddd„Zdd
d„ZdS )ÚTranscribableAdapterÚmodelr
   ÚreturnÚNonec                 C  s
   || _ d S )N)r,   )Úselfr,   r   r   r   Ú__init__4   s   
zTranscribableAdapter.__init__Úaudio_arrayú
np.ndarrayúTranscribeOutputBase[Segment]c                 K  s2   d|vrdd l }|j ¡ |d< | jj|fi |¤ŽS )Nr   r   )ÚtorchÚcudaÚis_availabler,   Ú
transcribe)r/   r1   Úkwargsr4   r   r   r   r7   7   s   zTranscribableAdapter.transcribeN)r,   r
   r-   r.   )r1   r2   r-   r3   )r   r   r   r0   r7   r   r   r   r   r+   3   s    
r+   ÚbaseÚ
audio_datar   r,   r   Ú	show_dictr   Úload_optionsú"LoadModelOptionalParameters | NoneÚtranscribe_optionsú$Unpack[TranscribeOptionalParameters]r-   ú#str | TranscribeOutputBase[Segment]c           	      K  s@   ddl }|j|fi |p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   Nr;   )ÚwhisperÚ
load_modelr   r+   Ú	recognize)	Ú
recognizerr:   r,   r;   r<   r>   rA   Úwhisper_modelÚwhisper_recognizerr   r   r   rC   B   s   ÿÿÿÿrC   )r9   FN)r:   r   r,   r   r;   r   r<   r=   r>   r?   r-   r@   )Ú
__future__r   Útypingr   r   r   Úspeech_recognition.audior   Ú1speech_recognition.recognizers.whisper_local.baser   r   ÚnumpyÚnpr4   Útyping_extensionsr	   rA   r
   r   r   r   r+   rC   r   r   r   r   Ú<module>   s"    û