Mixer – Mixes one or more audio samples together

Mixer mixes multiple samples into one sample.

class audioio.Mixer(channel_count=2, buffer_size=1024)

Create a Mixer object that can mix multiple channels with the same sample rate.

  • channel_count (int) – The maximum number of samples to mix at once
  • buffer_size (int) – The total size in bytes of the buffers to mix into

Playing a wave file from flash:

import board
import audioio
import digitalio

# Required for CircuitPlayground Express
speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)

music = audioio.WaveFile(open("cplay-5.1-16bit-16khz.wav", "rb"))
drum = audioio.WaveFile(open("drum.wav", "rb"))
mixer = audioio.Mixer(voice_count=2, sample_rate=16000, channel_count=1, bits_per_sample=16, samples_signed=True)
a = audioio.AudioOut(board.A0)

mixer.play(music, voice=0)
while mixer.playing:
  mixer.play(drum, voice=1)

Deinitialises the Mixer and releases any hardware resources for reuse.


No-op used by Context Managers.


Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.

play(sample, *, voice=0, loop=False)

Plays the sample once when loop=False and continuously when loop=True. Does not block. Use playing to block.

Sample must be an audioio.WaveFile, audioio.Mixer or audioio.RawSample.

The sample must match the Mixer’s encoding settings given in the constructor.


Stops playback of the sample on the given voice.


True when any voice is being output. (read-only)


32 bit value that dictates how quickly samples are played in Hertz (cycles per second).