首页 > 解决方案 > 在 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] 意外主机错误

标签: pythonanacondaspeech-recognitionpyaudio

解决方案


我自己使用 pyaudio 时遇到了很多问题,为我解决的问题是将其粘贴到

if (not os.environ.get('PYTHONHTTPSVERIFY', '') and getattr(ssl, '_create_unverified_context', None)): 

推荐阅读