Saturday, May 10, 2014

Microphone and speaker set up

Now that you have your camera set up and functional, lets get the setup parts out of the way.

First, I'll walk you through the speakers set up.
This should be simple - simply plugin the speakers (3.5mm) cable in to the pi, and that should be it.

To verify that your speakers work, SSH in to your rPi, and type speaker-test
That should immediately start producing white noise from your speakers.

Just for kicks, I would also try the following command:
aplay /usr/share/scratch/Media/Sounds/Vocals/Singer2.wav

aplay is the default audio player (for playing wav files, mp3s etc), and Singer2 is one of the default files that comes installed on the pi :)

Now that you have your speakers set up (leave a comment if for some reason your speakers aren't working), time to set up the mic.
Shutdown your pi (Remember sudo shutdown now) and plugin the USB microphone. Restart your pi, ssh back in to it, and time to get to work.

First, lets change a setting in alsa (Advanced Linux Sound Architecture).
Type sudo nano /etc/modprobe.d/alsa-base.conf
Change the line that says "options snd-usb-audio index=-2" to "options snd-usb-audio index=0"
Then, Ctrl+O to save, Ctrl+X to exit.
Reload alsa by typing sudo alsa force-reload
Reboot your pi (sudo reboot)

Now, ssh back in to your pi
Enable the USB microphone by typing sudo modprobe snd_bcm2835
Now, try recording by typing arecord -f S16_LE -D hw:0,0 -r 48000 test.wav
And, play it back by typing aplay test.wav

Now, your audio might have recorded but is very very faint/weak. To increase the audio capture volume, type alsamixer
Press F6 so as to select the USB sound card, and increase the "capture gain" using the arrow keys.
Save your settings by typing sudo alsactl store

Note: You may have to try several times before you can actually get the "ideal gain" for your microphone.

Here is a photo of the final set up. To capture your attention and remind you how cool this project will end up being, the next post will deal with setting up the voice recognition using Jasper and will include fun apps and videos :)


The left corner (behind the speakers) is a cardboard box with the pi and USB hub in it (until I can learn and afford to make my own 3D printed packaging). At the top of the box you see the little camera peeking out. On the bottom right corner you can see the USB microphone. This will be the final set up for the voice recognition + motion detection project.

No comments:

Post a Comment