Skip to content

Instantly share code, notes, and snippets.



Created Apr 12, 2021
What would you like to do?
Play MP3 File on Maker Pi Pico Using CircuitPython
import time
import board
import digitalio
from audiomp3 import MP3Decoder
from audioio import AudioOut
except ImportError:
from audiopwmio import PWMAudioOut as AudioOut
except ImportError:
pass # not always supported by every board!
button1 = digitalio.DigitalInOut(board.GP20)
# Replace with your mp3files name
mp3files = ["Selamat.mp3"]
# You have to specify some mp3 file when creating the decoder
mp3 = open(mp3files[0], "rb")
decoder = MP3Decoder(mp3)
audio = AudioOut(board.GP18)
while True:
if not button1.value:
decoder.file = open(mp3files[0], "rb")
print("playing", mp3files[0])
t = time.monotonic()
while time.monotonic() - t < 3:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment