Our customers build a lot of projects using embedded audio using Adafruit Audio FX boards. They're pretty much the easiest way to add sampled audio to your electronics project. I'm working on a personal project where I need to generate sound in a fairly small enclosure, and this project was the first time I'd ever used an audio trigger or sound board. While they're pretty straightforward, and Adafruit's tutorial is really helpful, there are some little gotchas that you've got to learn and work around.
Audio triggers, if you haven't heard of them before, are a really simple idea: press a button, it plays a sound. Fancy ones have multiple buttons, and fancier still ones can have loops, stop/start controls and a whole bunch more. The Audio FX boards are definitely up there in the “fancier still” category. The board attaches to a USB port and becomes a drive on which you can save samples. Eject the drive, and you've got a solid multi-sample sound trigger.
I've only got room in my project for the tiny Audio FX Mini Sound Board, but I can also (just!) fit in a tiny amplifier and flat speaker. This results in a compact and loud mono unit, all in a couple of small circuit boards.
A couple of tips I picked up from this build:
While triggers are most often used with buttons, you can trigger them from a microcontroller. Here's a simple Arduino setup to play a single sample once every fifteen seconds. I may have chosen the opening bars of “The Hampsterdance Song”, but you might wish something less annoying.
In order to trigger the sample, we need to setup a pin as an output, and hold the value high until we want the sample triggered. We then have to hold the pin low for a time (Adafruit suggest 50 ms, but I didn't find anything less than 120 ms to be reliable) and the sample will play.
/* * “Think of it, Ellen - a world that plays * ‘The Hampsterdance Song’ every 15 seconds” * * “That would be wonderful ...” */ void setup() { pinMode(7, OUTPUT); // pin 7 to Audio FX port pinMode(LED_BUILTIN, OUTPUT); // also signal built-in LED on Arduino digitalWrite(7, HIGH); // keep the trigger pin high delay(5000); // initial 5 s pause } void loop() { digitalWrite(7, LOW); // set trigger digitalWrite(LED_BUILTIN, HIGH); // set visual confirmation delay(120); // pause 0.12 seconds digitalWrite(LED_BUILTIN, LOW); // clear trigger digitalWrite(7, HIGH); // turn off visual confirmation delay(15000); // wait 15 s before next trigger }