o
    i                     @  s   d dl mZ d dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlmZ er.d dlmZ G dd deZedddZedddZdddddZdS )    )annotationsN)Path)TYPE_CHECKINGLiteral	TypedDictUnioncastoverload)
SetupError)	AudioDatac                   @  s   e Zd ZU ded< dS )VoskResponsestrtextN)__name__
__module____qualname____annotations__ r   r   V/home/kuhnn/.local/lib/python3.10/site-packages/speech_recognition/recognizers/vosk.pyr      s   
 r   
audio_datar   verboseLiteral[False]returnr   c                C     d S Nr   _recognizerr   r   r   r   r   	recognize      r   Literal[True]c                C  r   r   r   r   r   r   r   r      r   F)r   boolUnion[str, VoskResponse]c          
      C  s   ddl m}m} ttjjd d }| std| dd}||t||}|	|j
|dd	 | }ttt|}	|rC|	S |	d
 S )aO  
    Perform speech recognition on ``audio_data`` using Vosk.

    Requires the Vosk model to be downloaded and unpacked in a folder named 'model' (``$PWD/model``).

    If ``verbose`` is ``False`` (default), only the recognized text is returned.
    If ``verbose`` is ``True``, the parsed result dictionary from Vosk is returned.
    r   )KaldiRecognizerModelmodelsvoskzVosk model not found at z?. Please download the model using `sprc download vosk` command.i>     )convert_rateconvert_widthr   )r%   r"   r#   r   __file__parentexistsr
   r   AcceptWaveformget_raw_dataFinalResultr   r   jsonloads)
r   r   r   r"   r#   vosk_model_pathSAMPLE_RATErecfinal_recognitionresultr   r   r   r      s    
)r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r    r   r!   )
__future__r   r/   pathlibr   typingr   r   r   r   r   r	   speech_recognition.exceptionsr
   speech_recognition.audior   r   r   r   r   r   r   <module>   s     