Python API — Streams, Blocks & Plan Reports
Covers session planning (CaptureRequest.inspect()), real-time safe streaming (ManagedStream, AudioStream), zero-copy PEP 3118 PcmBlock buffers, and mixer diagnostics.
CaptureRequest
Section titled “CaptureRequest”Immutable session specification supporting side-effect-free .inspect(), permission preflights, and .open().
| Property | Type |
|---|---|
allow_reroute |
bool |
backends |
Backends |
budgets |
AggregateManagerBudgets |
combine_mode |
CombineMode |
input_conversion |
InputConversionPolicy |
mixer_config |
MixerConfig |
on_format_change |
OnFormatChange |
output_converter |
OutputConverter | None |
permission_policy |
PermissionPolicy |
targets |
list[CaptureTarget] |
timing |
TimingRequirement |
tree_strategy |
ProcessTreeRange |
def check_permissions() -> PermissionReportdef inspect() -> CapturePlanReportdef inspect_for_os(os: PlatformOs | str) -> CapturePlanReportdef open(overflow: Overflow | str=..., timing: TimingRequirement | str | None=None) -> ManagedStreamdef request_permissions(timeout_ms: SupportsIndex=30000, open_settings_if_denied: bool=False) -> PermissionReportasync def request_permissions_async(timeout_ms: SupportsIndex=30000, open_settings_if_denied: bool=False) -> PermissionReportdef with_permission_policy(policy: PermissionPolicy | str) -> CaptureRequestManagedStream
Section titled “ManagedStream”Primary multi-target/pass-through session supporting with / async with, read, 0-alloc read_into, read_async, callbacks, and live update_targets hot-swap.
| Property | Type |
|---|---|
active_reader_count |
int |
callback_invocations |
int |
is_software_mix |
bool |
last_callback_error |
str | None |
last_cleanup_error |
str | None |
output_format |
Format | None |
plan |
CapturePlanReport | None |
segment_id |
int |
selected_backend |
BackendId |
session_id |
int |
targets |
list[CaptureTarget] |
working_format |
Format | None |
async def __aenter__() -> ManagedStreamdef __aiter__() -> ManagedStreamdef __enter__() -> ManagedStreamdef __iter__() -> ManagedStreamdef input_handles() -> list[InputStatusHandle]def read(frames: SupportsIndex=480, timeout_ms: SupportsIndex=200, cancel: Cancellation | None=None) -> ReadOutcomeasync def read_async(frames: SupportsIndex=480, timeout_ms: SupportsIndex=200, cancel: Cancellation | None=None) -> ReadOutcomedef read_into(destination: bytearray | memoryview | Any, frames: SupportsIndex, timeout_ms: SupportsIndex=200, cancel: Cancellation | None=None) -> ReadOutcomedef start_callback(callback: Any, frames: SupportsIndex=480, timeout_ms: SupportsIndex=50) -> Nonedef stop(mode: StopMode | str=...) -> Nonedef stop_callback() -> Nonedef update_targets(target: CaptureTarget | Sequence[CaptureTarget]) -> intdef wait_cleanup() -> boolAudioStream
Section titled “AudioStream”Lightweight single-session backend stream without discovery watchers, process-tree monitoring, or automatic device-follow.
| Property | Type |
|---|---|
active_reader_count |
int |
format |
Format |
last_callback_error |
str | None |
last_cleanup_error |
str | None |
def __enter__() -> AudioStreamdef __iter__() -> AudioStream@staticmethoddef open(target: CaptureTarget, tree_strategy: ProcessTreeRange | ProcessTreeStrategy | str | None=None, backends: Backends | None=None, overflow: Overflow | str=..., timing: TimingRequirement | str=..., cleanup_timeout_ms: SupportsIndex=2000, permission_policy: PermissionPolicy | str | None=None, request_permissions: bool | None=None) -> AudioStreamdef read(frames: SupportsIndex=480, timeout_ms: SupportsIndex=200, cancel: Cancellation | None=None) -> ReadOutcomedef read_into(destination: bytearray | memoryview | Any, frames: SupportsIndex, timeout_ms: SupportsIndex=200, cancel: Cancellation | None=None) -> ReadOutcomedef stop(mode: StopMode | str=...) -> Nonedef wait_cleanup() -> boolPcmBlock
Section titled “PcmBlock”Ref-counted zero-copy PCM buffer supporting PEP 3118 memoryview(block) and to_numpy(copy=False) even after stop().
| Property | Type |
|---|---|
byte_len |
int |
byte_order |
ByteOrder |
channels |
int |
data_ptr |
int |
frames |
int |
generation |
int |
materialized_copies |
int |
rate |
int |
sample_format |
SampleType |
segment |
int |
sequence |
int |
def __buffer__(flags: int, /) -> memoryviewdef to_bytes() -> bytesdef to_numpy(copy: bool=False, unpack_i24: bool=False) -> AnyReadOutcome
Section titled “ReadOutcome”Result of read, read_into, or read_async carrying frames, blocks, reason, boundary_kind, and mixed_metadata.
| Property | Type |
|---|---|
blocks |
list[PcmBlock] |
boundary_kind |
BoundaryKind | None |
copy_bytes |
int |
copy_destinations |
int |
failure |
FailureKind | None |
frames |
int |
mixed_metadata |
MixedBlockMetadata | None |
reason |
PartialReason |
segment |
int |
session |
int |
Format
Section titled “Format”Explicit PCM stream format (rate, channels, sample_format, byte_order, speaker layout, bytes_per_frame).
class Format(rate: SupportsIndex=48000, channels: SupportsIndex=2, sample_format: SampleType | str=..., byte_order: ByteOrder | str=..., layout: SupportsGetItem[int, Channel | str] | None=None) -> Format| Property | Type |
|---|---|
byte_order |
ByteOrder |
bytes_per_frame |
int |
channels |
int |
layout |
list[Channel] | None |
rate |
int |
sample_format |
SampleType |
CapturePlanReport
Section titled “CapturePlanReport”Side-effect-free execution plan detailing combine_resolution, target_plans, stream count, and PCM byte budget.
| Property | Type |
|---|---|
allow_reroute |
bool |
backends |
Backends |
combine_backend |
BackendId | None |
combine_mode |
CombineMode |
combine_resolution |
CombineResolutionKind |
duplicate_target_ids |
list[str] |
estimated_active_streams |
int |
estimated_pcm_bytes |
int |
input_conversion |
InputConversionPolicy |
os |
PlatformOs |
overlap_semantics |
OverlapSemantics |
permission_policy |
PermissionPolicy |
requires_discovery_subscription |
bool |
selected_backend |
BackendId | None |
target_plans |
list[TargetPlan] |
tree_strategy |
ProcessTreeRange |
uses_output_converter |
bool |
uses_software_mixer |
bool |
TargetPlan
Section titled “TargetPlan”Resolved per-target backend, acquisition mode, and candidate evaluation trace inside CapturePlanReport.
| Property | Type |
|---|---|
acquisition |
TargetAcquisitionKind |
attempts |
list[TargetCandidateAttempt] |
process_tree_strategy |
ProcessTreeStrategy | None |
resolved_backend |
BackendId |
target_id |
str |
target_index |
int |
TargetCandidateAttempt
Section titled “TargetCandidateAttempt”Single backend candidate evaluation record (accepted or PlanErrorCode rejection).
| Property | Type |
|---|---|
accepted |
bool |
acquisition |
TargetAcquisitionKind | None |
backend |
BackendId |
process_tree_strategy |
ProcessTreeStrategy | None |
rejection |
PlanErrorCode | None |
InputStatusHandle
Section titled “InputStatusHandle”Read-only per-input diagnostic handle exposing BYPASS/SYNC normalizer state, participation, and drift-slip counters.
| Property | Type |
|---|---|
backend |
BackendId |
clipped_samples |
int |
drift_slips |
int |
dropped_frames |
int |
failure_code |
int | None |
is_identity_bypass |
bool |
is_resampled |
bool |
mixer_format |
Format |
native_format |
Format |
nonfinite_samples |
int |
participation_state |
ParticipationState |
queued_packets |
int |
target_id |
str |
target_index |
int |
MixedBlockMetadata
Section titled “MixedBlockMetadata”Per-block software mixer telemetry (contributing_mask, synthesized_silence, clock-domain skew_estimate_ns, drift_slips).
| Property | Type |
|---|---|
clipped_samples |
int |
contributing_mask |
int |
drift_slips |
int |
failed_inputs |
int |
late_inputs |
int |
membership_version |
int |
nonfinite_inputs |
int |
nonfinite_samples |
int |
skew_estimate_ns |
int | None |
skew_uncertainty_ns |
int | None |
synthesized_silence |
bool |
Cancellation
Section titled “Cancellation”Thread-safe cooperative cancellation token waking blocked read, read_into, or read_async calls immediately.
class Cancellation() -> Cancellationdef cancel() -> Nonedef is_cancelled() -> bool