In this lab, we'll use the listen and analyze tone nodes to train TJBot to listen to utterances and analyze the emotion, lighting up an LED light based on which emotion is most prevalent. You will need a microphone and LED connected to the TJBot for this lab.
-
In the Node-RED editor running on the Raspberry Pi, drag two nodes onto the canvas. Double click on each node and configure as shown below.
-
Add a node as shown below. This node will take the payload from the inject nodes and set the
msg.mode
property, which the listen node in the next step will use. -
Add a node as shown below. The listen node has several modes, start and stop, that can be configured programmatically using the
msg.mode
property to start and stop listening. When listening is enabled, the listen node produces messages as TJBot hears and transcribes words, with the text being passed in themsg.payload
property.The listen node uses the Watson Speech to Text service, which requires service credentials from IBM Cloud. Click on the pencil icon to the right of the Bot dropdown menu.
-
Click on the link icon next to the Speech to Text heading to launch into the IBM Cloud console and create a Watson Speech to Text service instance.
-
If you don't have an IBM Cloud account, sign up at https://bluemix.net. Sign into your account if prompted. Leave the service name as is and click Create.
-
Click on Service Credentials in the menu on the left. If there are no credentials in the list, click New credential and Add to create a set of credentials. Click on View Credentials to display the service credentials.
-
Copy the username and password into the fields back in the Node-RED editor under the Speech to Text section.
-
At the top of the configuration window, select US English (US dialect) from the Listen dropdown menu. Enable the microphone by ticking the checkbox labeled Microphone.
-
Add a node as shown below. Select Emotion from the Tones dropdown menu.
The analyze node uses the Watson Tone Analyzer service, which requires service credentials from IBM Cloud. Click on the pencil icon to the right of the Bot dropdown menu.
-
Click on the link icon next to the Tone Analyzer heading to launch into the IBM Cloud console and create a Watson Tone Analyzer service instance.
-
Leave the service name as is and click Create.
-
Click on Service Credentials in the menu on the left. If there are no credentials in the list, click New credential and Add to create a set of credentials. Click on View Credentials to display the service credentials.
-
Copy the username and password into the fields back in the Node-RED editor under the Tone Analyzer section.
-
Watson Tone Analyzer returns scores for five emotions: anger, disgust, fear, joy, and sadness. Use a node to find the emotion that scores the highest.
-
Add a node to test which emotion scored highest as shown below.
-
Add four shine nodes, each with a color representing one of the emotions: red (anger), green (disgust), magenta (fear), yellow (joy), and blue (sadness).
-
Connect the nodes together as shown below.
-
Click on the button in the top-right corner of the Node-RED editor to save and deploy the changes.
-
Click on the tab to the left of the inject node labeled Start Listening to activate the microphone. Speak into the microphone and wait for the LED to turn the color that represents the emotion that's most prevalent. Click on the tab to the left of the inject node labeled Stop Listening to deactivate the microphone.
This lab uses the TJBot Node.js library which uses an older version of the Tone Analyzer. As of September 25th 2017 (service version: 3.4.1, interface version: 2017-09-21), the Tone Analyzer service no longer returns the emotion disgust.