【问题标题】:Error using PyAudio and SpeechRecognition python 2 in Anaconda在 Anaconda 中使用 PyAudio 和 SpeechRecognition python 2 时出错
【发布时间】: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 收到此错误
  • 我希望其中之一对您有所帮助(12)。如果这不起作用,请告诉我们。

标签: python anaconda speech-recognition pyaudio


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-09
    • 2021-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多