Raspberry Pi Zero with Speaker pHAT play recorded sounds

I am building a retirement project for a colleague and would like to put together a Speaker pHAT and Raspberry Pi Zero that plays back audio clips from a SD card when an emergency stop button is pressed. It will need to be battery powered and small enough to fit in the base of the button enclosure.

Any assistance with a parts list and pointers on what programming needs to be done would be greatly appreciated.

Obviously need power (battery), on/off switch, audio to an internal speaker and connectivity to the “big red button”…

Hey Stuart,

That sounds like a great project!

We don’t stock the Speaker pHAT anymore, so if you are looking to buy one you should check out the replacement, the Pimoroni Pirate Audio Speaker for Raspberry Pi. It’s perfect for making a tiny radio, sound effect player or games console!

Regarding playing audio files, I recommend the Pygame library. I may be wrong, but I believe that it is pre-installed on the Pi. You can use the Pygame Mixer Music Module to play audio files. I have included an example code below (for if you had a file named myFile.wav)O

import pygame
while pygame.mixer.music.get_busy() == True:

For the button that will activate the sound, I’d look into the Big Dome Push Button. It sounds like the ideal size/shape/design for what you’re looking for!