【发布时间】:2021-03-09 15:01:12
【问题描述】:
'这是我的代码:'
import speech_recognition as sr
# get audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Please say response:")
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
resp=r.recognize_google(audio)
try:
print("You said " + resp)
except sr.UnknownValueError:
print("Could not understand audio")
except sr.RequestError as e:
print("Could not request results; {0}".format(e))
'这是错误信息:'
runfile('C:/Users/Owner/speechrecognition.py', wdir='C:/Users/Owner') Traceback(最近一次调用最后一次):
文件“”,第 1 行,在 runfile('C:/Users/Owner/speechrecognition.py', wdir='C:/Users/Owner')
文件“C:\Users\Owner\anaconda3\envs\py27\lib\site-packages\spyder_kernels\customize\spydercustomize.py”,第 827 行,在运行文件中 execfile(文件名,命名空间)
文件“C:\Users\Owner\anaconda3\envs\py27\lib\site-packages\spyder_kernels\customize\spydercustomize.py”,第 95 行,在 execfile exec(compile(scripttext, filename, 'exec'), glob, loc)
文件“C:/Users/Owner/speechrecognition.py”,第 11 行,在 以 sr.Microphone() 作为来源:
文件“C:\Users\Owner\anaconda3\envs\py27\lib\site-packages\speech_recognition_init_.py”,第 141 行,输入 input=True, #stream 是输入流
文件“C:\Users\Owner\anaconda3\envs\py27\lib\site-packages\pyaudio.py”,第 750 行,打开 stream = Stream(self, *args, **kwargs)
init 中的文件“C:\Users\Owner\anaconda3\envs\py27\lib\site-packages\pyaudio.py”,第 441 行 self._stream = pa.open(**arguments)
IOError: [Errno -9999] 意外主机错误
【问题讨论】:
-
您是否允许 python 访问您的麦克风?新的 Windows 版本在
Settings > Privacy > Microphone中内置了访问控制。 Check this。可能是骗子here。 -
是的,我前一天运行了相同的代码,它可以很好地访问我的麦克风,但是当我第二天运行它时,我开始使用 PyAudio 收到此错误
标签: python anaconda speech-recognition pyaudio