Created
April 12, 2021 14:48
-
-
Save idriszmy/ef02d96831e4e72f85e0673e0da79a7f to your computer and use it in GitHub Desktop.
Play MP3 File on Maker Pi Pico Using CircuitPython
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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