Skip to content

Choosing an API

Every SDK exposes the same core building blocks. Use the decision tables below to pick the cleanest path for your workload.


1. CaptureManager (capture) vs AudioStream (open_stream)

Section titled “1. CaptureManager (capture) vs AudioStream (open_stream)”
Question Use CaptureManager / ManagedStream (Recommended Default) Use AudioStream (Advanced Single-Session)
Single speaker, mic, or app? ✅ Uses zero-extra-copy PassThrough automatically when no mixing/conversion is needed. ✅ Opens one raw OS session directly.
Follow OS default speaker/mic switches? ✅ DefaultDeviceMode::Follow seamlessly closes old and opens new endpoints. ❌ Never monitors device switches (Follow requires CaptureManager).
Mix multiple sources ([mic, app])? ✅ Orchestrates SharedNativeGraphMix or CspaMixer automatically. ❌ Single target only.
Resample / convert format (16 kHz i16/f32)? ✅ Built-in OutputConverter + silence_on_idle. ❌ Native OS device format only.
Wait for app relaunch (OnRootExit::Wait) or hot-swap targets? ✅ Supported (update_targets). ❌ Ends on session exit.

  • Follow (Default): When a user plugs in USB/Bluetooth headphones or changes their default microphone in OS settings, CaptureManager detects the change via native event listeners (IMMNotificationClient, PipeWire/Pulse metadata, AudioObjectAddPropertyListener) and transitions the stream automatically, emitting a Boundary marker so downstream consumers know when hardware changed.
  • Pin: Resolves the current default output or microphone ID once at open time and stays bound to that specific endpoint even if the OS default changes later.

3. Read Delivery Patterns (read vs read_into vs asyncio vs Callbacks)

Section titled “3. Read Delivery Patterns (read vs read_into vs asyncio vs Callbacks)”
import capture_system_or_process_audio as cspa
# Pattern A — Zero-copy PcmBlock views (great for NumPy / batch consumers):
with cspa.capture(cspa.default_output(), silence_on_idle=True) as stream:
outcome = stream.read(frames=480, timeout_ms=200)
for block in outcome.blocks:
view = memoryview(block) # PEP 3118 zero-copy read-only view
# Pattern B — Zero-allocation read_into (0 steady-state heap allocs, safe on 3.14t/3.15t -Xgil=0):
conv = cspa.OutputConverter(rate=48000, channels=2, sample_format="i16")
with cspa.capture(cspa.default_output(), output_converter=conv, silence_on_idle=True) as stream:
reusable = bytearray(480 * 2 * 2)
into_res = stream.read_into(reusable, frames=480, timeout_ms=200)
print("Frames written:", into_res.frames)

4. When Should You Enable silence_on_idle?

Section titled “4. When Should You Enable silence_on_idle?”

On Windows WASAPI loopback and per-process taps, the OS emits zero packets while all audio playback is paused.

  • Leave silence_on_idle=False (default) when recording only active audio bursts or event-driven streams.
  • Set silence_on_idle=True whenever feeding continuous wall-clock consumers (WebRTC, Discord bots, VADs, or PyAudio-style blocking loops) so idle periods emit metadata-flagged silent frames (synthesized_silence = true) instead of timing out.

Explore SDK Overview & Quick Starts or Multi-SDK API Reference next.