所以我在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
额外信息:在运行代码之前花了几秒钟才崩溃并产生错误。
有谁知道可能导致此错误的原因以及我如何解决它?
谢谢, 汤姆
答案 0 :(得分:0)
如果这不起作用,请尝试将您的 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