Search code examples
audioembeddedstm32microcontroller

How would you play sounds from a microcontroller (STM32 etc.)?


For example, how would a washing machine play a specific sound (MP3 or WAV or whatever) when finished? Which external components are needed?

I know this is a really vague question but I could not find any real solutions except some kind of MP3 player module which seems to be more "end-user friendly" instead of being used programmatically (skip and pause buttons).


Solution

  • Various beeps can be made simply by toggling a pin, but I assume your are looking for something more melodious, and without using a sound synthesiser.

    For short sound bites: you can store them in (external) memory and play them through a DAC, if your MCU has one. I put a basic implementation of this for SAMD21G-based Arduinos here; the idea is the same for all MCUs that have a DAC. If your MCU doesn't have a DAC, you can use an external one, or make a "poor man's DAC" by using PWM and low-pass filtering the output.

    Another option is creating an I2S stream from stored samples and send them to an external amplifier (module) that accepts I2S. It helps when your MCU has an I2S peripheral.

    For longer sounds, your best bet is probably playing them from a MCU-controlled MP3-player, because you need the SD-card storage or a similarly large storage anyway for large sound files.

    In all cases, you'll need an external amplifier and speaker.