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.
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
pygame.mixer.init()
pygame.mixer.music.load("myFile.wav")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
continue
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!
And you can get our latest projects and tips straight away by following us on: