Skip to content

Instantly share code, notes, and snippets.

@idriszmy
Created April 12, 2021 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idriszmy/ef02d96831e4e72f85e0673e0da79a7f to your computer and use it in GitHub Desktop.
Save idriszmy/ef02d96831e4e72f85e0673e0da79a7f to your computer and use it in GitHub Desktop.
Play MP3 File on Maker Pi Pico Using CircuitPython
import time
import board
import digitalio
from audiomp3 import MP3Decoder
try:
from audioio import AudioOut
except ImportError:
try:
from audiopwmio import PWMAudioOut as AudioOut
except ImportError:
pass # not always supported by every board!
button1 = digitalio.DigitalInOut(board.GP20)
button1.switch_to_input(pull=digitalio.Pull.UP)
# 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")
audio.play(decoder)
print("playing", mp3files[0])
t = time.monotonic()
while time.monotonic() - t < 3:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment