Developer guide
Capture system audio with Core Audio process taps
Modern macOS lets an app record what other apps play without a virtual audio driver. This is how echo99 does it in production, including the mistakes that cost real recordings.
On this page: the five steps, from permission and creating the tap to the aggregate device, the IOProc, and teardown; then the failures that cost us recordings: device changes, Bluetooth sample rates, a wrong format label, the mic clock, voice processing, and Swift 6 callbacks.
What a process tap is
A process tap is a Core Audio object that receives a copy of the audio one or more processes
send to an output device. You describe what to capture with CATapDescription, create
the tap with AudioHardwareCreateProcessTap, and read it the way you read any input:
add it to a private aggregate device and run an IOProc on that device. Nothing is rerouted. The
user’s audio keeps playing through the device they chose, and no kernel extension or virtual
output device is involved.
Apple’s reference lists AudioHardwareCreateProcessTap from macOS 14.2, and
Apple publishes a sample,
Capturing
system audio with Core Audio taps. Guilherme Rambo’s open-source
AudioCap targets macOS 14.4, and echo99 follows
its recipe and requires macOS 15. The snippets below are simplified from echo99’s recorder,
with error handling trimmed.
1. Ask for permission, and don’t trust a successful tap
Add NSAudioCaptureUsageDescription to your Info.plist. The first time your app
starts recording from an aggregate device that contains a tap, macOS asks the user for system audio
recording permission. The choice lives in System Settings under Privacy & Security, in Screen
& System Audio Recording.
The trap: AudioHardwareCreateProcessTap succeeds even when the user has
denied access. The tap then delivers silence, and every call still returns
noErr. A working tap is not proof of permission. Confirm the permission before you
record, and treat a stream of exact zeros as a warning sign, not a quiet room.
2. Describe and create the tap
// Everything the system plays, as a stereo mixdown.
let description = CATapDescription(stereoGlobalTapButExcludeProcesses: [])
description.uuid = UUID()
description.muteBehavior = .unmuted // the user keeps hearing it
var tapID = AudioObjectID(kAudioObjectUnknown)
var status = AudioHardwareCreateProcessTap(description, &tapID)
guard status == noErr else { throw TapError.osStatus(status) }
Two variations are worth knowing. If your own app plays audio, exclude it: translate your pid
to a Core Audio process object with kAudioHardwarePropertyTranslatePIDToProcessObject
and put it in the exclude list, or your output loops back into the recording. To capture a single
app, use CATapDescription(stereoMixdownOfProcesses: [processObjectID]) instead.
Read the tap’s format with kAudioTapPropertyFormat, which returns an
AudioStreamBasicDescription. It is fixed when the tap is created, which matters
later.
3. Wrap the tap in a private aggregate device
let outputUID = try deviceUID(of: defaultOutputDeviceID()) // kAudioDevicePropertyDeviceUID
let aggregate: [String: Any] = [
kAudioAggregateDeviceNameKey: "MyApp System Tap",
kAudioAggregateDeviceUIDKey: UUID().uuidString,
kAudioAggregateDeviceMainSubDeviceKey: outputUID,
kAudioAggregateDeviceIsPrivateKey: true,
kAudioAggregateDeviceIsStackedKey: false,
kAudioAggregateDeviceTapAutoStartKey: true,
kAudioAggregateDeviceSubDeviceListKey: [[kAudioSubDeviceUIDKey: outputUID]],
kAudioAggregateDeviceTapListKey: [[
kAudioSubTapDriftCompensationKey: true,
kAudioSubTapUIDKey: description.uuid.uuidString
]]
]
var aggregateID = AudioObjectID(kAudioObjectUnknown)
status = AudioHardwareCreateAggregateDevice(aggregate as CFDictionary, &aggregateID)
Because the aggregate is private, it never shows up in Audio MIDI Setup or in other apps. Its clock comes from the current output device, and the tap is linked by the UUID you gave the description.
4. Read it with an IOProc, and keep the callback real-time
var procID: AudioDeviceIOProcID?
status = AudioDeviceCreateIOProcIDWithBlock(&procID, aggregateID, ioQueue) {
_, inputData, inputTime, _, _ in
ring.write(inputData, at: inputTime) // copy into a lock-free ring, nothing else
}
status = AudioDeviceStart(aggregateID, procID)
This block runs against a hard deadline: at 48 kHz with 512-frame buffers it has
10.67 ms. Don’t write files, log, allocate, or wait on a lock in it. In echo99, a
synchronous AVAudioFile.write on this thread stalled for 11–42 ms. After
repeated missed deadlines, coreaudiod stops delivering the tap’s audio and substitutes
silence for the rest of the session, with no error. One recording lost 76 seconds that way and
still came out as a full-length file.
The fix is a split: the callback copies samples into a lock-free ring buffer, and a separate queue drains the ring to disk (echo99 drains every 20 ms). If the ring overflows, report it. Lost frames should read back as silence the app knows about, not vanish.
5. Tear down in a strict order
AudioDeviceStop(aggregateID, procID)
AudioDeviceDestroyIOProcID(aggregateID, procID)
AudioHardwareDestroyAggregateDevice(aggregateID)
AudioHardwareDestroyProcessTap(tapID)
Stop, destroy the IOProc, destroy the aggregate, then destroy the tap. Never run this on the
IOProc’s own queue: calling AudioDeviceStop from there can hang the HAL. echo99
runs teardown and every rebuild on a separate serial control queue.
The failures that cost us recordings
- The output device changes mid-call. AirPods connect, headphones come out,
a dock disconnects. Listen to
kAudioHardwarePropertyDefaultOutputDeviceand rebuild the tap and aggregate around the new device on your control queue. Listen to the default input device too: an input-only change can stop the tap’s IO. - Bluetooth changes the sample rate under you. When anything opens a
Bluetooth headset’s mic, the headset leaves its music profile for its call profile and the
output’s nominal sample rate changes in place. The tap’s format stays frozen at its
creation value. Without a listener on
kAudioDevicePropertyNominalSampleRate, the rest of our recording played back about 1.84× too fast. - The label can be wrong with no event at all. We have seen taps deliver
samples at a different rate than
kAudioTapPropertyFormatclaims, and on Apple silicon with macOS 26.6.2 a rebuilt tap came back labeled 48 kHz whatever the output ran at. echo99 measures the delivered rate frommSampleTimeagainst host time and relabels the buffers instead of trusting the format. - The microphone runs on a different clock. A mic captured with AVAudioEngine and a tap on the output device are clocked by different hardware. echo99 keeps them as separate files and never mixes them in real time.
- Voice processing fights the tap. In echo99, turning on
setVoiceProcessingEnabledfor the microphone made the aggregate fail to start, and the recording came out empty. - Swift 6 concurrency. A closure written inside a
@MainActortype inherits main-actor isolation. When Core Audio or Dispatch calls it on another queue, Swift traps at runtime, although the code builds cleanly. Mark the callbacks you hand to Core Audio and Dispatch@Sendable.
Or skip the plumbing
If you need recordings rather than code, echo99 does all of this in a free menu-bar app: your mic and the system audio as two WAV files, then an on-device transcript. Recording system audio covers it from the user’s side, and Technology lists the models echo99 runs.
Related guides: Record system audio, Soundflower and BlackHole alternative, Technology
Need recordings, not code? Try echo99
Free download. No account. Recording and transcription stay on your Mac.
Free · macOS 15+ · Apple silicon & Intel · Notarized by Apple