Build a Raspberry Pi Soundboard with Buttons and a Speaker

raspberry pi soundboard

Quick answer: A raspberry pi soundboard loads WAV clips into pygame mixer, maps one GPIO button to each clip and plays through whichever speaker you select as the audio output. Start with a USB speaker and WAV files, then add buttons.

This build centres on the audio side: choosing an output, getting samples to play on cue and fixing silence or lag. If you are new to wiring inputs, the wider set of raspberry pi gpio projects shows other ways to use the same pins.

What you need and where to start

The simplest working setup is a Raspberry Pi running Raspberry Pi OS, a handful of momentary push buttons, a speaker and a folder of WAV clips. One published soundboard project used a Raspberry Pi 3 with momentary push buttons and relied on pygame and Python 3 to play its sounds, according to its GitHub project page. That is a sensible template because it keeps the software small: Python reads the buttons and pygame mixer does the playback.

  • Raspberry Pi and Raspberry Pi OS: any model you can wire to and connect a speaker to will do. The reference project used a Raspberry Pi 3.
  • Momentary push buttons: one per sound, plus optionally a button that switches between sound categories.
  • A speaker: a USB speaker is the easiest first choice because it is a separate audio device you can select and test on its own.
  • WAV audio files: short clips in a single folder next to your script.
  • Python with pygame: pygame supplies the mixer module used for playback.

Get one button and one clip playing through your chosen speaker before you wire the rest. A single working path makes every later fault easier to place, whether it lies in wiring, code or audio output.

Choosing an audio output

You can send sound to the HDMI display, the headphone jack, a USB speaker or an audio add-on board. For a soundboard, pick the output that lets you test sound independently of the buttons, then confirm it plays a normal audio file before you write any code. One Raspberry Pi sound-clip player simply instructs you to connect the audio output to speakers or headphones and press the button, as described in the Pi sound effects player write-up.

USB speaker

A USB speaker suits most first builds. It appears as its own device, so you can switch to it in the audio settings on the desktop and leave other outputs untouched. If the Python side later seems silent, you can still rule the speaker in or out by playing any other file through it.

Red Focusrite audio interface on a white desk with cables attached, a hand touching its top, and books stacked behind it
A USB audio interface on a desk with its cables attached. Anything that presents itself as a separate audio device is selected the same way as a USB speaker.

Headphone jack and HDMI

The headphone jack is the compact route for a small powered speaker, and HDMI makes sense when the board already sits next to a monitor or TV. Both are built-in outputs, so you choose between them in the same audio output menu as a USB device. If you are building an enclosure with a dedicated speaker, the jack or a USB speaker is usually the less awkward choice than routing sound through a display.

Corner of a white PC case front panel with two USB ports, a round audio jack and a small round logo, against a black background
USB ports beside an audio jack on a PC front panel. Illustrative only: the Pi’s own sockets sit on the board edge, but the two connection types are the same.

Audio add-on boards

If you want better sound or a built-in amplifier, add-on boards from Raspberry Pi are an option. Their differences are mostly about whether you need a separate amplifier.

Board Price Notable feature Planning use
DAC+ $20 Lowest-cost audio HAT; designed for use with an external amp Pair with an amplified speaker or separate amp when cost matters most
DAC Pro $25 Highest-fidelity HAT; designed for use with an external amp Choose for sound quality if you already own an amplifier
DigiAMP+ $30 Integrated amplifier on board Suits a build where you want to avoid a separate amp
Codec Zero $20 Supports a range of audio input and output devices; has LEDs and a tactile button A low-cost board if you also want audio input or on-board indicators

Prices and descriptions come from Raspberry Pi’s announcement of its audio boards.

For a basic soundboard, a HAT is optional. It earns its place only if you are unhappy with the sound from a USB speaker or the headphone jack, or you want an amplifier integrated into the stack.

Wiring the buttons

Each button connects one GPIO pin to ground, and your code decides which sound belongs to which pin. A shared ground rail keeps the wiring tidy, because every button then needs only one signal wire back to the Pi.

How many buttons can you use?

The GPIO header offers plenty of pins, but the practical limit is how many you want to press and wire. The tabletop soundboard project arranged 12 momentary push buttons in 3 rows of 4 for playing sounds, and gave GPIO21 to a separate category-cycle button. That pattern is the useful one: rather than adding a button for every clip, let one button switch the set of sounds the others play.

