I'm trying to record speaker output with PyAudio. I have BackgroundMusic installed, which claims to allow recording system output. I don't think it's the issue but I could be wrong.
Code
import pyaudio
p = pyaudio.PyAudio()
stream = p.open(
format=pyAudio.paInt16,
channels=1,
rate=44100,
input=True,
frames_per_buffer=2048
)
# code to do stuff with stream.read(), not relevant here
Error
||PaMacCore (AUHAL)|| AUHAL component not found.Traceback (most recent call last):
File ".../script.py", line 5, in <module>
stream = p.open(
File "/opt/homebrew/lib/python3.9/site-packages/pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "/opt/homebrew/lib/python3.9/site-packages/pyaudio.py", line 441, in __init__
self._stream = pa.open(**arguments)
OSError: [Errno -9999] Unanticipated host error
Some system info
$ brew config
HOMEBREW_VERSION: 2.7.2
...
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 12.0 build 1200
macOS: 11.1-arm64
CLT: 12.3.0.0.1.1607026830
Xcode: 12.3
Rosetta 2: false
$ brew info python
[email protected]: stable 3.9.1 (bottled)
...
$ brew info portaudio
portaudio: stable 19.6.0 (bottled), HEAD
...
$ pip show pyaudio
Version: 0.2.11
...
According to this thread, I need to grant microphone access? When running in the terminal, it doesn't ask for microphone access and I see no way to add it in System Preferences.
The thread also points to this PortAudio function as a means of getting more information out of this error, but I'm not sure how exactly to hack the PyAudio library for that information.
I'd love some guidance in the right direction on this. Thanks in advance.
After installing non-Homebrew Python and installing portaudio using brew install portaudio --HEAD
, I was able to get it to work.
I also reinstalled Homebrew to use Rosetta, but I'm not sure if that made a difference.