Python: Portaudio Errno -9986 内部 PortAudio 错误

Python: Portaudio Errno -9986 Internal PortAudio error

我正在尝试 运行 一个简单的 python 语音识别程序。代码如下:

import speech_recognition as sr
import pyttsx3 


r = sr.Recognizer()  

engine = pyttsx3.init("nsss",True)

engine.say("hello")
engine.runAndWait()


while True:
    try:
        print("starting process")
        with sr.Microphone() as source2:    
            r.adjust_for_ambient_noise(source2, duration=0.2)  
            print("completed adjustment")
            audio2 = r.listen(source2) 
            MyText = r.recognize_google(audio2) 
            MyText = MyText.lower() 
            print("Did you say "+MyText) 
            SpeakText(MyText) 
    
    except sr.RequestError as e:
        print("Could not request results; {0}".format(e))
    except sr.UnknownValueError:
        print("an unknown error occured")

当 运行 时,语音测试成功说出“你好”,但随后抛出

||PaMacCore (AUHAL)|| Failed to open AUHAL component.||PaMacCore (AUHAL)|| Error on line 1263: err='-50', msg=Unknown Error
Traceback (most recent call last):
  File "test1.py", line 16, in <module>
    with sr.Microphone() as source2:    
  File "/Users/markus/Library/Python/3.6/lib/python/site-packages/speech_recognition/__init__.py", line 141, in __enter__
    input=True,  # stream is an input stream
  File "/Users/markus/Library/Python/3.6/lib/python/site-packages/pyaudio.py", line 750, in open
    stream = Stream(self, *args, **kwargs)
  File "/Users/markus/Library/Python/3.6/lib/python/site-packages/pyaudio.py", line 441, in __init__
    self._stream = pa.open(**arguments)
OSError: [Errno -9986] Internal PortAudio error

我已经尝试用 brew 卸载并重新安装 portaudio。

-- 编辑--

我 运行 在 musescore 中遇到了与 portaudio 类似的问题,运行使用 sudo 解决了这个问题。

安装 Mojave 后,您能否确认您的麦克风工作正常并且没有受到音频问题的影响,参考 here

您的代码看起来不错。看起来错误是由您的 microphone 系统中的某些故障引起的。确保您已正确遵循包索引页面中的 instructions。 值得注意的是,

PyAudio (for microphone users) PyAudio is required if and only if you want to use microphone input (Microphone). PyAudio version 0.2.11+ is required, as earlier versions have known memory management bugs when recording from microphones in certain situations.

您还应该在此处查看此线程上发布的一些解决方案 - Re: Error code -9986 Internal PortAudio error

`brew 卸载 portaudio

brew 安装 portaudio --HEAD`

消除 Mac Big sur

上的此错误