
    ,h                     F    d dl Zd dlZddlmZmZ ddlmZ  G d de      Zy)    N   )UnknownMethod
ShellError   )ShellParserc                       e Zd ZdZddZd Zy)ParseraV  
    Extract text (i.e. speech) from an audio file, using SpeechRecognition.

    Since SpeechRecognition expects a .wav file, with 1 channel,
    the audio file has to be converted, via sox, if not compliant

    Note: for testing, use -
    http://www2.research.att.com/~ttsweb/tts/demo.php,
    with Rich (US English) for best results
    c                 z   d}t         j                  j                  |      \  }}|dk7  r=| j                  |      }	  | j                  ||fi |}t        j
                  |       |S t        j                         }t        j                  |      5 }	|j                  |	      }
d d d        	 |dk(  s|dk(  r|j                  
      }n"|dk(  r|j                  
      }nt        |      |dz  }|S # t        j
                  |       w xY w# 1 sw Y   ixY w# t        $ r d}Y :t        j                  $ r d}Y Pw xY w)N z.wavgooglesphinx
)ospathsplitextconvert_to_wavextractremovesr
RecognizerWavFilerecordrecognize_googlerecognize_sphinxr   LookupErrorUnknownValueError)selffilenamemethodkwargsspeechbaseexttemp_filenamersourceaudios              X/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/textract/parsers/audio.pyr   zParser.extract   s3    GG$$X.	c&= //9M)%mVFvF		-(, ) AH% )()
X%2//6Fx'//6F'// dNF- 		-() )  '' s/   C0 D
+>D 0D
DD:#D:9D:c                 r    dj                  | j                               }| j                  dddd||g       |S )z
        Uses sox cmdline tool, to convert audio file to .wav

        Note: for testing, use -
        http://www.text2speech.org/,
        with American Male 2 for best results
        z{0}.wavsoxz-Gz-c1)formatr$   run)r   r   r$   s      r(   r   zParser.convert_to_wav6   s<     "((););)=>%tS(MBC    N)r   )__name__
__module____qualname____doc__r   r    r.   r(   r	   r	      s    	 D
r.   r	   )	speech_recognitionr   r   
exceptionsr   r   utilsr   r	   r3   r.   r(   <module>r7      s     	 2 8[ 8r.   