Wednesday, October 2, 2013

Step by step guide - Beagle Bone Black voice recognition on an LED matrix

So after I made a BeagleBone black output voice recognition to an LED Matrix, I thought I will post a "How-to" guide to make one yourself.

NOTE: If at any point you find yourself confused with a technical term, try to google it, if you are still having trouble, or you would like to make things more clear about this post, add a comment and I will follow up on it :)

First, Materials, Make sure you have all of these when you start:
1. BeagleBone Black
2. USB Audio card  - I narrowed it down for you (1$-3$)
3. Microphone - the smaller the better
4. MicroSD card 8GB
5. AdaFruit I2C LED Backpack - I used green.
6. Male - Female Jumper wire - You will need at least 4 wires
7. Internet connection - I used a LAN cable to keep it simple.

Step 1: Setting up the Angstrom distro on the Beagle
Use this tutorial to create an Angstrom image on the MicroSD card http://learn.adafruit.com/beaglebone-black-installing-operating-systems/windows
Next, plug the card into the Beaglebone and Boot to the new OS, make sure you have the USB cable connected.
Once all this is done, open up your com port and login as root. once you get a shell proceed to the next step.

Step 2: Setting up pocket sphinx 
Plug in the LAN cable to your BeagleBone, if you have WiFi good for you, just use a hub to have the USB audio enabled later.
Follow these steps:

  1. run opkg update
  2. opkg install python-distutils
  3. From here (https://groups.google.com/forum/#!topic/beagleboard/aBznzq_bNuU) follow these steps:
    1. Install libasound2, alsa-dev, alsa-lib-dev (http://www.angstrom-distribution.org/repo/) before compiling sphinxbase and pocketsphinx.
    2. Get sphinxbase-0.8, and pocketsphinx-0.8 from http://cmusphinx.sourceforge.net/ and extract the tar files.           http://downloads.sourceforge.net/project/cmusphinx/sphinxbase/0.8/sphinxbase-0.8.tar.gz       http://downloads.sourceforge.net/project/cmusphinx/pocketsphinx/0.8/pocketsphinx-0.8.tar.gz
    3. Change directory to the sphinxbase directory.
    4. Run "./autogen.sh" to generate the configure file.
    5. If needed run "./configure" 
    6. Run "make"
    7. Run "make install"
    8. Change directory to pocketsphinx directory and redo steps 4, 5, 6, 7.
  4. To check if the pocket sphinx installation worked power off the BeagleBone, make sure the USB audio card is plugged in and power on.
  5. run this command to do a quick test:
    "pocketsphinx_continuous -adcdev hw:1,0 -nfft 2048 -samprate 48000 2>/dev/null"
            note: hw:1,0 is the hw node of your usb audio.
Step 3: Setting up the environment for the AdaFruit LED Backpack
To setup the adaFruit libs and files
1. run "opkg install python-pip python-setuptools python-smbus"
2. run "pip install Adafruit_BBIO"

Step 4: Connect the LED Backpack to the BeagleBone
Switch P8 and P9, the person who created this image mixed them up. 
We will only use the left side header (P8 in this photo)

Connect the LED Backpack like this:
LED Backpack VCC --> PIN 7 SYS_5V
LED Backpack GND --> PIN 1 DGND
LED Backpack SDA --> PIN 20 I2C2_SDA
LED Backpack SCL  --> PIN 19 I2C2_SCL















Step 5: Setting up the code
Copy these files over to your BeagleBone, I put them on my ~/Desktop/ but you can choose wherever.
  1. Adafruit_LEDBackpack.py - From AdaFruit RaspberryPi example code
    https://docs.google.com/file/d/0B4cQqo_E3D-iS19rcnR1ZnpYVDg/edit?usp=sharing
  2. Adafruit_I2C.py - From AdaFruit RaspberryPi example code, Modified to use I2C 1 on the BeagleBone.
    https://docs.google.com/file/d/0B4cQqo_E3D-iUTh0VFZidDBXSVk/edit?usp=sharing
  3. Adafruit_8x8.py - From AdaFruit RaspberryPi example code.
    https://docs.google.com/file/d/0B4cQqo_E3D-idnRDY2ZybU5mdUU/edit?usp=sharing
  4. runVisibleVoice.py - My code to run PocketSphinx and to display the output on the LED Backpack
    https://docs.google.com/file/d/0B4cQqo_E3D-iVFdwUlVNa0lLTzQ/edit?usp=sharing
Once copied, simply run "python runVisibleVoice.py" and watch the magic :)

Feel free to modify my code in any way you want, but do not use it to make money. 
Share it, Don't sell it.

Here is a picture of my final version: