File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import board
2+ import digitalio
3+
4+ from audiomp3 import MP3Decoder
5+
6+ try :
7+ from audioio import AudioOut
8+ except ImportError :
9+ try :
10+ from audiopwmio import PWMAudioOut as AudioOut
11+ except ImportError :
12+ pass # not always supported by every board!
13+
14+ button = digitalio .DigitalInOut (board .A1 )
15+ button .switch_to_input (pull = digitalio .Pull .UP )
16+
17+ # The listed mp3files will be played in order
18+ mp3files = ["begins.mp3" , "xfiles.mp3" ]
19+
20+ # You have to specify some mp3 file when creating the decoder
21+ mp3 = open (mp3files [0 ], "rb" )
22+ decoder = MP3Decoder (mp3 )
23+ audio = AudioOut (board .A0 )
24+
25+ while True :
26+ for filename in mp3files :
27+ # Updating the .file property of the existing decoder
28+ # helps avoid running out of memory (MemoryError exception)
29+ decoder .file = open (filename , "rb" )
30+ audio .play (decoder )
31+ print ("playing" , filename )
32+
33+ # This allows you to do other things while the audio plays!
34+ while audio .playing :
35+ pass
36+
37+ print ("Waiting for button press to continue!" )
38+ while button .value :
39+ pass
You can’t perform that action at this time.
0 commit comments