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.
`brew uninstall portaudio
brew install portaudio --HEAD`
that eliminate this error on Mac Big sur