loading

This instructable guides you through connecting a Raspberry Pi to Weather Company Data for IBM and creating a talking weather bot. You will use: (1) Watson Speech to Text to convert your vocal weather question into text, (2) Weather Company Data for IBM to retrieve weather conditions for the location in question and finally (3) Watson Text to Speech so the robot can talk back to you and tell you the weather conditions you asked for.

A working demo can be viewed here.

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 href="https://deb.nodesource.com/setup_6.x" | sudo -E bash -
sudo apt-get install -y nodejs

Step 3: Hardware Setup

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

TJBot assembly video: https://www.youtube.com/watch?v=bLt3Cf2Ui3o

Depending on which audio output source you are using with your Pi (HDMI, 3.5mm audio jack, Bluetooth, USB speaker), you may need to set the audio config.

HDMI/ 3.5mm Audio Jack
If you use 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.

lsusb


Next is to detect the card number of your USB audio.

aplay -l

Take a note of the card number associated with your USB Audio. Then go to the also.config file to set it as default.

sudo nano /usr/share/alsa/alsa.conf

Look for:

defaults.ctl.card 0
defaults.pcm.card 0

and update the card number (0 here) to the card number of your USB audio.

Different versions of Raspberry Pi OS may need a different setup. If you have problem with your USB setup, check out this guide to troubleshoot.

Bluetooth Speaker

If you plan to use a Bluetooth speaker, you may need to install the Raspberry Pi Bluetooth software. Here is a good tutorial to set it up: Play audio on a bluetooth speaker with Raspberry Pi 3

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.

cd tjweather
npm install

Step 5: Update Your Bluemix 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) Weather Company Data for IBM and (3) Watson Text to Speech. You need to copy your credentials for all these services.

Let's start with creating a Watson Speech to Text (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.

Next, we need to copy your credentials from Bluemix. Click on 'Sevice Credentials' on the left menu and copy your credentials into clipboard.

Then locate config.default.js in the tjweather folder that you already downloaded (or cloned) from github in the previous step. Rename it to config.js then open the config.js file using your favorite text editor. Update the config file with your own username and password.

You are done with Speech to Text credentials! The next step is Weather Company Data for IBM. You need to follow the similar steps as above. You may leave all the default values and select ‘create’.

Now go to 'Service Credentials' on the left menu and copy your credentials into clipboard. You need to copy username, password, and the URL.

You need to update config.js with your Weather Company Data credentials.

The last stop is the Watson Text to Speech. You need to use the exact same thing you did with the other two services. You may leave all the default values and select 'create'.

Now go to 'Service Credentials' on the left menu and copy your credentials into clipboard.

Update config.js with your Text to Speech credentials.

Congratulations! You survived the credentials section!

Step 6: Run the Code

All we need to do is to run the module. Open a terminal, go to the tjweather/ folder where the code is located and execute the following command:

node weather.js

Now you can talk to your robot through the microphone and it talks back! Try "Watson what is the weather in San Francisco, California? "

Remember, right now, this is a weather bot which understands your question if you have “weather” in your question. Also, you need to specify a city and state in the U.S.A.

You need an attention word to wake up your robot. The default attention word is 'Watson', 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.

A working demo can be viewed here.

Enjoy! Don't forget to share a picture/video of your setup #TJBot!

<p>I am just now trying to run the program and it is throwing me a lot of compiling errors, particularly about the use of strict mode in index.js. Am I doing something wrong, or is the code being weird?</p>
<p>That's neat :) Do you have a video of it working?</p>
<p>Thanks for the feedback. I am working on a video!</p>
<p>that will be cool</p>

About This Instructable

1,910views

31favorites

License:

More by supbt:Build a Weather Bot 
Add instructable to: