The Sound Files

The PyPortal can play WAV files rather easily using the onboard speaker or adding a larger speaker for a bigger sound. There are plenty of places to download WAV files or you can make your own and save them as a WAV.

You will want to place all of your sound files into a folder named sounds on your CIRCUITPY drive.

There is already a really good guide on how to make CircuitPython compatible audio files at the link below.

Playing Sound

The PyPortal library makes it very easy to play sounds using the PyPortal.play_file() function.

For this example we will be setting up three sound file locations so that we can easily change what sound we want to play. We will mostly be using sounds that relate to buttons being pressed in the UI.

# ---------- Sound Effects ------------- #
soundDemo = '/sounds/sound.wav'
soundBeep = '/sounds/beep.wav'
soundTab = '/sounds/tab.wav'

pyportal.play_file(soundDemo)

This guide was first published on Feb 10, 2020. It was last updated on Mar 28, 2024.

This page (Sounds) was last updated on Mar 08, 2024.

Text editor powered by tinymce.