
    i                        d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
mZ eZeZeZeeeef   ZeZeZeeef   Z	 	 	 	 d	 	 	 	 	 	 	 	 	 d	dZy)
    )annotationsN)Sequence)PortableNamedTemporaryFile)	AudioData)RequestErrorUnknownValueErrorc           	     	   |t        d |D              sJ d       	 ddlm}m}m} t        |t              rt        j                  j                  t        j                  j                  t        j                  j                  t        j                  j                  t                          d|      }	t        j                  j                  |	      st        dj                  |	            t        j                  j                  |	d	      }
t        j                  j                  |	d
      }t        j                  j                  |	d      }n|\  }
}}t        j                  j                  |
      st        dj                  |
            t        j                  j!                  |      st        dj                  |            t        j                  j!                  |      st        dj                  |            |j#                         }|j%                  d|
       |j%                  d|       |j%                  d|       |j%                  dt        j&                         |j)                  |      }|j+                  dd      }|kt-        d      5 }|j/                  d |D               |j1                          |j3                  d|j4                         |j7                  d       ddd       n~|{t        j                  j9                  |      st;        dj                  |            t        j                  j=                  t        j                  j                  |            }t        j                  j?                  t        j                  jA                  |            d   }dj                  ||      }t        j                  j9                  |      s[ ||      }|jC                  dj                  |            }|jE                  ||jG                         d      }|jI                  |       n |||jG                         d      }|jK                  ||       |jM                  |       |jO                          |jQ                  |dd       |jS                          |r|S |jU                         }||jV                  S tY               # t        $ r t        d      w xY w# 1 sw Y   xY w)aP  
    Performs speech recognition on ``audio_data`` (an ``AudioData`` instance), using CMU Sphinx.

    The recognition language is determined by ``language``, an RFC5646 language tag like ``"en-US"`` or ``"en-GB"``, defaulting to US English. Out of the box, only ``en-US`` is supported. See `Notes on using `PocketSphinx <https://github.com/Uberi/speech_recognition/blob/master/reference/pocketsphinx.rst>`__ for information about installing other languages. This document is also included under ``reference/pocketsphinx.rst``. The ``language`` parameter can also be a tuple of filesystem paths, of the form ``(acoustic_parameters_directory, language_model_file, phoneme_dictionary_file)`` - this allows you to load arbitrary Sphinx models.

    If specified, the keywords to search for are determined by ``keyword_entries``, an iterable of tuples of the form ``(keyword, sensitivity)``, where ``keyword`` is a phrase, and ``sensitivity`` is how sensitive to this phrase the recognizer should be, on a scale of 0 (very insensitive, more false negatives) to 1 (very sensitive, more false positives) inclusive. If not specified or ``None``, no keywords are used and Sphinx will simply transcribe whatever words it recognizes. Specifying ``keyword_entries`` is more accurate than just looking for those same keywords in non-keyword-based transcriptions, because Sphinx knows specifically what sounds to look for.

    Sphinx can also handle FSG or JSGF grammars. The parameter ``grammar`` expects a path to the grammar file. Note that if a JSGF grammar is passed, an FSG grammar will be created at the same location to speed up execution in the next run. If ``keyword_entries`` are passed, content of ``grammar`` will be ignored.

    Returns the most likely transcription if ``show_all`` is false (the default). Otherwise, returns the Sphinx ``pocketsphinx.pocketsphinx.Decoder`` object resulting from the recognition.

    Raises a ``speech_recognition.UnknownValueError`` exception if the speech is unintelligible. Raises a ``speech_recognition.RequestError`` exception if there are any issues with the Sphinx installation.
    Nc              3     K   | ]9  \  }}t        |t        d       t        d       f      xr d|cxk  xr dk  nc  ; yw) r      N)
isinstancetype.0keywordsensitivitys      i/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/speech_recognition/recognizers/pocketsphinx.py	<genexpr>zrecognize.<locals>.<genexpr>*   sN       *\  tHsz  }H*WtBxc>S*T*nYZ^iYnmnYn*n  *\s   ?Az^``keyword_entries`` must be ``None`` or a list of pairs of strings and numbers between 0 and 1r   )FsgModelJsgfpocketsphinxzJmissing PocketSphinx module: ensure that PocketSphinx is set up correctly.zpocketsphinx-dataz2missing PocketSphinx language data directory: "{}"zacoustic-modelzlanguage-model.lm.binzpronounciation-dictionary.dictz>missing PocketSphinx language model parameters directory: "{}"z.missing PocketSphinx language model file: "{}"z2missing PocketSphinx phoneme dictionary file: "{}"z-hmmz-lmz-dictz-logfni>     )convert_rateconvert_widthwc              3  R   K   | ]  \  }}d j                  |d|z  dz
         ! yw)z
{} /1e{}/
d   n   N)formatr   s      r   r   zrecognize.<locals>.<genexpr>P   s.     |ThT[]h--gs[7H37NO|s   %'keywordszGrammar '{0}' does not exist.z{0}/{1}.fsgz{0}.{0}g      @FT)-allr   r   r   ImportErrorr   r   strospathjoindirnamerealpath__file__isdirr   isfileConfig
set_stringdevnullDecoderget_raw_datar   
writelinesflushadd_kwsnameactivate_searchexists
ValueErrorabspathsplitextbasenameget_rule	build_fsgget_logmath	writefileset_fsg
set_search	start_uttprocess_rawend_utthyphypstrr   )
recognizer
audio_datalanguagekeyword_entriesgrammarshow_allr   r   r   language_directoryacoustic_parameters_directorylanguage_model_filephoneme_dictionary_fileconfigdecoderraw_datafgrammar_pathgrammar_namefsg_pathjsgfrulefsg
hypothesiss                           r   	recognizer[      s   , "c  *\  L[  *\  '\  ~  ^~  ~  \i== (C WW\\"''//"''//"''JZJZ[cJd:e*fh{  ~F  Gww}}/0U\\]opqq(*5GIY(Z% ggll+=?VW"$'',,/ACc"dV^S%':<S77==67]dd  fC  D  E  	E77>>-.MTTUhijj77>>12QXXYpqrr   "F
f;<
e01
g67
h

+""6*G &&E&KH "', 	0LL|l{||GGI OOJ/##J/	0 	0 
	ww~~g&<CCGLMMwwrwww'?@ww''(8(8(AB1E ''lCww~~h'=D==!1!1,!?@D..w':':'<cBCMM(#8W%8%8%:C@Cc*<(%.OO Jj&7&77

C  ighhi@	0 	0s   
S AS+S(+S4)zen-USNNF)
rG   r   rH   zstr | SphinxDataFilePathsrI   zSequence[KeywordEntry] | NonerJ   z
str | NonerK   bool)
__future__r   r$   collections.abcr   speech_recognitionr   speech_recognition.audior   speech_recognition.exceptionsr   r   r#   AcousticParametersDirectoryPathLanguageModelFilePathPhonemeDictionaryFilePathtupleSphinxDataFilePathsKeywordfloatSensitivityKeywordEntryr[        r   <module>rm      s    " 	 $ 9 . I"%   ;=RTmmn 
Wk)* +259[[ ([ 3	[
 [ [rl   