Raspberry Pi Soundboard


PI Soundboard is first gen Raspberry Pi running Raspbian OS with functionality provided by a small Python script. Pushing each of the five buttons will play a different MP3 sound-byte. The speakers and circuitry are taken from a pair of Logitech PC speakers. Both the speakers and Pi are powered by a 5v 3A DC power supply.


These five GI Joe figures are my favorites from the 80s public service announcements that were on during the Saturday morning cartoons. Each character has an important public safety message that will play when the corresponding button is pressed.

The software uses the Python Gpiozero libray to interface with the buttons and LEDs. The PyGame library makes it easy to play MP3s. This system makes it easy to add new sound clips or even copy to a entirely different theme soundboard.

Now you know, and knowing is half the battle!

Source:

import pygame # Make playing MP3s easy import os import sys import time from time import sleep from random import randint from gpiozero import Button from gpiozero import LED # GPIO MAPPINGS: green_led = LED(4) red_led = LED(17) button1 = Button(8) # Mutt button2 = Button(10) # Doc button3 = Button(25) # Blowtorch button4 = Button(9) # Snowjob button5 = Button(24) # Roadblock button6 = Button(11) # Gungho switch_random = Button(23) switch_clean = Button(18) # SOUND CLIPS: random_sounds = [ "./mp3/blowtorch/porkchop_sandwiches.mp3", "./mp3/doc/first_dibs.mp3", "./mp3/gungho/hey_whats_up.mp3", "./mp3/mutt/help_computer.mp3", "./mp3/roadblock/lets_launch.mp3", "./mp3/snowjob/get_off_my_ice.mp3", ] button_sounds = [ "./mp3/mutt/mutt_full.mp3", "./mp3/doc/doc_full.mp3", "./mp3/blowtorch/blowtorch_full.mp3", "./mp3/snowjob/snowjob_full.mp3", "./mp3/roadblock/roadblock_full.mp3", "./mp3/gungho/gungho_full.mp3", ] def main(): # Set working directory: os.chdir(os.path.dirname(sys.argv[0])) # init pygame: pygame.mixer.init() pygame.mixer.music.set_volume(1.0) # Play sound to indicate system is ready: play_sound("./mp3/common/gijoe.mp3") is_running = True last_event_time = time.time() # So we know when to play a random sound while is_running: # I JUST WANT TO RUN! if button1.is_pressed: button_press(1) last_event_time = time.time() elif button2.is_pressed: button_press(2) last_event_time = time.time() elif button3.is_pressed: button_press(3) last_event_time = time.time() elif button4.is_pressed: button_press(4) last_event_time = time.time() elif button5.is_pressed: button_press(5) last_event_time = time.time() elif button6.is_pressed: last_event_time = time.time() button_press(6) last_event_time = time.time() # If the random clip switch is on, and it's been 1 min since last event: if switch_random.is_pressed and time.time() - last_event_time > 60: play_random_sound() last_event_time = time.time() # Flash green light to indicate everything is still running: green_led.on() sleep(.1) # don't rail the cpu green_led.off() sleep(.1) def play_sound(filename): try: print("Playing file " + filename) green_led.on() # Play the sound: pygame.mixer.music.load(filename) pygame.mixer.music.play() # Wait for the sound to stop playing: while pygame.mixer.music.get_busy() == True: sleep(0.1) green_led.off() red_led.off() # turn this off now in case it was on previously except: red_led.on() # Flag something is wrong def button_press(button_number): # Make sure the button number is valid: if button_number < 1 or button_number > len(button_sounds): print("Invalid button number " + str(button_number)) red_led.on() return print("Button " + str(button_number) + " is pressed") play_sound(button_sounds[button_number - 1]) def play_random_sound(): print("Time to play random sound") index = randint(0, len(random_sounds) - 1) play_sound(random_sounds[index]) # Do the program now: main()