System Speaker Loopback
Capture whatever is playing on speakers or headphones without installing VB-Cable, BlackHole, or Soundflower — automatically tracking OS default-endpoint switches in Follow mode.
Capture system speakers, isolate any single app/process, or mix microphones into one live PCM stream across Windows, Linux & macOS.
Native WASAPI · PipeWire · PulseAudio · Core Audio Process Taps · ScreenCaptureKit — zero virtual audio cables, zero silent fallbacks.
Pick your language — your selection stays synced across every guide on this site:
pip install "capture-system-or-process-audio[numpy]"python -m capture_system_or_process_audioimport capture_system_or_process_audio as cspa
# List & filter active audio apps deterministically (or use cspa.find_app("Zoom")):apps = [a for a in cspa.discover().applications if a.active_audio is True]app_target = apps[0].with_gain(0.9) if apps else cspa.default_output()
# Mix default microphone + app into one 16 kHz mono float32 stream for Whisper / STT:converter = cspa.OutputConverter(rate=16000, channels=1, sample_format="f32")
with cspa.capture( [cspa.microphone(), app_target], output_converter=converter, silence_on_idle=True,) as stream: outcome = stream.read(frames=1600, timeout_ms=200) # 100 ms @ 16 kHz for block in outcome.blocks: samples = block.to_numpy() # zero-copy view, shape: (frames, 1), dtype: float32cargo add capture-system-or-process-audiouse capture_system_or_process_audio::{ CapabilityError, CaptureTarget, DefaultDeviceMode, Stop, capture_single,};use std::time::Duration;
fn main() -> Result<(), CapabilityError> { let target = CaptureTarget::default_output(DefaultDeviceMode::Follow); let mut manager = capture_single(target)?;
let fmt = manager.output_format().expect("active output format").clone(); let mut pcm_buf = vec![0u8; 480 * fmt.bytes_per_frame()];
// Zero-allocation steady-state pull into caller-owned buffer: let res = manager .read_into(&mut pcm_buf, 480, Duration::from_millis(200)) .expect("read PCM frames"); println!("Captured {} frames @ {} Hz", res.frames, fmt.rate());
manager.stop(Stop::Drain); manager.wait_cleanup(Duration::from_secs(2)); Ok(())}cmake_minimum_required(VERSION 3.20)project(audio_example LANGUAGES CXX)
find_package(Cspa REQUIRED CONFIG)add_executable(example main.cpp)target_compile_features(example PRIVATE cxx_std_17)target_link_libraries(example PRIVATE Cspa::cspa_ffi)#include <cspa.hpp>#include <cstdio>#include <vector>
int main() { auto speaker = cspa::Target::default_output(cspa::DefaultDeviceMode::Follow).take_value(); auto mic = cspa::Target::microphone(cspa::DefaultDeviceMode::Follow).take_value();
cspa::MixerConfig mixer; mixer.set_silence_on_idle(true);
cspa::CaptureRequest req({speaker, mic}); req.set_mixer_config(mixer) .set_output_converter(cspa::OutputConverter(48000, 2, cspa::SampleFormat::F32));
auto stream_res = cspa::ManagedStream::open(req); if (!stream_res.is_ok()) return 1; cspa::ManagedStream stream = stream_res.take_value();
std::vector<uint8_t> pcm(480 * 2 * sizeof(float)); auto rd = stream.read_into(pcm.data(), pcm.size(), 480, 200); if (rd.is_ok()) { std::printf("Captured %llu mixed frames\n", static_cast<unsigned long long>(rd.value().frames)); }
stream.stop(false); stream.wait_cleanup(2000); return 0;}#include <cspa_experimental.h>#include <stdint.h>#include <stdio.h>
int main(void) { if (cspa_abi_check(CSPA_EXPERIMENTAL_ABI_MAJOR, CSPA_EXPERIMENTAL_SCHEMA_REVISION) != CSPA_STATUS_OK) { return 1; }
cspa_capture_target_record target = {0}; target.struct_size = (uint32_t)sizeof(target); target.schema_revision = CSPA_EXPERIMENTAL_SCHEMA_REVISION; if (cspa_target_default_output(CSPA_DEFAULT_DEVICE_FOLLOW, 1.0f, &target) != CSPA_STATUS_OK) { return 1; }
cspa_stream *stream = NULL; if (cspa_stream_open(&target, CSPA_OVERFLOW_DROP_OLDEST, &stream) != CSPA_STATUS_OK) { return 1; }
uint8_t buffer[480 * 8]; cspa_managed_read_outcome_record out = {0}; out.struct_size = (uint32_t)sizeof(out); out.schema_revision = CSPA_EXPERIMENTAL_SCHEMA_REVISION;
if (cspa_stream_read_into(stream, buffer, sizeof(buffer), 480u, 200u, NULL, &out) == CSPA_STATUS_OK) { printf("Read %llu frames (%llu bytes)\n", (unsigned long long)out.actual_frames, (unsigned long long)out.copy_bytes); }
cspa_stream_stop(stream, 0u); uint32_t cleaned = 0; cspa_stream_wait_cleanup(stream, 2000u, &cleaned); cspa_stream_release(stream); return 0;}System Speaker Loopback
Capture whatever is playing on speakers or headphones without installing VB-Cable, BlackHole, or Soundflower — automatically tracking OS default-endpoint switches in Follow mode.
Single App & Process Isolation
Record audio from only Spotify, Zoom, Firefox, or a game (including helper child processes where supported) without capturing unrelated desktop notifications.
Microphones & Audio Inputs
Capture default or specific microphones with automatic Linux .monitor sink exclusion and event-driven default-input handover.
Drift-Synced Live Mixer & Resampler
Combine [microphone(), find_app("Zoom")] via CspaMixer into one clock-drift-compensated PCM stream converted on the fly to 16 kHz mono f32/i16, 44.1 kHz, or 48 kHz stereo.
Honest 5-State OS Permissions
Preflight or prompt macOS TCC (Microphone, SystemAudio, ScreenRecording) and Windows ConsentStore / GPO with macOS missing-Info.plist SIGABRT protection.
Zero-Allocation Real-Time Core
Preallocated bounded slot pools perform 0 heap allocations on warmed read_into loops across Rust, Free-Threaded Python 3.14t/3.15t (-Xgil=0), C++17, and C11.
PyAudioWPatch?Four years ago, @s0d3s created PyAudioWPatch to bring Windows WASAPI speaker loopback to Python’s PyAudio. Today it is the standard Windows loopback package in the Python ecosystem — serving 140,000+ monthly PyPI downloads (~1.6M+ annually) and powering 340+ open-source repositories across AI meeting copilots, live Whisper/STT transcription bots, voice agents, and desktop recorders.
140,000+ / mo
PyAudioWPatch PyPI downloads (~1.6M+ / yr) proven in production
340+ Repos
Open-source meeting copilots, STT pipelines & recorders built on it
4+ Years
Real-world WASAPI loopback bug reports & edge-case lessons
~1 Year R&D
Dedicated ground-up engineering & polish in safe Rust for this library
PyAudioWPatch Hit an Architectural Wall — and Why This Took Nearly a Year to BuildAs PyAudioWPatch grew, users repeatedly requested capabilities that were architecturally impossible to implement inside a legacy PortAudio C wrapper:
BlackHole or VB-Cable).stream.read() loops in PyAudioWPatch to hang forever); unplugging headphones breaks pinned streams; combining [Microphone + App/System Audio] drifts out of sync across independent hardware clocks; and Free-Threaded Python 3.14t/3.15t (-Xgil=0) collides with PortAudio’s global C state.Rather than bolting fragile workarounds onto a 20-year-old C wrapper, capture-system-or-process-audio is the result of nearly a year of dedicated ground-up development and polish in safe Rust — turning years of PyAudioWPatch production feedback into one zero-steady-state-allocation engine across Python, Rust, C++17, and C11:
| Capability | capture-system-or-process-audio |
PyAudioWPatch |
sounddevice / PyAudio |
cpal (Rust) |
Virtual Cables (VB-Cable / BlackHole) |
|---|---|---|---|---|---|
| System Speaker Loopback | ✅ Win · Linux · macOS | ✅ Windows only | ❌ | ⚠️ Partial | ⚠️ Manual driver install |
| Single App / Process Tree Isolation | ✅ Win · Linux · macOS | ❌ | ❌ | ❌ | ❌ |
| Microphone + App/System Live Mix | ✅ Built-in (CspaMixer + drift sync) |
❌ Manual | ❌ Manual | ❌ Manual | ⚠️ Manual multi-output |
| Silent-Speaker Hang Protection | ✅ (silence_on_idle + timeouts) |
❌ Hangs read() |
❌ | ❌ | N/A |
| Auto-Follow Default Device Switches | ✅ (Follow mode) |
❌ | ❌ | ❌ | ❌ Breaks volume keys |
| Built-In Resampler & Format Converter | ✅ (16k/44.1k/48k, f32/i16/i24/i32) |
❌ | ❌ | ❌ | ❌ |
| OS Permission Preflight & Prompt API | ✅ Honest 5-state report | ❌ | ❌ | ❌ | N/A |
Free-Threaded Python (3.14t/3.15t) |
✅ Native (Py_MOD_GIL_NOT_USED) |
❌ | ❌ | N/A | N/A |
| First-Class SDKs | Python, Rust, C++17, C11 | Python (Win) | Python | Rust | OS Driver |
Already using PyAudioWPatch? Jump straight to the Side-by-Side PyAudioWPatch Migration Guide.
When a requested scope or capability is unsupported on the active OS or OS build, capture-system-or-process-audio fails explicitly with a typed error (CapabilityError / PlanError) — it never silently substitutes full-system audio for single-process capture.
| Platform | Native Backends | System & Device Output | Application / Process Capture | Microphones & Inputs |
|---|---|---|---|---|
Windows 10 / 11 (x64, ARM64) |
wasapi |
✅ Build 19041+ (Follow/Pin, device) |
✅ Build 20348+ (scope="tree"; exact rejected explicitly) |
✅ Build 19041+ (Follow/Pin, input_device) |
Linux (x86_64, aarch64) |
pipewire (0.3.65+), pulseaudio (15.0+) |
✅ Sink monitor & default sink tracking | ✅ PipeWire virtual-sink fan-in (tree/exact) & PulseAudio stream mix |
✅ Physical/virtual sources (0 compile-time NEEDED links) |
macOS (Apple Silicon arm64) |
coreaudio, screencapturekit |
✅ macOS 14.2+ Core Audio Process Taps |
✅ macOS 14.2+ Core Audio Taps (tree/exact) & macOS 13.0+ SCK (exact) |
✅ macOS 13.0+ Core Audio HAL input (AVMediaTypeAudio) |
Adapters & Node.js SDK Planned Planned — Next Release
Today’s release connects directly to NumPy (block.to_numpy(copy=False)), faster-whisper (16 kHz mono f32), wave, asyncio, Rust, and C/C++. Next release adds zero-rewrite drop-in compatibility adapters (PyAudio/PyAudioWPatch, python-sounddevice, SoundCard, SpeechRecognition, Whisper sliding-window streams) alongside first-class napi-rs Node.js / TypeScript / Electron bindings.