Mixer – Mixes one or more audio samples together

Mixer mixes multiple samples into one sample.

class audiomixer.Mixer(voice_count=2, buffer_size=1024, channel_count=2, bits_per_sample=16, samples_signed=True, sample_rate=8000)

Create a Mixer object that can mix multiple channels with the same sample rate. Samples are accessed and controlled with the mixer’s audiomixer.MixerVoice objects.

  • voice_count (int) – The maximum number of voices to mix
  • buffer_size (int) – The total size in bytes of the buffers to mix into
  • channel_count (int) – The number of channels the source samples contain. 1 = mono; 2 = stereo.
  • bits_per_sample (int) – The bits per sample of the samples being played
  • samples_signed (bool) – Samples are signed (True) or unsigned (False)
  • sample_rate (int) – The sample rate to be used for all samples

Playing a wave file from flash:

import board
import audioio
import audiocore
import audiomixer
import digitalio

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

# Have AudioOut play our Mixer source
# Play the first sample voice
while mixer.playing:
  # Play the second sample voice

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.


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


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


A tuple of the mixer’s audiomixer.MixerVoice object(s).

>>> mixer.voice
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 audiocore.WaveFile, audiocore.RawSample, or audiomixer.Mixer.

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


Stops playback of the sample on the given voice.