Playback Recorder With Raspberry Pi




Posted in TechnologyRaspberry-pi

Introduction: Playback Recorder With Raspberry Pi

Hi everyone,

In this instructable I explain how I made a playback recorder using Raspberry Pi. The device is a Raspberry Pi model B+, with 7 push buttons on top, a speaker connected to one of the Pi's usb ports, and a microphone connected to another usb ports. Each button is associated to a sound, so it can play 7 different sounds. The sounds are played after a brief push of the button. To record a new sound, simply push the button for more than 1 second, record after the beep, and let go the button at the end of the record. It doesn't get any simpler than that!

Step 1: Material Needed

For this project I needed:

I also needed:

  • Some electrical wire
  • Right-angle female headers
  • Some wood, black paint and glue for the button case
  • A soldering iron and solder

Step 2: The Buttons

The buttons used are quite tall (6mm) so that they can go through the case thickness.

I placed my 7 buttons on a perma-proto board, which is like a breadboard, except components are soldered on it. This is more robust than a breadboard, and cheaper than printing a pcb. Each button links ground to a GPIO on the Raspberry Pi. I don't have resistors here since the Pi already has internal pull-up/down resistors which will be set in the program. In this case I have set them to pull-up (see program below).

The buttons are placed every 4 rows, or every 0.4 in.

Step 3: The Buttons Case

I made a very simple case for the buttons, with plywood sheets and wooden square dowel. The dowel size has to be big enough to contain the button base and board, but small enough to let the button top out of the case. I used a 1/4 in x 1/4 in dowel.

After making sure the board fits in the case, the dowels are glued to the base sheet. Holes are then drilled on the top sheet (the board can be used to precisely make marks every 0.4 inches). All wood parts are painted, the board placed in the case, and the top sheet glued on top of it.

Step 4: The Raspberry Pi

I did not want to solder the wires directly to the Pi, in case I want to use the Pi for something else in the future. I therefore soldered the wires to right-angle female headers, and plugged the headers on the Pi.

The GPIOs used are 21, 26, 20, 19, 13, 6 and 5. The ground pin is also used.

The microphone and speaker are simply plugged in 2 of the 4 usb ports.

The Pi is powered through the micro-usb outlet

Step 5: Programming

To program the Pi, I connected it to internet using an ethernet cable, and controlled it from a remote computer using VNC viewer. However, you cannot use this setup the first time you connect to the Pi, because the OS is not installed yet and SSH is not unabled. So you will need to connect a screen, keyboard and mouse, at least the first time.

It was quite a hassle to find the commands to record and play a sound on the right sound card. These are the commands that worked for me:

  • aplay -D plughw:CARD=Device_1,DEV=0 0.wav
    • Plays 0.wav
  • arecord 0.wav -D sysdefault:CARD=1 -f cd -d 20
    • Records for maximum 20 seconds in file 0.wav, with cd quality

The sound files are located in the default directory (/home/pi). A sound file for the beep is also necessary, placed in the default directory and called beep.wav.

The python code itself is the following:

python code for a Raspberry Pi playback recorder

import RPi.GPIO as GPIO
import time
import os
butPressed = [True, True, True, True, True, True, True]#if button i is pressed, then butPressed[i] is False
pin = [26, 19, 13, 6, 5, 21, 20]#GPIO pins of each button
recordBool = False#True if a record is in progress
for i in range(0, 7):
GPIO.setup(pin[i], GPIO.IN, pull_up_down=GPIO.PUD_UP)#sets Pi's internal resistors to pull-up
while True:
for i in range(0, 7):
butPressed[i] = GPIO.input(pin[i])#checks if a button is pressed
if butPressed[i] == False:#if a button is pressed
previousTime = time.time()
while butPressed[i] == False and recordBool == False:
butPressed[i] = GPIO.input(pin[i])
if time.time() - previousTime > 1.0:#if the button is pressed for more than a second, then recordBool is True
recordBool = True
if recordBool == True:#if recordBool is True, it plays a beep sound and then records
os.system("aplay -D plughw:CARD=Device_1,DEV=0 beep.wav")
os.system("arecord %d.wav -D sysdefault:CARD=1 -f cd -d 20 &" %i)#records for maximum 20 seconds in file i.wav, with cd quality
while butPressed[i] == False:
butPressed[i] = GPIO.input(pin[i])
os.system("pkill -9 arecord")#the record is stopped when the button is let go, or after 20 seconds
recordBool = False
else:#if recordBool is False, it plays sound i.wav
os.system("aplay -D plughw:CARD=Device_1,DEV=0 %d.wav" %i)

Step 6: Run the Python Script at Each Startup

To run the python script at each Pi's startup, the following lines are put in a file called playback.desktop in folder /home/pi/.config/autostart/

runs at Raspberry Pi's startup

[Desktop Entry]
Comment=This is a playback application
Exec= python /home/pi/
view rawplayback.desktop hosted with ❤ by GitHub

Step 7: End Note

Please tell me what you think of this project in the comment section, let me know of your recommendations, and vote for me in the Raspberry Pi contest if you liked it.

Looking forward to reading you!



    • Spotless Contest

      Spotless Contest
    • Microcontroller Contest

      Microcontroller Contest
    • Space Challenge

      Space Challenge

    We have a be nice policy.
    Please be positive and constructive.




    Awesome project! I feel like I could have use for something like this once it gets a little closer to April Fools Day. Been wanting to build a discreet playback device to 'haunt' a friend. :P