I2SOut – Output an I2S audio signal

I2S is used to output an audio signal on an I2S bus.

class audiobusio.I2SOut(bit_clock, word_select, data, *, left_justified)

Create a I2SOut object associated with the given pins.

  • bit_clock (Pin) – The bit clock (or serial clock) pin
  • word_select (Pin) – The word select (or left/right clock) pin
  • data (Pin) – The data pin
  • left_justified (bool) – True when data bits are aligned with the word select clock. False when they are shifted by one to match classic I2S protocol.

Simple 8ksps 440 Hz sine wave on Metro M0 Express using UDA1334 Breakout:

import audiobusio
import audiocore
import board
import array
import time
import math

# Generate one period of sine wave.
length = 8000 // 440
sine_wave = array.array("H", [0] * length)
for i in range(length):
    sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)

sine_wave = audiocore.RawSample(sine_wave, sample_rate=8000)
i2s = audiobusio.I2SOut(board.D1, board.D0, board.D9)
i2s.play(sine_wave, loop=True)

Playing a wave file from flash:

import board
import audioio
import audiocore
import audiobusio
import digitalio

f = open("cplay-5.1-16bit-16khz.wav", "rb")
wav = audiocore.WaveFile(f)

a = audiobusio.I2SOut(board.D1, board.D0, board.D9)

while a.playing:

Deinitialises the I2SOut 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, *, 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 itself should consist of 8 bit or 16 bit samples.


Stops playback.


True when the audio sample is being output. (read-only)


Stops playback temporarily while remembering the position. Use resume to resume playback.


Resumes sample playback after pause().


True when playback is paused. (read-only)