Python 语音识别'Child Process error'



所以我正在尝试python中的语音识别模块(https://pypi.python.org/pypi/SpeechRecognition/),并尝试以下代码:

import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:                # use the default microphone as the audio source
    audio = r.listen(source)                   # listen for the first phrase and extract it into audio data
try:
    print("You said " + r.recognize(audio))    # recognize speech using Google Speech Recognition
except LookupError:                            # speech is unintelligible
    print("Could not understand audio")

当它运行时,我收到以下错误:

Thomass-MBP:Turret thomashitch$ python Speech.py 
Traceback (most recent call last):
  File "Speech.py", line 4, in <module>
    audio = r.listen(source)                   # listen for the first phrase and extract it into audio data
  File "/Library/Python/2.7/site-packages/SpeechRecognition-1.1.4-py2.7.egg/speech_recognition/__init__.py", line 208, in listen
    return AudioData(source.RATE, self.samples_to_flac(source, frame_data))
  File "/Library/Python/2.7/site-packages/SpeechRecognition-1.1.4-py2.7.egg/speech_recognition/__init__.py", line 129, in samples_to_flac
    raise ChildProcessError("FLAC conversion utility not available - consider installing the FLAC command line application using brew install flac")
NameError: global name 'ChildProcessError' is not defined

额外信息:运行代码后需要几秒钟才能崩溃并产生错误。

有谁知道可能导致此错误的原因以及我如何解决它?

谢谢汤姆

如果这不起作用,请尝试将您的 python 版本升级到 3.6.6 或 3.8.4 它正在这些版本的 python 中工作

import speech_recognition as sr
        
        def speechrecognizer(): 
            try:
                r = sr.Recognizer()
                with sr.Microphone() as audio:
                    print('Listening...')
                    voice = r.listen(audio)
                    print("Thinking...")
                    query = r.recognize_google(voice,language='en-in')
                    str(query)
                    print(f"{query}") 
        
            except:
              pass
            return query

相关内容

  • 没有找到相关文章

最新更新