macos-audio-tap
A Swift package and command-line tool that reads the level of everything playing on a Mac through Core Audio process taps and prints it in dBFS as JSON lines.
audio-tap is designed to report, several times a second, how loud everything that is playing on a Mac is. The system output is tapped with Core Audio process taps, the RMS level of each buffer is computed, and that level is printed in dBFS. The audio itself never leaves the process, which means that only a number is passed to your code.
macOS 14.4 or later is required, since process taps were introduced in that release.
The permission that fails silently
The System Audio Recording permission, which is found under Privacy & Security in System Settings, has to be given to the app that runs audio-tap, and an NSAudioCaptureUsageDescription entry is required in its Info.plist. When the permission is missing, no error is returned by macOS. Setup therefore succeeds, and the tap delivers silence only.
A hint is printed on stderr when nothing above -100 dBFS arrives within --silence-timeout-s (8 seconds by default). A missing permission, however, cannot be told apart from a Mac on which nothing is playing. The permission is also tied to the code signature of the app, so it can be reset without any warning when the app is re-signed with a different identity, as happens with an ad-hoc build.
Install
For use from the command line, the tool is built as follows:
swift build -c release
.build/release/audio-tap --emit-interval-ms 100
For use from Swift without a separate process, the package is added as a dependency:
.package(url: "https://github.com/firedanceio/macos-audio-tap", from: "0.1.0")
Example
While it runs, one JSON object is printed per line:
{"event":"ready"}
{"dbfs":-18.4,"event":"level","timestampMs":1791419046720}
{"deviceName":"MacBook Pro Speakers","event":"outputDeviceChanged"}

Four kinds of event are sent by the tool. ready indicates that capture has started. level is sent every --emit-interval-ms (100 by default) and carries the loudness in dBFS, with silence reported as -120. outputDeviceChanged is sent when the default output is changed, for example from speakers to headphones. error indicates that setup has failed, after which the process exits with status 1. Capture is stopped and the tap is removed by Ctrl-C or SIGTERM.
The tool can be used by any program that is able to start a process and read lines, including Node, Python and shell scripts. In Swift, the same readings are provided as callbacks by the SystemAudioTap library:
import SystemAudioTap
let tap = SystemAudioTap(emitIntervalMs: 100)
tap.onLevel = { level in print(level.dbfs) }
try tap.prepare()
try tap.start(on: DispatchQueue(label: "levels"))
Limits
Only the level is reported. Samples, frequency data and per-app levels are outside its scope, since the tap covers every process at once. Process taps are unavailable before macOS 14.4.
When a custom tap is written, a private aggregate device that has no sub-devices, or one to which the tap is added after creation, may fail to start on some machines. This is avoided in audio-tap by using the default output device as the sub-device and by listing the tap at the moment the device is created.
Licence
Apache 2.0. The code follows patterns from the open-source projects AudioCap and AudioTee, and both are credited in the NOTICE file of the repository.
Read the announcement: Our first open source release.