audiodev.win_audio

WASAPI queued PCM backend for Windows CPython (via uwin32).

Playback and capture use shared-mode IAudioClient with AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM. There is no Python audio-thread callback. Import fails unless uwin32 loads.

class audiodev.win_audio.WinPCMOutput(fmt, *, device=None, samples=4096, queue_ms=2000, poll_ms=2, coalesce_ms=100, prebuffer_ms=None, session=None)[source]

Bases: PCMOutput

property speaker_sink

The firmware’s name for this speaker, or None.

"wasapi" for the default device: on an interpreter whose pump can open it (audiodev.pump.speaker), AudioOut hands the graph to the pump, which writes it to WASAPI from its own thread and never opens this transport. A named device stays on this transport.

queued_size()[source]

Bytes still waiting to play or capture. Default 0.

is_active()[source]

True while PCM remains queued. Default False.

clear()[source]

Drop queued PCM now. Default no-op.

property buffer_frames

Frames the WASAPI buffer holds in all; 0 until the output is open.

device_frames()[source]

Frames written to the device and not yet played (its padding).

write_now(buf, *, start=True)[source]

Write buf straight into the WASAPI buffer, now, and return the bytes written.

For a caller that runs its own short queue – a synth or mixer that renders a block at a time and decides itself how far ahead of the device to stay. It skips write’s media queue and coalescing, which batch PCM into 100 ms pieces and hold playback back until about 100 ms is queued: right for a decoder, far too much for a key-to-sound path.

Whole frames only, as many as the device has room for; it never waits and never keeps the rest, so a short count means the device is full and the caller still holds the remainder. Volume and mute apply, as they do to write. With start (the default) playback begins as soon as anything has been written; pass start=False to prime the buffer first and call start when it holds enough.

Use either this or write on one output, not both: they reach the device by different paths, and nothing orders one against the other. Pair it with device_frames to see how much the device still has to play, and buffer_frames for its capacity.

start()[source]

Start playing what write_now has written; True once playing.

service()[source]

Per-tick housekeeping. Queued hosts override; default is a no-op.

class audiodev.win_audio.WinPCMInput(fmt, *, device=None, samples=512, queue_ms=500, poll_ms=2, session=None)[source]

Bases: PCMInput

queued_size()[source]

Bytes still waiting to play or capture. Default 0.

audiodev.win_audio.pcm_out(format=None, *, device=None, latency=None, samples=None, queue_ms=None, coalesce_ms=None, prebuffer_ms=None, poll_ms=2)[source]

Create a WASAPI-backed PCMOutput.

audiodev.win_audio.pcm_in(format=None, *, device=None, latency=None, samples=None, queue_ms=None, poll_ms=2)[source]

Create a WASAPI-backed PCMInput.