This instructable guides you through connecting a Raspberry Pi to Watson conversation services and making a talking robot. You will use (1) Watson Speech to Text to convert your voice to text, (2) Watson Conversation to process the text and calculate a response, and (3) Watson Text to Speech to talk the response back.
Step 1: Parts
Step 2: Set up your Pi
If you have used Raspberry Pi before, install Node.js 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.
Connect Your Pi to the Internet
Open a terminal and type the following command to edit the configuration file with your wifi information:
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
Go to the bottom of the file and add the following:
network={ ssid="Name_of_your_wifi_network" psk="Your_wifi_password" }
Now save the file by pressing Ctrl+X then Y, then press Enter. Open a browser and check if your Pi is connected to the Internet. If you have problems, troubleshoot here.
Install Packages
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 <a href="https://deb.nodesource.com/setup_6.x"> <a href="https://deb.nodesource.com/setup_6.x"> https://deb.nodesource.com/setup_6.x </a> </a> | sudo -E bash - sudo apt-get install -y nodejs
Step 3: Hardware setup
Assemble TJ Bot. Here is a quick video of how to fold the kit.
Once your TJ Bot is ready, plug in your USB microphone and the speaker.
Depending on which audio output source you are using with your Pi (HDMI or 3.5mm audio jack), you may need to set the audio config. To do this, go to the terminal and open up raspi-config.
sudo raspi-config
This will open up the Raspberry Pi configuration screen:
Select “Advanced Options” and press Enter, then select “Audio” and press Enter. Choose the correct channel for the output audio. If you have connected an external speaker to the audio jack, you should select 3.5mm jack.
Step 4: Download the sample code
The source code is available at GitHub. Download or clone the code and execute the following commands from a terminal to install its dependencies as well as the ALSA package for audio recording.
sudo apt-get install alsa-base alsa-utils cd recipes/conversation npm install
Step 5: Update your credentials
In this step, we help you get API access to three Watson conversation services.
You will use three types of Watson services in this recipe: (1) Watson Speech to Text, (2) Watson Conversation, (3) Watson Text to Speech. You need to copy your credentials for all these services.
Let’s start with creating a Watson Conversation instance (If you don’t have a Bluemix account, follow these instructions to get a free trial).
You can leave the default values and select ‘Create’.
Now we need to copy your credentials from Bluemix. Click on ‘Sevice Credentials’ on the left menu and copy your credentials into clipboard. Then find config.js in the source code folder that you downloaded from Github. Update the config file with your own username and password for conversation services.
Next stop is the Watson Speech to Text. Follow the same process to create a service and copy your credentials.
You can leave the default values and select ‘Create’.
Now copy your credentials and add it to the config.js in your application folder.
The last stop is the Watson Text to Speech. You need to use the exact same thing with this service. You may leave all the default values and select ‘create’.
Almost set! You just need to copy your credentials and add it to the config.js in your application folder.
Step 6: Create a conversation flow
You need to train your robot with what to say and when to say it. For that, we useWatson Conversation. Open a browser and go to IBM Watson Conversation link.
From the top right corner, select the name of your conversation service and click ‘create’ to create a new workspace for your robot. You can create intents and dialogs there. Here is a step-by-step instructions to create a conversation flow:
It asks for a name. You may pick ‘TJ Bot’.
Click on the three vertical dots and select ‘view details’.
This would show you the workspace ID for the TJ Bot. You would need to update this ID at config.js in the source code folder that you downloaded from Github. Update the XXX for ConWorkspace with this conversation ID.
When you are done, select the back arrow (highlighted in the picture) to go to the previous page and select ‘get started’.
Everything is ready to start training the robot. Watson conversation uses intents to label the purpose of a sentence. For example when you ask “What’s the weather like today”, the intent is weather. In this step you need to create some intents for your robot. The robot is as smart as you train it. The more intents you add, the more meaningful conversations you can have with the robot. Let’s start with creating the first intent.
Choose a name for the intent and list several ways that the question or statement might be asked, to help your bot recognize the intent. For example instead of hello, you may say hey or yo!
Add 5 or more examples to help Watson clearly understand this intent. Once done, click ‘Done’.
You may add more intends for your bot. For example in my project I added an intent for goodbye.
The next step is to create a dialog and train the bot what to say when it recognizes an intent. Select ‘ Dialog’ from the top toolbar.
From the dialog window, select ‘create’.
A dialog uses intents from your application to return a response to each of your input. Create a dialog branch for each intent that you define. In each node (box), enter the name of an intent. Then enter the response that your bot should make when that intent is recognized.
You can test out your dialog from the icon on the right top corner. Type “Hello” and “Goodby” and test if the robot responds the way you wanted.
Congratulations! Your conversation is ready! You can add more intents to the dialog in the future.
Step 7: Run the Code
All we need to do is to run the module. Open a terminal and execute the following command:
node conversation.js
Now you can talk to your robot through the microphone and it talks back! Try “Hello, TJ” and “TJ, goodbye”!
You need an attention word to wake up your robot. The deafault attention word is ‘TJ’, but you can change it to your own word. Please keep this in mind that some words are easier for machine to recognize. If decided to change the attention word, experiment with multiple words and pick the one that is easier for the machine to recognize.
You can also change the voice of the robot. Three voice options are available for you. The default voice is Michael’s voice (en-US_MichaelVoice), but you can change it to female voices ( en-US_AllisonVoice or en-US_LisaVoice). You can change both the attention word and the voice model from config.js.
Enjoy! Don’t forget to share a picture/video of your setup #TJBot! 🙂
Troubleshoot
If you see TJ’s response on the terminal but don’t hear TJ talking, there is a good chance that one of these two things has happened: (1) The audio output is directed to a wrong channel (you can fix it from raspi-config), (2) your sound modules are blocked. In that case, go to /etc/modprobe.d/ and remove blacklist-rgb-led.conf
Then run the following command:
sudo update-initramfs -u
Reboot and confirm the “snd” modules are running by executing the command “lsmod”. This should solve the problem.
lsmod http://www.instructables.com/id/Build-a-Talking-Robot-With-Watson-and-Raspberry-Pi/?ALLSTEPS
Leave a Reply
You must be logged in to post a comment.