Several black and silver industrial push-button boxes with red, blue, yellow, white and black buttons, mounted on a wall with cables entering from above
Coloured push buttons with a cable entering each box. Colour coding helps on a soundboard too: it lets you group related sounds by category.

For a first build, wire as many buttons as you have distinct sounds to test, and keep the category button for later. A board with a modest number of buttons that all work beats a large panel with an intermittent wire you cannot trace.

Playing sounds with pygame mixer

The pattern is: initialise the mixer, load every clip once at start-up, then call play on the matching sound when its button is pressed. In an example pygame game tutorial, each WAV file is loaded into a pygame.mixer.Sound object, and pygame.mixer.Sound.play is called from the event handler when the key goes down. Replace the key event with your button press and the structure is identical for a soundboard.

A row of brown lever-arch binders with white spine labels, including labels reading "Kunden-Rechnungen" and "2015"
Binders are grouped and labelled by category and year, a physical version of sorting files into named folders.

Mixer settings

The same tutorial re-initialised the mixer with pygame.mixer.init(22050, -16, 2, 512) and set 32 channels. Those values set a frequency of 22050 Hz, a sample size of -16, stereo output and a buffer of 512. By comparison, the pygame-menu library’s sound module defaults to the same frequency, sample size and stereo channels but a buffer of 4096. The buffer is therefore the value that differs between a lower-delay setup and a more conservative one, so it is the setting to adjust when playback timing matters.

Having many mixer channels lets several clips overlap, which is what you want on a soundboard when two buttons are pressed close together.

Initialise only what you need

On a Raspberry Pi, calling every pygame module can trigger ALSA errors. The sound player described on pablonet.dev avoids that by initialising pygame modules individually. For a button-driven soundboard with no screen, that means starting the mixer and leaving display modules alone unless you really need them.

Choosing audio files

Use WAV files for the clips triggered by buttons. The pygame example loads WAV files straight into Sound objects, and the format is uncompressed and simple, which suits short effects. The touchscreen player on pablonet.dev works with MP3 clips instead, loading a file such as Illbeback.mp3 with mixer.music.load, so MP3 can work, but through the music interface rather than the Sound objects used above.

Format matters because a bad one fails quietly. In pygame-menu’s sound code, an invalid sound format causes the sound to be disabled with an error message, not a crash. If a clip is silent while others play, convert that file to WAV before suspecting anything else. Keep clips in a single folder with clear names, so button mappings in your script stay readable.

Troubleshooting silence, lag and crackle

Work from the speaker backwards: confirm the output, then the file, then the mixer, then the buttons.

  • No sound at all: check that the speaker is the selected output on Raspberry Pi OS and that it plays some other audio. Then try a different WAV file in case the format is rejected.
  • Some clips silent: an invalid sound format disables that sound rather than stopping the program, so look for an error message at load time and convert the file.
  • ALSA errors on start-up: initialise pygame modules individually rather than all at once, as the Pi sound player does.
  • Delay between press and sound: the pygame tutorial’s author found early playback a bit laggy, with a noticeable delay, and moved to explicit mixer settings with a 512 buffer. Try a smaller buffer, changing one setting at a time.
  • Crackle or stutter: treat buffer size and channel count as the first variables to adjust, and test the same clip on another output to see whether the speaker is involved.

Change one thing per test. If you alter the buffer, the output and the file together, you will not know which change helped.

Taking the Pi further

Once the soundboard works, the same pattern of reading GPIO inputs and reacting with sound transfers to other builds. A raspberry pi weather station project reads sensors on the same header, and a soil moisture sensor raspberry pi setup could use your speaker to announce a dry reading.

Frequently asked questions

Do I need an amplifier for a Raspberry Pi soundboard?

Not for a USB speaker that is powered itself. Among Raspberry Pi’s audio boards, the DAC+ and DAC Pro are designed for use with an external amp, while the DigiAMP+ has an integrated amplifier on board.

How do I make a sound loop until I stop it?

Use the music interface for continuous audio. In the pygame tutorial, pygame.mixer.music.play(-1) loops background music continuously.

Why add a short sleep to the button loop?

A loop that checks buttons constantly keeps the processor busy. The Pi sound player adds time.sleep(0.1) on each pass to reduce CPU use.