
    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	 d dl
mZmZ erd dlmZmZmZ d dlmZmZ  G d d	ed
      Z G d ded
      Z	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 ddZy)    )annotations)TYPE_CHECKING	TypedDictcast)URLError)	AudioData)RequestErrorUnknownValueError)RecognitionConfigRecognizeResponseSpeechContext)RequiredUnpackc                  D    e Zd ZU dZded<   ded<   ded<   ded<   ded	<   y
)GoogleCloudRecognizerParametersaC  Optional parameters.

    The recognition language is determined by ``language_code``, which is a BCP-47 language tag like ``"en-US"`` (US English). Default: ``"en-US"``.
    A list of supported language tags can be found in the `Speech-to-Text supported languages <https://cloud.google.com/speech/docs/languages>`__.

    If ``preferred_phrases`` is an iterable of phrase strings, those given phrases will be more likely to be recognized over similar-sounding alternatives.
    This is useful for things like keyword/command recognition or adding new phrases that aren't in Google's vocabulary.
    Note that the API imposes certain `restrictions on the list of phrase strings <https://cloud.google.com/speech/limits#content>`__.

    ``show_all``: See :py:func:`recognize`.

    ``model``: You can select the model to get best results. (See `RecognitionConfig's documentation <https://cloud.google.com/python/docs/reference/speech/latest/google.cloud.speech_v1.types.RecognitionConfig>`__ for detail)

    ``use_enhanced``: Set to true to use an enhanced model for speech recognition.
    z	list[str]preferred_phrasesboolshow_allstrlanguage_codemodeluse_enhancedN__name__
__module____qualname____doc____annotations__     i/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/speech_recognition/recognizers/google_cloud.pyr   r      s'    " ! N Jr    r   F)totalc                  X    e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   d
ed<   y)GoogleCloudSpeechV1ParameterszSpeech-to-Text V1 API's parameters.

    https://cloud.google.com/python/docs/reference/speech/latest/google.cloud.speech_v1.types.RecognitionConfig
    z)Required[RecognitionConfig.AudioEncoding]encodingzRequired[int]sample_rate_hertzzRequired[str]r   zlist[SpeechContext]speech_contextsr   enable_word_time_offsetsr   r   r   Nr   r   r    r!   r$   r$   .   s2    
 87$$  ((""Jr    r$   c                r   ddl m} t        |j                  j                  |j                  j                  j
                        | j                  |j                  dd      d}|j                  dd       x}r|j                  |      g|d<   |j                  d	d
      rd|d<    |j                  di ||z  S )Nr   speechr   zen-US)r%   r&   r   r   )phrasesr'   r   FTr(   r   )	google.cloudr+   r   r   AudioEncodingFLACsample_ratepopr   )
audio_datarecognizer_paramsr+   
parametersr   s        r!   _build_configr5   =   s     $ 11??AYAYAgAgAlAlm'33*..H1J
 .112EtLLL  ): ;)

$% Z/15
-.#6##Gz4E'EGGr    Nc           	        	 ddl m} ddlm} |r|j                  j                  |      n|j                         }|j                  d|j                  cxk  rdk  rn ndnt        dt        |j                  d            d	      }|j                  |
      }t        ||j                               }		 |j                  |	|      }
|j'                  d      r|
S t)        |
j*                        dk(  r
t-               dj/                  d |
j*                  D              }|S # t        $ r t        d      w xY w# |$ r}t        |      d}~wt         $ r)}t        dj#                  |j$                              d}~ww xY w)a  Performs speech recognition on ``audio_data`` (an ``AudioData`` instance), using the Google Cloud Speech-to-Text V1 API.

    This function requires a Google Cloud Platform account; see the `Set up Speech-to-Text <https://cloud.google.com/speech-to-text/docs/before-you-begin>`__ for details and instructions. Basically, create a project, enable billing for the project, enable the Google Cloud Speech API for the project.
    And create local authentication credentials for your user account. The result is a JSON file containing the API credentials. You can specify the JSON file by ``credentials_json_path``. If not specified, the library will try to automatically `find the default API credentials JSON file <https://developers.google.com/identity/protocols/application-default-credentials>`__.

    Returns the most likely transcription if ``show_all`` is False (the default). Otherwise, returns the raw API response as a JSON dictionary.
    For other parameters, see :py:class:`GoogleCloudRecognizerParameters`.

    Raises a ``speech_recognition.UnknownValueError`` exception if the speech is unintelligible. Raises a ``speech_recognition.RequestError`` exception if the speech recognition operation failed, if the credentials aren't valid, or if there is no Internet connection.
    r   )GoogleAPICallErrorr*   zXmissing google-cloud-speech module: ensure that google-cloud-speech is set up correctly.i@  i  N   )convert_rateconvert_width)content)configaudioz"recognition connection failed: {0}r    c              3  j   K   | ]+  }|j                   d    j                  j                          - yw)r   N)alternatives
transcriptstrip).0results     r!   	<genexpr>zrecognize.<locals>.<genexpr>   s2       	A))//1s   13)google.api_core.exceptionsr7   r-   r+   ImportErrorr	   SpeechClientfrom_service_account_jsonget_flac_datar0   maxminRecognitionAudior5   copy	recognizer   formatreasongetlenresultsr
   join)
recognizerr2   credentials_json_pathkwargsr7   r+   client	flac_datar=   r<   responseerA   s                r!   rO   rO   Q   s    
A' ! 	556KL  "  (( z--66 T3z55u=> ) I ##I#6E:v{{}5F
##6#? zz*
8!!! && J U  
f
 	

4  1o 
077A
 	

s/   D 3D7 D47E<<EE<$E77E<)r2   r   r3   r   returnr   )N)r2   r   rW   z
str | NonerX   z'Unpack[GoogleCloudRecognizerParameters]r]   zstr | RecognizeResponse)
__future__r   typingr   r   r   urllib.errorr   speech_recognition.audior   speech_recognition.exceptionsr	   r
   google.cloud.speechr   r   r   typing_extensionsr   r   r   r$   r5   rO   r   r    r!   <module>re      s    " 1 1 ! . I 
 3iu 8IU HH.MHH. )-== &= 6	=
 =r    