PyAudio 无法在 macOS 11.1

时间:2021-01-07 22:04:07

标签: python pyaudio portaudio macos-big-sur

我正在尝试使用 PyAudio 录制扬声器输出。我安装了 BackgroundMusic,它声称允许记录系统输出。我不认为这是问题所在,但我可能是错的。

代码

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

错误

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

一些系统信息

$ 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
python@3.9: stable 3.9.1 (bottled)
...

$ brew info portaudio
portaudio: stable 19.6.0 (bottled), HEAD
...

$ pip show pyaudio
Version: 0.2.11
...

根据this thread,我需要授予麦克风访问权限?在终端中运行时,它不会要求访问麦克风,而且我认为无法在系统偏好设置中添加它。

该线程还指出 this PortAudio function 作为从该错误中获取更多信息的一种方式,但我不确定如何准确地破解 PyAudio 库以获取该信息。

我希望得到一些正确方向的指导。提前致谢。

0 个答案:

没有答案