text: My sound effect box basically consists of twelve buttons, two speakers, a raspberry pi, a box (I printed it on a 3d printer.) and many jumper cables. I couldn't find a battery to put in and used raspberry's cable to plug in. There are twelve buttons to press and hear a sound.
  Step 1: Download Sound Samples Into Raspberry Pi
  Before playing sounds, we need to download sound samples.
  Follow this to download them:
  1- Open a Terminal window from the desktop or application menu.
  2- Type the command "ls" (You should see the files and folders which are in your home directory.)
  3- Create a new folder called "musicbox" with this command: mkdir musicbox
  4- Enter the folder with this command: cd musicbox
  5- Make a copy of Sonic Pi's sound samples folder with this command: cp -r /opt/sonic-pi/etc/samples/ . (Don't forget dot (" .") )
  6- Type "ls" and you'll see the samples folder has been copied over. Type "ls samples" and you'll see a list of ".flac" audio files inside that folder.
  7- The .flac format is fine for Sonic Pi, but to use them in Python you'll need to convert them to ".wav" files. First, you'll need to switch into the samples directory, by typing: "cd ~/musicbox/samples"
  8- Now you can use "avconv" to convert all the files. This line of bash converts the file from ".flac" to ".wav" and keeps the same base file name: "for f in *.flac; do avconv -i "$f" "${f%.flac}.wav"; done"
  9- Lastly, you can remove the ".flac" files from the copy of the samples directory with that line: "rm *.flac"
  Step 2: Box Design and Printing
  I designed my box on "123D Design" (You can use another program like Fusion or Tinkercad.) and printed it on a 3d printer. I made a basic design but you can make futuristic designs or you can use other boxes. For example, my first prototype was a cardboard box.
  Warning: Be careful about lengths and leave space for cables.
  Step 3: Connect Buttons to Raspberry Pi
  We need to a connection between buttons and Raspberry Pi. You can use "" to look pin numbers. I connected them to this pins: BCM 2, BCM 3, BCM 4, BCM 17, BCM 27 BCM 22, BCM 10, BCM 9, BCM 11, BCM 0, BCM 5, BCM 6, and I just soldered cables to buttons. Buttons must be connected to ground. I used only one ground and connected it to all buttons using a breadboard. You can see my schema above.
  Step 4: Program It With Python 3
  These are my codes:
  ##Warning: There is a problem about Tab and be careful about spaces when you are writing that.
  import pygame.mixer
  from pygame.mixer import Sound
  from gpiozero import Button
  from time import sleep
  from signal import pause
  pygame.mixer.init()
  button_sounds = { Button(2): Sound("samples/tabla_tun1.wav"),
  Button(3): Sound("samples/guit_e_fifths.wav"),
  Button(4): Sound("samples/ambi_choir.wav"),
  Button(17): Sound("samples/drum_cymbal_closed.wav"),
  Button(27): Sound("samples/bd_klub.wav"),
  Button(22): Sound("samples/vinyl_backspin.wav"),
  Button(10): Sound("samples/elec_pop.wav"),
  Button(11): Sound("samples/perc_snap2.wav"),
  Button(0): Sound("samples/misc_burp.wav"),
  Button(9): Sound("samples/tabla_na_o.wav")
  Button(5): Sound("samples/drum_tom_mid_hard.wav")
  Button(6): Sound(""samples/elec_hi_snare.wav"")
  }
  for button, sound in button_sounds.items():
  button.when_pressed = sound.play
  ##You can play with codes and change button numbers or sound samples.
  2 Discussions
  Question 10 months ago on Step 4
  Hi! Nice tutorial!
  I want to install a button that when pressed stop all sound. Can u post the code? Have u a suggestion? Thx
  1 year ago
  exactly what I've been struggling with. my only problem is that it just seems to run and quit, am i missing something?