This instructable guides you through connecting a Raspberry Pi to Watson Speech to Text and change the color of a LED through speech. For example, you may say "Turn the light green" to change the color of the LED to green.
Step 1: Parts
Step 2: Prepare Your Pi
If you have used Raspberry Pi before, install Node.js and the Alsa packages and go to the next step. Otherwise, follow the instructions below to set up your Pi:
Getting Started with Your Pi
Raspberry Pi is similar to a full computer, which means you need a monitor, mouse, and keyboard for it. If you have a TV around, you can connect your Pi to your TV via a HDMI cable. In most of the Pi kits, the SD card is already preloaded with an image of the Raspberry Pi Operating System. You need to put the SD card in the Pi, turn the Pi ON and follow the instructions on screen to complete the installation of the operating system. If you have problems setting up your Pi, you can troubleshoot here.
Open a terminal application on the Pi and execute the following commands to install the latest version of Node.js and npm (Node Package Manager). You need these packages later to run your code.
sudo apt-get update sudo apt-get dist-upgrade curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - sudo apt-get install -y nodejs sudo apt-get install alsa-base alsa-utils libasound2-dev
Step 3: Assemble TJBot
Here is a quick video of how to fold the kit. The detailed instructions are available on another instructable: Build TJBot out of Cardboard
Once your TJBot is ready, get ready to connect your LED to the Pi Pins.
It's very important to make sure you connect the LED to the right pins, otherwise you may damage your LED or the Pi.
ALWAYS start with the GND pin. GND is the longest leg of your LED. The LED has a flat side. The GND is the second leg from the flat side. Again if you are unsure, DO NOT connect the LED to the Pi.
Connect the GND to GND pin on the pi (see the picture). Then connect 'Data in', the 4th leg from the flat side, to the Pi's GPIO pin. Lastly, connect the third leg from the flat side to the 3.3V on the Pi.
Step 4: Download the Sample Code
The sample code is available at github. Download or clone the sample code and execute the following commands from a terminal to install its dependencies.
Here are the instructions for how to clone a repository from github if you have not done that before.
git clone https://github.com/ibmtjbot/tjbot.git cd tjbot/recipes/speech_to_text npm install
Step 5: Update Your Credentials
In this step, we help you get API access to the Watson Speech to Text. Let's start with creating a Speech to Text instance on Bluemix (If you don't have a Bluemix account, follow the instructions to create a free trial).
You may leave the default values and select 'Create'.
Almost done! You just need to copy your credentials to the clipboard.
Click on 'Sevice Credentials' on the left menu and copy your credentials into the clipboard.
Now go to the speech_to_text folder and make a copy of the default config file.
cp config.default.js config.js
Open config.js file using your favorite text editor and update it with your username and password.
Step 6: Run the Code
Once done with testing the LED, you can run the main module:
sudo node stt.js
Now talk to your microphone to change the color of the LED.
Say "Turn the light blue" to change the light to blue. You can try other colors: yellow, green, orange, purple, magenta, red, blue, aqua, white). You can either say "Turn the light on" or "Turn the light off"!
Is the LED not lighting up? No worries, we can fix it.
You may test your LED setup to make sure the connections are correct and the library is properly installed. When you run the test module, it should turn your LED on.
cd tjbot/bootstrap/tests npm install sudo node test.led.jsIf the LED does not light up, you can try moving the power from 3.3 to 5 volts. If neither the 3.3v or 5v pins work, you will need a 1N4001 diode. The diode is inserted between the power pin of the LED (the shorter of the two middle pins) and the 5v pin on the Raspberry Pi. If you have problems with the setup, please refer to Adafruit's Neopixel on Raspbeery Pi guide to troubleshoot.
The LED library uses the PWM module (GPIO 18) to drive the data line of the LEDs. This conflicts with the built-in audio hardware, which uses the same pin to drive the audio output. Depending on your configuration of Raspbian, the sound drivers may be more aggressive in taking away control of GPIO 18 from other processes. If your LED shows random colors instead of the expected color, use this trick to fix it.
sudo cp blacklist-rgb-led.conf /etc/modprobe.d/ sudo update-initramfs -u
Reboot and confirm no "snd" modules are running by executing the command "lsmod".
Enjoy! Don't forget to share a picture/video of your setup #TJBot! :-)
Step 7: What's Next?
You can add new colors to your color palette in stt.js. TJBot uses a NeoPixel RGB LED, which means it can show any combination of red, green, and blue.
We have hidden a disco party for you. Find the code for disco party in stt.js and uncomment the code. Now you can ask TJBot to show you the disco lights by saying "Let's have a disco party"!
Try implementing your own TJBot party and share it with us #TJBot!
Once ready to move on, try the next recipe to make TJBot respond to emotions using Watson.