audiodev.alsa_audio

ALSA PCM backend for Linux, straight to libasound with no SDL or pygame.

Playback and capture use ALSA’s own ring buffer in non-blocking mode: a write takes what fits and waits a little for the rest, and queued_size() is what the sound card still holds. There is no thread and no callback into Python. It runs on CPython (through ctypes) and on the unix MicroPython and CircuitPython builds that have ffi. Import fails unless libasound loads.

device is any name ALSA’s snd_pcm_open takes: "default", the sound server’s plug-in, when it is left out, or a card such as "plughw:2,0". devices lists the cards the kernel has.

audiodev.alsa_audio.has_cards()[source]

True when the kernel has at least one sound card.

audiodev.alsa_audio.devices()[source]

The sound cards’ PCM devices, from /proc/asound/pcm.

Returns a list of dicts: name (what to pass as device, such as "plughw:2,0"), card, device, description, and whether it can playback or capture. It is empty where there are no cards.

class audiodev.alsa_audio.AlsaPCMOutput(fmt, *, device=None, latency_us=200000, prebuffer_ms=50, poll_ms=2, session=None)[source]

Bases: _Stream, PCMOutput

xruns

Underruns the card has had since this output opened. A healthy run has none.

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.

class audiodev.alsa_audio.AlsaPCMInput(fmt, *, device=None, latency_us=200000, poll_ms=2, session=None)[source]

Bases: _Stream, PCMInput

xruns

audio the caller didn’t read in time.

Type:

Overruns since this input opened

queued_size()[source]

Bytes still waiting to play or capture. Default 0.

clear()[source]

Drop queued PCM now. Default no-op.

audiodev.alsa_audio.pcm_out(format=None, *, device=None, latency=None, poll_ms=2)[source]

Create an ALSA PCMOutput.

latency picks the ring buffer: "low" is 40 ms, the others 200 ms.

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

Create an ALSA PCMInput.