
    1h                        S SK Jr  S SKJrJr  S SKJr  S SKJr  S SK	J
r
Jr  \(       a  S SKJrJrJr  S SKJr   " S S	\S
S9r " S S\S
S9r      SS jr S       SS jjrg)    )annotations)TYPE_CHECKING	TypedDict)URLError)	AudioData)RequestErrorUnknownValueError)RecognitionConfigRecognizeResponseSpeechContext)Requiredc                  L    \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   S\S
'   Srg)GoogleCloudRecognizerParameters   a  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_enhanced N__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r       c/var/www/auris/envauris/lib/python3.13/site-packages/speech_recognition/recognizers/google_cloud.pyr   r      s'    " ! N Jr!   r   F)totalc                  `    \ rS rSr% SrS\S'   S\S'   S\S'   S	\S
'   S\S'   S\S'   S\S'   Srg)GoogleCloudSpeechV1Parameters.   zSpeech-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   r   Nr   r   r!   r"   r%   r%   .   s2    
 87$$  ((""Jr!   r%   c                B   SSK Jn  UR                  R                  R                  U R
                  UR                  SS5      S.nUR                  SS 5      =n(       a  UR                  US9/US'   UR                  S	S
5      (       a  SUS'   UR                  " S0 X1-  D6$ )Nr   speechr   zen-US)r'   r(   r   r   )phrasesr)   r   FTr*   r   )google.cloudr-   r
   AudioEncodingFLACsample_ratepopr   )
audio_datarecognizer_paramsr-   
parametersr   s        r"   _build_configr7   =   s     $ ,,::??'33*..H1J
 .112EtLLL  ): ;)

$% Z//15
-.##Gz'EGGr!   Nc           	         SSK Jn  SSKJn  U(       a  UR                  R                  U5      OUR                  5       nUR                  SUR                  s=::  a  S::  a  O  OSO[        S[        UR                  S5      5      SS	9nUR                  US
9n[        XR                  5       5      n	 UR                  XS9n
UR'                  S5      (       a  U
$ [)        U
R*                  5      S:X  a
  [-        5       eSR/                  S U
R*                   5       5      nU$ ! [         a    [        S5      ef = f! U a  n[        U5      eSnAf[          a)  n[        SR#                  UR$                  5      5      eSnAff = f)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  p   #    U  H,  nUR                   S    R                  R                  5       v   M.     g7f)r   N)alternatives
transcriptstrip).0results     r"   	<genexpr>recognize.<locals>.<genexpr>   s4      &F 	A))//11&s   46)google.api_core.exceptionsr9   r/   r-   ImportErrorr   SpeechClientfrom_service_account_jsonget_flac_datar2   maxminRecognitionAudior7   copy	recognizer   formatreasongetlenresultsr	   join)
recognizerr4   credentials_json_pathkwargsr9   r-   client	flac_datar?   r>   responseerC   s                r"   rR   rR   Q   s    
A' ! 	556KL  "  (( z--66 T3z55u=> ) I ##I#6E:{{}5F
##6#? zz*
8!!! && J U  
f
 	

4  1o 
077A
 	

s/   D! 3D: !D7:F EF$E<<F)r4   r   r5   r   returnr
   )N)r4   r   rZ   z
str | Noner[   r   r`   zstr | RecognizeResponse)
__future__r   typingr   r   urllib.errorr   speech_recognition.audior   speech_recognition.exceptionsr   r	   google.cloud.speechr
   r   r   typing_extensionsr   r   r%   r7   rR   r   r!   r"   <module>rh      s    " + ! . I 
 +iu 8IU HH.MHH. )-== &= .	=
 =r!   