Introduction
There is a kids' toy that is a pocket-sized voice/effects box. It has half a dozen buttons on the front, and whenever any button is pressed, a burst of audio is played. Such toys are cheap when released, but eventually can sell for quite a lot on ebay! I wanted to build something similar, i.e. from a birds-eye view there is nothing very original for this project, the end result is an open-sourced rip-off of the commercial products : ) See the two-minute video below for a demonstration.
Unlike the commercial toy, this project uses the Python programming language running on a Pi Pico board. It allows for kids to be able to customize the unit and to be able to easily upload their own audio files for their favorite movies/shows (for instance).
The project uses CircuitPython's MP3 playing capabilities as discussed here: . This project is similar to that, the only slight difference is that instead of using pulse width modulation (PWM) for generating the final output for the audio amplifier, this project instead uses a separate digital to analog converter (DAC), in the audio world it is known as an I2S DAC. The audio quality can hopefully be better than the commercial toy. As a result, although this project does not have hi-fi quality, it should be way better than typical kids' toys. I used MP3 files recorded from a movie, but they could be replaced with sounds from favorite kids' animations for example or musical effects. There is not a lot of memory, but several minutes of audio is feasible (perhaps more with different MP3 settings - I used the following settings: 64 kbps, 44.1 kHz, mono).
This project uses large components and is easy to solder. It shouldn't take more than half an hour to assemble it if built on the printed circuit board (PCB).
Circuit
The circuit below (click it to enlarge) consists of up to 10 push-buttons connected to the Pi Pico directly, and the digital audio output from the Pi Pico goes into a ready-made (available from Adafruit and resellers) MAX98357 board. The power source for the project can be a 9V battery; the voltage is reduced using a ready-made 5V DC-DC converter5V DC-DC converter which is pin-compatible with the traditional linear 7805 regulatorslinear 7805 regulators; either can be used with this project. The circuit shows two slide switches, SW10 SW10 and SW11SW11. Only one is required, there are two in the board layout so that the constructor can choose to fit a right-angle or vertical mount switch.
Building It
I built the prototype using lots of jumper wires, however, I have created a circuit board layout and the files are downloadable from this blog post, ready for sending to any PCB factory such as JLC PCB or Elecrow. Log on to your preferred PCB factory site, click on Upload Gerber and select the zip file that is attached to this blog post. After a few tens of seconds, the web page should update with the following type of information, and then the board can be ordered.
This is the prototype (without the PCB):
The PCB is untested, I have not built this yet. The board has space for up to 10 buttons (I figured it could also be converted into a maths toy if it had ten buttons, for instance, a maths quiz like a vocal version of Little Professor should be feasible.
The completed board fits Hammond 1593T series boxes (see the parts list for the details) along with a small speaker, or perhaps a case could be 3D-printed.
Parts List
Reference | Qty | Description |
---|---|---|
C1, C2, C3 | 3 | 47uF 16V Capacitor |
D1 | 1 | 1N5711 or any other Schottky Diode |
D2 | 1 | 5mm LED |
J1 | 1 | PP3 9V Battery Clip |
R1 | 1 | 220 ohm Resistor |
SW0 to SW9 | 10 | Tact Switch 6 x 6 mm |
SW10 | 1 | OS202013MT5QN1OS202013MT5QN1 DPDT Slide Switch Vertical (Preferred) |
SW11 | 1 | OS102011MA1QN1OS102011MA1QN1 SPDT Slide Switch (optional alternative) |
U1 | 1 | Raspberry Pi Pico |
U2 | 1 | MAX98357 I2S DAC/Amplifier Board |
U3 | 1 | R-78E5.0-0.5R-78E5.0-0.5 DC-DC Converter (Preferred), or 7805 Regulator |
SPKR | 1 | 8 ohm Speaker (e.g. 'laptop internal speaker') |
Box | 1 | Hammond 1593T series: 1593TBK1593TBK or 1593TGY1593TGY or 1593TTBU1593TTBU |
Code
See GitHub for the latest version of the source code, however a basic working example is also printed below. Line 8 contains a list of names for the audio files, this can be extended for as many buttons as are connected to the Pi. Line 10 contains the mapping to the GPIO pins, for all the buttons. The main function contains a loop that runs forever, waiting on any button to be pressed, and then playing out the associated MP3 file.
import board import audiomp3 import audiobusio import digitalio import time # file names fnames = ["1.mp3", "2.mp3", "3.mp3", "4.mp3", "5.mp3", "6.mp3"] # buttons input_gpio = [board.GP1, board.GP2, board.GP3, board.GP4, board.GP5, board.GP6] buttons = [] # other variables forever = 1 # main program def main(): global buttons print("Hello") # setup connections # create I2S output, pins order: (BCLK, FS, DATA) i2s = audiobusio.I2SOut(board.GP14, board.GP15, board.GP13) # board LED boardled = digitalio.DigitalInOut(board.GP25) boardled.direction = digitalio.Direction.OUTPUT # buttons for idx, v in enumerate(input_gpio): buttons.append(digitalio.DigitalInOut(v)) buttons[idx].direction = digitalio.Direction.INPUT buttons[idx].pull = digitalio.Pull.UP # create MP3 decoder with any file dummy = open(fnames[0], "rb") asource = audiomp3.MP3Decoder(dummy) while forever: for idx, b in enumerate(buttons): if b.value is False: # button is pressed asource.file = open(fnames[idx], "rb") start = time.monotonic() i2s.play(asource) # play the audio source while i2s.playing: pass stop = time.monotonic() print(f"Played {fnames[idx]} {stop - start} sec") main() # run main program
Uploading the Code to the Pi Pico
For the first time, hold down the only button that is on the Pi Pico, and connect the Pi Pico to your PC using a USB cable, and then release the button. A USB Storage drive letter will appear on the PC. Drag the latest CircuitPython firmware onto that drive letter, and the Pi Pico should update itself within a few seconds, and the drive name will change to CIRCUITPYTHON. From now on, the button on the Pi Pico does not ever need to be pressed at USB insertion, unless the CircuitPython firmware is being updated.
Next, drag the Pocket Scarface code.py file available from GitHub onto that drive letter, along with any MP3 files. That's it, now you can disconnect the USB connection and begin to use the project.
Summary
Using mainly off-the-shelf modules such as the Pi Pico and an I2S Audio DAC board, it is possible to make a simple toy for kids. The benefit of using the Python programming language is that hopefully kids may be encouraged to edit the code, modify the functionality, or change the audio files. As a next step, it would be interesting to rewrite the code into a different project using the same hardware - for instance if the buttons were labeled 1-10 on the enclosure, then an audio version of Little Professor could be interesting.
Thanks for reading!