python - 在 Anaconda 中使用 PyAudio 和 SpeechRecognition python 2 时出错
问题描述
'这是我的代码:'
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,位置)
文件“C:/Users/Owner/speechrecognition.py”,第 11 行,以 sr.Microphone() 作为源:
文件“C:\Users\Owner\anaconda3\envs\py27\lib\site-packages\speech_recognition_init _.py ”,第141行,输入 输入=True,#stream是输入流
文件“C:\Users\Owner\anaconda3\envs\py27\lib\site-packages\pyaudio.py”,第 750 行,打开流 = Stream(self, *args, **kwargs)
文件“C:\Users\Owner\anaconda3\envs\py27\lib\site-packages\pyaudio.py”,第 441 行,在init self._stream = pa.open(**arguments)
IOError:[Errno -9999] 意外主机错误
解决方案
我自己使用 pyaudio 时遇到了很多问题,为我解决的问题是将其粘贴到
if (not os.environ.get('PYTHONHTTPSVERIFY', '') and getattr(ssl, '_create_unverified_context', None)):
推荐阅读
- forms - xyz表格;在第一列上使用 [halfWidth] 时如何释放“行”的第二个“列”
- css - “溢出:自动”不会阻止宽 div 破坏表格布局
- python - 防止在加载、连接和重新保存 CSV 文件时更改浮点值
- c++ - 为什么我的输出没有以正确的值打印?
- r - R:提取数据集的语法相似条目
- arrays - 如何解决这个任务?在字符串中查找子字符串。C语言
- grafana - 限制对分配的命名空间的 Grafana 仪表板访问
- amazon-web-services - AWS RDS - 如何将快照设为私有
- javascript - 有没有办法在本地主机上实时更新/重新加载我的 php 页面?
- c++ - 在模板之外定义函数模板类