Introduction: Arduino Becomes Talking Tom
One of my oldest memories of using a smartphone was playing the 'Talking Tom' game. The game was pretty simple. There is a cat, named Tom, which can talk, sort of. In the game, Tom would listen for any input through the phone's mic and then repeat whatever it heard. So, whatever say to Tom, it would just repeat that same thing in its own shrill voice.
While it sounds simple, this whole procedure requires many complex steps like sampling the mic analog input in digital form, manipulating the audio in order to give Tom its unique voice and then reconstructing the signal from all those digital values to play it back through the speaker. All these complex steps, but the smartphone handled it like a charm even 9 to 10 years back!
The interesting thing would be to see if the same can be done with a cheap microcontroller based Arduino board. So, in this instructable I will be showing how you can make a simple Talking Tom like project from an Arduino and some other inexpensive electronics.
This instructable was written in collaboration with Hatchnhack Makerspace in Delhi
NOTE: This instructable is the first version of the project which completes the 'Talking' feature of Talking Tom where the arduino will be able to to repeat whatever you say to it. The voice changing part will be covered in the future version, although, due to less resolution of Arduino's in built ADC the recorded audio already sounds a bit different :P (This can be clearly noticed in the project video).
So Let's Start!
Step 1: Materials Used
- An Arduino UNO
- MAX4466 microphone module with Adjustable Gain
- SPI based SD Card Reader module
- SD card
- Audio Amplifier like PC speaker, PAM8403 amplifier module, etc.
- Speakers for connecting to the Amplifier
- Female Audio Jack
- 1 x 1k ohm resistor
- 2 x 10k ohm resistor
- 1 x 10uF Capacitor
- 2 x Push Button
- Jumper Wires
- Arduino IDE
- TMRpcm and SD library for Arduino
Step 2: A Basic Overview of the Project
The project mainly has 2 features:
- It can play a randomly chosen audio from a set of pre-installed audio files in the SD card for sound effects etc.
- It can record sound input from the microphone and then play it back as soon as the recording stops. This allows the arduino to repeat whatever it heard through the mic.
The User Interface of the project mainly consist of 2 push buttons each of which correspond to one of the above feature.
The main hard work of recording and playing of the audio files from the SD card is handled by the TMRpcm library.
The audio recording makes use of the MAX4466 mic module, arduino's internal ADC and the TMRpcm library to sample the audio and then temporarily store it in the SD card as '.wav' file for playback. '.wav' audio files use PCM (Pulse Code Modulation) to store the audio data in the digital format so that it can be easily played again. Generally, it is better to use an external ADC for audio based projects as the resolution of Arduino's ADC is not that high but it works for this project.
Playing of the audio files(pre-installed & recorded) is also done with the help of the TMRpcm library which outputs the audio as a PWM signal from a PWM enabled pin of the arduino. This signal is then fed into an RC filter to get analog signal which is then fed into an amplifier for playing the audio through a speaker. For this part you could also use an external DAC as arduino does not have one internally. Using a DAC might be a better option as it would significantly improve the audio quality.
The communication between the SD card module and arduino is done through SPI (Serial peripheral Interface). The code, makes use of the SD & SPI library to easily access the contents of the SD card.
Step 3: Prepare the SD Card & Connect the SD Card Module
- First you have to format as the SD card with a FAT16 or FAT32 file system (You can use your smartphone to format the SD card).
- Now pre-install some .wav audio files in the SD card. You can generate .wav files with Audacity (see the instructions below). Remember to the name the files as audio_1.wav, audio_2.wav, audio_3.wav and so on.
The SD card module uses SPI to communicate the data with the arduino. Therefore, it connects to only those pins which have SPI enabled. These connections are as follows:
- Vcc ---> 5v
- GND ---> GND
- MOSI (Master Out Slave In) ---> pin 11
- MISO (Master In Slave Out) ---> pin 12
- CLK (Clock) ---> pin 13
- SS/CS (Slave Select/Chip Select) ---> pin 10
Generating '.wav' file with Audacity Software:
- Open the audio file you want to convert to .wav in Audacity.
- Click on the file name and then select 'Split Stereo to Mono'. This option splits the stereo audio into two mono channels. You can now close one of the channel.
- Change 'Project Rate' value in the bottom to 16000 Hz. This value corresponds to the max sampling frequency of arduino's internal ADC.
- Now got to File->Export/Export as WAV.
- Choose the appropriate location and name of the file. From the encoding menu select 'Unsigned 8-bit PCM' as we are using the PCM format to store the audio in digital format.
Step 4: Connect the Audio Output & Microphone
Connecting the Microphone:
- Vcc ---> 3.3v
- GND ---> GND
- OUT ---> A0 pin
- Try to connect the microphone directly to the arduino instead of using a breadboard as it might induce unnecessary noise in the input signal.
- Make sure to cleanly solder the headers on the microphone module as bad solder joints also produce noise.
- This microphone module has adjustable gain which can be controlled with the help of a pot in the backside of the board. I would suggest you to keep the gain somewhat low as then it won't amplify the noise very much while you could speak keeping it near your mouth resulting in a cleaner output.
Connecting the Audio Output:
- Place the 10 uF Capacitor and the 1k ohm resistor in series on the breadboard with the positive of the capacitor connected to the resistor. These together form an RC filter which convert the PWM output to analog signal that can be fed into the amplifier.
- Connect the pin 9 of Arduino to the other end of the resistor.
- The negative terminal of the Capacitor gets connected to the left and right channel of the female audio jack.
- GND of the Audio jack gets connected to the GND.
- Audio jack is connected to the amplifier with an Aux Cable. In my case I used my PC's Speaker System.
- Using PWM as the audio output might not be the best option as an external DAC would provide much better resolution and quality. Additionally, the capacitor and resistor in the RC filter may induce unwanted noise. But still the output was pretty decent for this project.
Step 5: Wire Up the Buttons
The project uses to push buttons as the user interface. Both perform different functions and are used differently but have the same wiring. Their connection is as follows:
- Place the buttons on the breadboard.
- Attach one terminal of one of the button to pin 2 of the arduino with a 10k ohm pull down resistor. The other terminal of the button gets connected to 5v. So, when button is pressed the pin 2 gets HIGH and we can detect that in the code.
- The other button gets connected the same with arduino's pin 3 instead of 2.
The button connected to pin 2 plays a random audio file from the set of pre-installed audio files on the SD Card when it is pressed once.
The button connected to pin 3 is for the recording. You have to press and hold this button for the recording. The arduino starts recording as soon as this button is pressed and stops the recording when this button is released. After stopping the recording, it immediately replays that recording.
Step 6: Upload the Code
Before uploading the code, make sure you have installed all the required libraries like TMRpcm, SD etc.
You can also open the Serial Monitor after uploading the code to get a feedback of what the arduino is doing.
Currently the code is not manipulating the recorded audio to make it sound different but I plan to include this feature in the next version where you might be able to set the output frequency of the audio signal with the help of pot and get different types of sounds.
And You Are Done!!
Participated in the
Audio Challenge 2020