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),AudioOuthands the graph to the pump, which writes it to WASAPI from its own thread and never opens this transport. A nameddevicestays on this transport.
- property buffer_frames
Frames the WASAPI buffer holds in all; 0 until the output is open.
- 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; passstart=Falseto prime the buffer first and callstartwhen it holds enough.Use either this or
writeon one output, not both: they reach the device by different paths, and nothing orders one against the other. Pair it withdevice_framesto see how much the device still has to play, andbuffer_framesfor its capacity.
- class audiodev.win_audio.WinPCMInput(fmt, *, device=None, samples=512, queue_ms=500, poll_ms=2, session=None)[source]
Bases:
PCMInput