使用python在macOS上获取扬声器的内部音频输出

Joh*_*bbe 7 python macos core-audio pyaudio python-sounddevice

我想用 python 获取 macOS 上扬声器的内部音频输出。我可以在 Windows 上运行它,但无法在 macOS 上运行它。一开始我们使用 PyAudio,但我认为 SoundDevice 是更好的选择。

这是 Windows 的工作脚本:

import sounddevice as REC
import scipy.io.wavfile

# Recording properties
SAMPLE_RATE = 48000
SECONDS = 10

# Channels
MONO = 1
STEREO = 2

print(REC.query_devices())
# Command to get all devices listed: py -m sounddevice
# Device you want to record
REC.default.device = "PC-Lautsprecher (Realtek HD Audio output with SST)"

print(f'Recording for {SECONDS} seconds')

# Starts recording
recording = REC.rec(int(SECONDS * SAMPLE_RATE), samplerate=SAMPLE_RATE, channels=STEREO)
REC.wait()  # Waits for recording to finish
print("done recording")
scipy.io.wavfile.write("test.wav", SAMPLE_RATE, recording,)
Run Code Online (Sandbox Code Playgroud)

有谁知道在MacOS(核心音频)上运行的方法吗?还有其他适用于 MacOS 的库吗?