WaveFile – Load a wave file for audio playback

A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must be 8 bit unsigned or 16 bit signed. If a buffer is provided, it will be used instead of allocating an internal buffer.

class audiocore.WaveFile(file[, buffer])

Load a .wav file for playback with audioio.AudioOut or audiobusio.I2SOut.

  • file (typing.BinaryIO) – Already opened wave file
  • buffer (bytearray) – Optional pre-allocated buffer, that will be split in half and used for double-buffering of the data. If not provided, two 512 byte buffers are allocated internally.

Playing a wave file from flash:

import board
import audiocore
import audioio
import digitalio

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

data = open("cplay-5.1-16bit-16khz.wav", "rb")
wav = audiocore.WaveFile(data)
a = audioio.AudioOut(board.A0)

while a.playing:

Deinitialises the WaveFile and releases all memory resources for reuse.


No-op used by Context Managers.


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


32 bit value that dictates how quickly samples are loaded into the DAC in Hertz (cycles per second). When the sample is looped, this can change the pitch output without changing the underlying sample.


Bits per sample. (read only)


Number of audio channels. (read only)