Playing audio files on the ESP32 is possible without any external hardware, though it can be quite taxing on the device and can make multi-tasking difficult since implementation of song playback can be non-blocking. One way to avoid this is to offload this task to a secondary chip/chipset so that you can give it a command, and then get on with your life and go and time that button push or whatever. One really inexpensive chipset/board that can do this is this:
The device has a chip onboard that allows decoding of mp3-type files and a second chip on board that acts as an audio amplifier so you can directly drive a speaker at reasonable volumes.
The library to work with this chip is actually in the primary archive for Arduino (often times ones that work with the ESP32 are not, but in this case it is so Yahtzee for us). Go to Sketch>Include Library>Manage Libraries and then after that, loads search for "DFRobotDFPlayer" and select the most recent version of the library that comes up for installation.
The sketch linked here is a slightly modified version of their default example code that works with our ESP32 when it is hooked up and controlling the board using the following wiring scheme:
For reference the pins on the MP3 board are shown below:
The last step is to get a microSD Card. I grabbed a SanDisk 16GB Class 10, generically formatted it, and then dragged an MP3 file onto it on my computer. Then popped it out put it into the DFPlayer board (while powered down), turned it all on and a song started playing. If you need an mp3 file, here is "See You Again", a track off of Tyler the Creator's excellent album Flower Boy from last year where I feel he really came into his own, commercially and artistically.
When playing, the script works by receiving serial commands you send to it over the Serial monitor. Read the code and comments to figure it out...then from there you can extract the functionality you'll need for your purposes.
\ / /\__/\ \__=( o_O )= (__________) |_ |_ |_ |_Course Site powered by CAT-SOOP 14.0.4.dev5.