# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
CircuitPython I2S WAV file playback.
Plays a WAV file once.
"""
import audiocore
import board
import audiobusio
audio = audiobusio.I2SOut(board.A0, board.A1, board.A2)
with open("StreetChicken.wav", "rb") as wave_file:
wav = audiocore.WaveFile(wave_file)
print("Playing wav file!")
audio.play(wav)
while audio.playing:
pass
print("Done!")
Now you'll hear the wave file play, and on completion, print Done Playing! to the
serial console.
You can play a different WAV file by updating "StreetChicken.wav" to be the name
of your CircuitPython-compatible WAV file.
You can do other things while the WAV file plays! There is a pass in this example
where you can include other code, such as code to blink an LED.
CircuitPython I2S-Compatible Pin Combinations
I2S audio is supported on specific pins. The good news is, there's a simple way to find
out which pins support audio playback.
In the example below, click the Download Project Bundle button below to download
the necessary libraries and the code.py file in a zip file. Extract the contents of the zip
file, open the directory CircuitPython_Templates/i2s_find_pins/ and then click on the
directory that matches the version of CircuitPython you're using and copy the
contents of that directory to your CIRCUITPY drive.
Your CIRCUITPY drive should now look similar to the following image:
©Adafruit Industries Page 179 of 263