Python: Portaudio Errno -9986 Internal PortAudio error

Viewed 1904

I'm trying to run a simple python speech recognition program. The code is as follows:

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")

When run, the test to speech says "Hello" successfully but then throws

||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

I have tried uninstalling and reinstalling portaudio with brew.

-- EDIT --

I ran into similar issues with portaudio in musescore, running the program using sudo solved the issue.

2 Answers

`brew uninstall portaudio

brew install portaudio --HEAD`

that eliminate this error on Mac Big sur

Can you confirm that your microphone works fine and it's not being affected by audio issue after installing Mojave, reference here.

Your code seems fine. It looks like the error is stemming from some faults in your microphone system. Make sure that you have correctly followed the instructions from the package index page. Notably,

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.

You should also see some of the solutions posted on this thread here - Re: Error code -9986 Internal PortAudio error

Related