Introduction: TJBot - Build a Talking Robot With Watson Conversation

Picture of TJBot - Build a Talking Robot With Watson Conversation

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: Prepare 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.

Here is an easy way to get your Pi connected to wifi.


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 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, plug in your USB microphone and the speaker.

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.

USB Speaker

If you have a USB audio, you need to update your /usr/share/alsa/alsa.config to set the USB audio as the default device. Begin with running the following command to make sure your USB is connected and listed there.

 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 alsa.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 source code is available at github. Download or clone the 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/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, you need to create one).

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.


Now 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.

The Conversation service needs one more ID to configure. It's called the Workspace ID (exports.conversationWorkspaceId). Don't worry about it for now. In the next step, we will walk you through creating a conversation workspace.

You are done with the Conversation credentials! Next stop is Watson Speech to Text. Follow the same process to create a service and copy your credentials.

You may leave the default values for the service & credential names and select 'Create'.

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

You need to update config.js with your Speech to Text credentials.

The last stop is Watson Text to Speech. You need to do the exact same steps you did with the other two services. You may leave the default values for service and credential name and select 'create'.

Copy your credentials and add them to config.js.

Here is the section of config.js that you need to update:

Congradulations! You survived the credentials section! ::robot-smile::

Step 6: Create a Conversation Flow

You need to train your robot with what to say and when to say it. For that, we use Watson Conversation. Open a browser and go to IBM Watson Conversation.

Log in, and in the the top left menu, select the name of your conversation service. Click on 'Import' icon to import the sample conversation.

In the dialog that opens, click 'Choose a file' and select 'workspace-sample.json' from the 'tjbot/recipes/conversation' folder. Make sure 'Everything (Intents, Entities, and Dialog)' is selected.

After the workspace has been imported, click the dotted menu and select 'View details'. Copy your Workspace ID as shown.

Next, update your config.js file with the workspace ID.

Congratulations, your conversation is ready!

Step 7: Run the Code

Now, you are ready to talk to your TJBot!

Open a terminal and execute the following command:

sudo node conversation.js

Watson conversation uses intents to label the purpose of a sentence. For example when you ask TJBot "Please introduce yourself", the intent is to make an introduction. You can add your own new intents in the Conversation editor, but for now, we have started you off with two intents:

  • Introduction. You can say phrases such as "Watson, please introduce yourself", "Watson, who are you", and "Watson, can you introduce yourself"
  • Joke. You can ask "Watson, please tell me a joke" or "Watson, I would like to hear a joke".

If you would like to create your own intents, we recommend following this guide.

An attention word is used so TJBot knows you are talking to him. The default attention word is 'Watson', but you can change it in conversation.js as follows. Update conversation.js and change tjConfig to add the 'robot' section:

// turn on debug logging to the console
var tjConfig = {
    verboseLogging: true,
    robot: {
        name: 'Watson',
        gender: 'male'
    }
};

You can change the 'name' to whatever you would like to call your TJBot. In addition, if you change the gender to 'female', TJBot will use a female voice to speak to you!

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

Troubleshoot

If you see TJBot's response on the terminal but don't hear TJBot 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

Comments

EstherVL (author)2017-09-24

Hi everyone,

I also asked this on github/TJbot, but maybe there are some clever people out here that can help me get this solved:

My TJbot hears what I say, but does not respond to me, either in the terminal or on audio. No errors are given either. The output looks as follows:


pi@TJbot:~/tjbot/recipes/conversation $ sudo node conversation.js
info: Hello from TJBot! My name is TJ.
You can ask me to introduce myself or tell you a joke.
Try saying, "TJ, please introduce yourself" or "TJ, who are you?"
You can also say, "TJ, tell me a joke!"
info: TJBot heard: could
info: TJBot heard: I
info: TJBot heard: TJ tell me a joke
info: TJBot heard: but
{ filename: '/tmp/tjbotxxxxxx,
gain: 100,
debug: true,
player: 'aplay',
device: 'plughw:0,0' }


At first I thought it was an audio problem, as I had found out through aplay that plughw needed to be 2,0 rather than 0,0. I have bought a standard Adafruit TJbot kit that contains a USB speaker and USB microphone & Raspberry Pi 3. Testing both devices separately, they work fine. You can find the output from aplay and arecord below:


Aplay
pi@TJbot:~/tjbot/recipes/conversation $ aplay -l
** List of PLAYBACK Hardware Devices **
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: Device_1 [USB2.0 Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0


Arecord
pi@TJbot:~/tjbot/recipes/conversation $ arecord -l
** List of CAPTURE Hardware Devices **
card 1: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0


I tried changing the alsa.conf file, and when that didn't work I made sure the Raspberry Pi itself recognized my audio devices and set the USB speaker to default, I created an asound.conf file and I even adapted the conversation.js and sst.js files. See changes below:


Alsa.conf
defaults.ctl.card 2
defaults.pcm.card 2
defaults.pcm.device 0
defaults.pcm.subdevice -1
defaults.pcm.nonblock 1
defaults.pcm.compat 0


Asound.conf
GNU nano 2.2.6 File: asound.conf

pcm.!default {
type hw
card 2
}

ctl.!default {
type hw
card 2
}


Conversation.js & sst.js
// set up TJBot's configuration
var tjConfig = {
verboseLogging: true,
speakerDeviceId: 'plughw:2,0',
microphoneDeviceId: 'plughw:1,0',
robot: {
name: 'TJ',
homophones: ['DJ','Deejay','Teejay'],
gender: 'female'
}
};


I followed this tutorial when setting up TJ and also looked at the troubleshooting section:
"If you see TJBot's response on the terminal but don't hear TJBot 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"


The first option does not seem to apply to me since I have a USB speaker, no audio jack or HDMI. For the second option, I don't even have the file blacklist-rgb-led.conf. Since I tried most audio-related troubleshooting, I'm wondering whether it is something with TJ just not responding, but as far as I'm aware I have installed the Conversation, Speech-to-Text and Text-to-Speech correctly and my credentials have been correctly inserted. Can you please help me?

cmackin (author)2017-09-06

Cannot find module 'tjbot'

I have tried everything including rebuilding the RPi. Below is what I type to run Conversation.js and the following is the error. Any help here would be great.

I get a similar error when I run stt.js

Error: Cannot find module './config'

It seems like the directory of install is wrong or there is an index file that needs to be configured.

pi@raspberrypi:~/tjbot/recipes/conversation $ sudo node conversation.js

module.js:472

throw err;

^

Error: Cannot find module 'tjbot'

at Function.Module._resolveFilename (module.js:470:15)

at Function.Module._load (module.js:418:25)

at Module.require (module.js:498:17)

at require (internal/module.js:20:19)

at Object.<anonymous> (/home/pi/tjbot/recipes/conversation/conversation.js:17:13)

at Module._compile (module.js:571:32)

at Object.Module._extensions..js (module.js:580:10)

at Module.load (module.js:488:32)

at tryModuleLoad (module.js:447:12)

at Function.Module._load (module.js:439:3)

BENYS7 (author)2017-05-03

Hi,

I have also this error but not about npm :( "

Cannot find module 'tjbot'

---------------------------------------------

$ node conversation.js
module.js:471
throw err;
^

Error: Cannot find module 'tjbot'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (......\TJBOT\tjbot-master\recipes\conversation\conversation.js:17:13)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)

cmackin (author)BENYS72017-09-06

I am having the same problem. I have reinstalled and still I can't get it to work. I have configured the config.js and removed the default, but still no joy. I had this working in a previous installation but this one is not working. What does it mean by "Cannot find module 'tjbot'?"

I think this must have something to do with the directory that tjbot is installed. I have tried moving it around, but still not working.

CalebV14 (author)2017-08-22

Hello, thank you for this lovely guide. I followed it step by step and get the following error when I try to execute sudo node conversation.js: module.js:471

throw err;

^

Error: Cannot find module '/home/pi/conversation.js'

at Function.Module._resolveFilename (module.js:469:15)

at Function.Module._load (module.js:417:25)

at Module.runMain (module.js:604:10)

at run (bootstrap_node.js:389:7)

at startup (bootstrap_node.js:149:9)

at bootstrap_node.js:504:3

Any ideas on a fix? Thanks!

EdwardB98 (author)2017-08-18

I have some prior experience training the Watson Text to Speech and Speech to text systems, but looking through the code in github, I was unable to find if there was some where to specify a customization_id for either? And is it possible to specific the exact voice (so I could use the British voice for example) rather than the default?

Accetron (author)2017-08-10

I set everything up as you described and my new buddy is working beautifully. Now I want to go a bit further and have him tell me the time whenever I ask him. Since I have conversation.js running most (read: all) of the time, I'd like to expand this function so that it can do this as well. Any tips on how to do this efficiently for an absolute beginner?

the_spankles (author)2017-07-16

Hello everyone, thankyou for reading my question. After setting up tjbot and running the code, everything boots up fine. However, when I give it a command like "watson introduce yourself" it recognises the command and posts it in the console, but then gives an error

error: the speech_to_text service returned an error. Error: Session closed. Reason: Payload exceeds the 104857600 bytes limit.

(The full error is below) I have checked my credentials and everything is fine. I even wiped my pi and started over, just to receive the same error. The full error is below

error: the speech_to_text service returned an error. Error: Session closed. Reason: Payload exceeds the 104857600 bytes limit.

at emitError (/home/pi/tjbot/recipes/conversation/node_modules/watson-developer-cloud/speech-to-text/recognize_stream.js:145:13)

at W3CWebSocket.socket.onmessage (/home/pi/tjbot/recipes/conversation/node_modules/watson-developer-cloud/speech-to-text/recognize_stream.js:165:7)

at W3CWebSocket._dispatchEvent [as dispatchEvent] (/home/pi/tjbot/recipes/conversation/node_modules/yaeti/lib/EventTarget.js:107:17)

at W3CWebSocket.onMessage (/home/pi/tjbot/recipes/conversation/node_modules/websocket/lib/W3CWebSocket.js:234:14)

at WebSocketConnection.<anonymous> (/home/pi/tjbot/recipes/conversation/node_modules/websocket/lib/W3CWebSocket.js:205:19)

at emitOne (events.js:96:13)

at WebSocketConnection.emit (events.js:188:7)

at WebSocketConnection.processFrame (/home/pi/tjbot/recipes/conversation/node_modules/websocket/lib/WebSocketConnection.js:547:26)

at /home/pi/tjbot/recipes/conversation/node_modules/websocket/lib/WebSocketConnection.js:321:40

at _combinedTickCallback (internal/process/next_tick.js:73:7)

at process._tickCallback (internal/process/next_tick.js:104:9)

If anyone can help me that would be much appreciated. Thanks

Luke

victordibia (author)the_spankles2017-07-17

Hi Luke,

The error above indicates you may be posting audio to the speech to text services that is above the normal payload. Normally this should not occur after a single short sentence (which is well below the limit).
I just tested the STT service locally and it does work fine at my location.
A few things I would suggest ...
- If possible, please do try out a new set of STT credentials (it is possibly that your current credentials are in being used in a different application hence the limits)
- Also try the to run the STT sample and let me know if you still have the same issue.
- Please open an issue on Github - its easier to follow up there and track our discussion.

https://github.com/ibmtjbot/tjbot/issues/new

- Victor.

ZygimantasB1 (author)2017-05-08

Hi all,

get following

error: unable to retrieve TTS voices Error: Not Authorized

Any ideas???

Thanks

OK, seems that just like in previous comments from Ooduc, the service does not work if it is based in 'Germany' region. creating services in US-South works just fine.

jeffreycfho (author)ZygimantasB12017-06-19

I am getting the same error. I have the workspace and services created in US South. Any ideas? thanks.

RobertR337 (author)2017-03-03

I cannot seem to get Jumps from one node to the next to work. STT doesn't return the next node, only the one that immediately addressed the previous dialogue. So:

user: let's go to mars.

TJ: Okay heading to @planet (mars) sounds great.

TJ: Are you ready to go?

// second node doesn't return, though it should automatically (and works in conversation service).

Do I need to add an additional listener in STT?

rabbbit (author)RobertR3372017-06-16

Place a TRUE in the trigger section of the node you want to always activate (once it is reached).

victordibia (author)RobertR3372017-03-05

Hi RobertR337,

It appears you have created your dialog to have two consecutive turns ( user, TJ, TJ, user). Does the user say anything between these turns? Usually each party has a SINGLE turn - user, TJ, user, TJ, user, TJ etc.
To maintain this pattern ... will the following work?

user: .. lets to to mars
TJ: okay heading to @planet(mars) sounds great. Are you ready to go?
user: awesome! Firing up rocket, checking sensors and gadgets. Launching in three. two. one. zero ...

Does this help? Im unsure I fully understand the issue. Please also see this link for a quick primer on designing a conversation dialog.

https://www.ibm.com/watson/developercloud/doc/conversation/dialog-build.html


Btw .. we can move this conversation to github.

Thanks.

arprive (author)2017-05-16

Hi all,

Got a problem, the conversation service returns an error. Can't find the problem. I have other recipes working (Speech to Text, Sentiment Analysis) and I have tested all tjbot-devices (ran all tests in jbot/bootstrap/tests). The error that I got is:

info: TJBot heard: Watson how are you
error: the conversation service returned an error. Error: Resource not found
at Request._callback (/home/pi/tjbot/recipes/conversation/node_modules/watson-developer-cloud/lib/requestwrapper.js:87:15)
at Request.self.callback (/home/pi/tjbot/recipes/conversation/node_modules/request/request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (/home/pi/tjbot/recipes/conversation/node_modules/request/request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at Gunzip.<anonymous> (/home/pi/tjbot/recipes/conversation/node_modules/request/request.js:1091:12)
at Gunzip.g (events.js:292:16)
at emitNone (events.js:91:20)
at Gunzip.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)

Hope anyone can help me.

Ar.

arprive (author)arprive2017-05-16

Oh, and yes, I checked the service credentials etc. I also uploaded the intents to Conversation, all looks fine there too.

geneLo (author)arprive2017-06-07

Hi, did you ever find the problem causing it?? I have the exact error and my credentials are correct as well.

I believe the issue has to do with rPI not seeing my usb speaker.

arprive (author)geneLo2017-06-12

No answer yet. Still the same issue.

geneLo (author)arprive2017-06-13

Same here, still. I found out that the output audio has trouble working when the led is on.

https://github.com/victordibia/tjwave#known-issue-...

and in another repo by the same guy i found "Any small speaker with either a 3.5mm audio jack or Bluetooth will work. Note that if you are using the 3.5mm audio jack, you may wish to add a USB Audio Adapter to avoid audio interference with the LED."

So until i go buy a usb adapter, TJ is speechless.

demelza_xx (author)2017-05-24

Hi,

Hope you can advise on the following error I see when issuing the 'sudo node conversation.js' ? I've checked that all the credentials are listed correctly in the config.js

pi@raspberrypi:~/tjbot/recipes/conversation $ sudo node conversation.js

verbose: TJBot initializing microphone

verbose: TJBot initializing conversation service

verbose: TJBot initializing speech_to_text service

verbose: TJBot initializing text_to_speech service

info: Hello from TJBot! My name is Watson.

verbose: TJBot library version v1.2.1

You can ask me to introduce myself or tell you a joke.

Try saying, "Watson, please introduce yourself" or "Watson, who are you?"

You can also say, "Watson, tell me a joke!"

verbose: TJBot initializing microphone

error: the speech_to_text service returned an error. type=error, isTrusted=false, _yaeti=true, , addEventListener=function _addEventListener(type, newListener) {

var

listenersType,

i, listener;

if (!type || !newListener) {

return;

}

listenersType = this._listeners[type];

if (listenersType === undefined) {

this._listeners[type] = listenersType = [];

}

for (i = 0; !!(listener = listenersType[i]); i++) {

if (listener === newListener) {

return;

}

}

listenersType.push(newListener);

}, removeEventListener=function _removeEventListener(type, oldListener) {

var

listenersType,

i, listener;

if (!type || !oldListener) {

return;

}

listenersType = this._listeners[type];

if (listenersType === undefined) {

return;

}

for (i = 0; !!(listener = listenersType[i]); i++) {

if (listener === oldListener) {

listenersType.splice(i, 1);

break;

}

}

if (listenersType.length === 0) {

delete this._listeners[type];

}

}, dispatchEvent=function _dispatchEvent(event) {

var

type,

listenersType,

dummyListener,

stopImmediatePropagation = false,

i, listener;

if (!event || typeof event.type !== 'string') {

throw new Error('`event` must have a valid `type` property');

}

// Do some stuff to emulate DOM Event behavior (just if this is not a

// DOM Event object)

if (event._yaeti) {

event.target = this;

event.cancelable = true;

}

// Attempt to override the stopImmediatePropagation() method

try {

event.stopImmediatePropagation = function () {

stopImmediatePropagation = true;

};

} catch (error) {}

type = event.type;

listenersType = (this._listeners[type] || []);

dummyListener = this['on' + type];

if (typeof dummyListener === 'function') {

dummyListener.call(this, event);

}

for (i = 0; !!(listener = listenersType[i]); i++) {

if (stopImmediatePropagation) {

break;

}

listener.call(this, event);

}

return !event.defaultPrevented;

}, _url=wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_BroadbandModel, _readyState=3, _protocol=undefined, _extensions=, _bufferedAmount=0, _binaryType=arraybuffer, _connection=undefined, domain=null, , _eventsCount=0, _maxListeners=undefined, maxReceivedFrameSize=1048576, maxReceivedMessageSize=8388608, fragmentOutgoingMessages=true, fragmentationThreshold=16384, webSocketVersion=13, assembleFragments=true, disableNagleAlgorithm=true, closeTimeout=5000, , _req=null, protocols=[], origin=null, protocol=wss:, slashes=true, auth=null, host=stream.watsonplatform.net, port=443, hostname=stream.watsonplatform.net, hash=null, search=?model=en-US_BroadbandModel, query=model=en-US_BroadbandModel, pathname=/speech-to-text/api/v1/recognize, path=/speech-to-text/api/v1/recognize?model=en-US_BroadbandModel, href=wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_BroadbandModel, secure=true, base64nonce=/bI/W/vDaLupLpWE1CYy5w==, onerror=function (error) {

self.listening = false;

self.emit('error', error);

}, onopen=function () {

socket.send(JSON.stringify(openingMessage));

self.emit('connect');

}, onclose=function (e) {

self.listening = false;

self.push(null);

/**

* @event RecognizeStream#close

* @param {Number} reasonCode

* @param {String} description

*/

self.emit('close', e.code, e.reason);

}, onmessage=function (frame) {

if (typeof frame.data !== 'string') {

return emitError('Unexpected binary data received from server', frame);

}

let data;

try {

data = JSON.parse(frame.data);

} catch (jsonEx) {

return emitError('Invalid JSON received from service:', frame, jsonEx);

}

let recognized = false;

if (data.error) {

emitError(data.error, frame);

recognized = true;

}

if (data.state === 'listening') {

// this is emitted both when the server is ready for audio, and after we send the close message to indicate that it's done processing

if (!self.listening) {

self.listening = true;

self.emit('listening');

} else {

self.listening = false;

socket.close();

}

recognized = true;

}

if (data.results) {

/**

* Object with interim or final results, including possible alternatives. May have no results at all for empty audio files.

* @event RecognizeStream#results

* @param {Object} results

*/

self.emit('results', data);

// note: currently there is always either no entries or exactly 1 entry in the results array. However, this may change in the future.

if (data.results[0] && data.results[0].final && data.results[0].alternatives) {

/**

* Finalized text

* @event RecognizeStream#data

* @param {String} transcript

*/

self.push(data.results[0].alternatives[0].transcript, 'utf8'); // this is the "data" event that can be easily piped to other streams

}

recognized = true;

}

// note: some messages will have both results and speaker_labels

// this will cause them to be emitted twice - once for each event

if (data.speaker_labels) {

/**

* Speaker labels

* @event RecognizeStream#speaker_labels

* @param {Object} speaker_labels

*/

self.emit('speaker_labels', data);

recognized = true;

}

if (!recognized) {

emitError('Unrecognised message from server', frame);

}

}, cancelable=true, stopImmediatePropagation=function () {

stopImmediatePropagation = true;

}

verbose: TJBot initializing microphone

gdandrea (author)demelza_xx2017-05-30

Have you fixed your issue?
I got the same here...

demelza_xx (author)gdandrea2017-06-06

Hi, yes I fixed - it was a typo in the credentials. I recommend doing a cut and paste to avoid the same issue !!

I'm also is the same boat. I've installed a debugger to try and figure out what's going on here. They say that's half the battle. I'll post my findings and any resolution. I'm an optimist :-)

I rechecked my the credentials I'd put in the config.js and I had made a typo with my 'b' and 'd'. once corrected the error is gone

gdandrea (author)2017-05-30

Same error as demelza_xx...

cassandrabot (author)2017-05-12

Hi all,

I just knew TJBot yesterday. And would like to try it. Could you please tell me where to buy the materials? And the list of material with brand version #?

Thanks

TJBot (author)cassandrabot2017-05-12

Hi there, please check ibm.biz/mytjbot for purchase options. For a list of electronics with an amazon link to purchase them, check out https://github.com/ibmtjbot/tjbot Have fun with TJBot! :-)

cassandrabot (author)TJBot2017-05-12

Thank you, TJBot. I tried to order at amazon.com, but many of the components won't ship outside of US. I then tried at amazon.ca, can't find exactly the same brand for some components. I s there anyone in Toronto that bought all the required materials?

Jon Hurd (author)cassandrabot2017-05-19

@Henry Will has a Blog post with links to required parts. ==>

http://henrywill4.blogspot.com/2017/04/tjbot-part-...

There is also a parts list in GitHub ==>

https://github.com/bmeunier/TJBot-Parts-List

perfectlax (author)2017-04-25

Hello:

I'm stuck on step 6.

Whenever I tried to upload the workspace-sample.json to IBM Watson Conversation, I get the following error:

Unable to import workspace from file workspace-sample.json. Error: File upload error

Any ideas how to solve this?

Thank you very much for your help.

Best Regards!

victordibia (author)perfectlax2017-04-28

It might be the case that your json file might be corrupted?
Perhaps consider downloading a new copy of the file and uploading that?

-V.

perfectlax (author)victordibia2017-05-12

I fixed it by changing the permissions to the file (777)

thank you for your response!

ZRob314 (author)perfectlax2017-05-12

I also had that error. I still had the config.js editor open, so I saved and closed it and re-uploaded the workspace-sample.json.....problem fixed.

perfectlax (author)ZRob3142017-05-12

Thanks for your response, also I changed permissions in the file (chmod 777) and that also solved the problem.

Best Regards!

jman24saints (author)2017-05-06

Hi, This is the error we are receiving:

pi@raspberrypi:~/tjbot/recipes/conversation $ sudo node conversation.js

module.js:471

throw err;

^

Error: Cannot find module './config'

at Function.Module._resolveFilename (module.js:469:15)

at Function.Module._load (module.js:417:25)

at Module.require (module.js:497:17)

at require (internal/module.js:20:19)

at Object.<anonymous> (/home/pi/tjbot/recipes/conversation/conversation.js:18:14)

at Module._compile (module.js:570:32)

at Object.Module._extensions..js (module.js:579:10)

at Module.load (module.js:487:32)

at tryModuleLoad (module.js:446:12)

at Function.Module._load (module.js:438:3)

at Module.runMain (module.js:604:10)

at run (bootstrap_node.js:390:7)

at startup (bootstrap_node.js:150:9)

at bootstrap_node.js:505:3

Can you please help? Thanks.

TJBot (author)jman24saints2017-05-08

Hi jman24saints, did you rename config,default.js to config.js? This should solve your problem.

Ooduc (author)2017-04-24

I am out of ideas.

I checked the credentials twice after following the instructions (twice, or thrice because on the first attempt I didn't notice that password was first in the config)

Is it my system or something with the connection?

I followed the instructions word by word because I am not a raspi-jockey (jet?)

TJBot (author)Ooduc2017-04-24

We've only seen that error come up when putting in the credentials incorrectly. The username is the very long string with dashes and the password is the shorter string. Make sure you are not copying with extra spaces at the beginning or at the end.

Ooduc (author)TJBot2017-04-26

I did everything again, twice didn't work.

I deleted all Watson services changed the region from 'Germany' to 'United States (South)' created a division (no sure if it is division only have the german interface). After that I created all services anew, also noticed that there are more services available.

Works almost perfect only one thing: If I just say 'watson' and nothing else it crashes with some 'no text' error.

victordibia (author)Ooduc2017-04-28

Hi Ooduc,
Glad you were able to resolve the credentials issue!
We have fixed the "no text crash".
To get the latest update you can run reinstall the libary by running the code below.

rm -rf node_modules

npm install

-V.

AlanU7 (author)2017-04-16

Hi

on running: sudo node conversation.js in step 7

I get error:
SyntaxError: Unexpected token =
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/pi/tjbot/recipes/conversation/node_modules/tjbot/index.js:1:80)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)

When running npm install I had 1 warning:

npm WARN deprecated node-uuid@1.4.8: Use uuid module instead

Username and password x 3 double checked as was exports.conversationWorkspaceId and opening and closing quotes.

Note this is a working Jessie from a Pi 1 B+ imaged to a new Pi 3. I ran steps 1 to 6 OK (well took a day to get the BT speaker working!). A USB microphone is installed but not tested. LEDs and servo not yet connected.

Help appreciated.

Alan

AlanU7 (author)AlanU72017-04-20

Realised I missed a bit of the error message. The above is prefixed:

sudo node conversation.js
/home/pi/tjbot/recipes/conversation/node_modules/tjbot/lib/tjbot.js:854
TJBot.prototype.pulseOnce = function(color, duration = 1.0) {

Seems to me this code is trying to control the LED but this Instructable does not include the LED in the build whereas another Instructable "Build TJBot Out of Cardboard" does have the LED. I did not fit the LED so why does it appear the conversation.js code is trying to control the LED?

Thanks

Alan

victordibia (author)AlanU72017-04-28

Hi Alan,
The above error is helpful in troubleshooting. The way the TJBot library is designed, there should be no call to "pulse" or LED since "led" is not specified as a config parameter in the conversation.js recipe.
The correct way to disable LED is to not have it in the config parameter.

var hardware = ['microphone', 'speaker'];

One thing we can try is to uninstall and reinstall your node_modules.
sudo rm -rf node_modules
npm install.

I see you have posted on gitub, lets continue the conversation there

https://github.com/ibmtjbot/tjbot/issues/37


-V.

AlanU7 (author)AlanU72017-04-28

I've been following the instructions at

https://www.instructables.com/id/Use-Your-Voice-to-... to try to get the LED to work but unsuccessfully. I read that the Neopixels are not suitable for the Raspberry Pi https://www.instructables.com/id/Use-Your-Voice-to-... and elsewhere I read there are problems with the Rasp Pi 3 and Neopixels.

I don't really need the LED and the parts list for this instructables doesn't list the LED but the code seems to crash trying to use an LED. Is there any way to disable the LED function so I can continue with the Conversation functions? Help much appreciated as I was hoping to show TJBot at meeting in 10 days time.

chechaquo (author)2017-04-14

Nice Article, but i'm having problems following it, I'm getting following error:

pi@raspberrypi:~/tjbot/recipes/conversation $ sudo node conversation.js

info: Hello from TJBot! My name is cat.

You can ask me to introduce myself or tell you a joke.

Try saying, "cat, please introduce yourself" or "cat, who are you?"

You can also say, "cat, tell me a joke!"

info: TJBot heard: cat

info: TJBot heard: who are you

events.js:160

throw er; // Unhandled 'error' event

^

Error: Missing required parameters: text

at Object.getMissingParams (/home/pi/tjbot/recipes/conversation/node_modules/watson-developer-cloud/lib/helper.js:47:33)

at createRequest (/home/pi/tjbot/recipes/conversation/node_modules/watson-developer-cloud/lib/requestwrapper.js:132:26)

at TextToSpeechV1.synthesize (/home/pi/tjbot/recipes/conversation/node_modules/watson-developer-cloud/text-to-speech/v1.js:71:10)

at /home/pi/tjbot/recipes/conversation/node_modules/tjbot/lib/tjbot.js:1106:23

at /home/pi/tjbot/recipes/conversation/node_modules/temp/lib/temp.js:252:7

at FSReqWrap.oncomplete (fs.js:123:15)

Any clue what can be the cause?

chechaquo (author)chechaquo2017-04-15

never mind, understood the problem :)

AryanS64 (author)2017-03-25

Im getting an error in the first command execution itself. Node conversation.js

Image attached.

TJBot (author)AryanS642017-03-26

Hi AryanS64,

Have you edited the code for conversation.js at all? When I run it, this is what I see:

$ node conversation.js

Hello from TJBot! My name is Watson.

You can ask me to introduce myself or tell you a joke.

Try saying, "Watson, please introduce yourself" or "Watson, who are you?"

You can also say, "Watson, tell me a joke!"

AryanS64 (author)TJBot2017-04-02

it works now! thanks. Now we need to figure out how to make it do more stuff!

About This Instructable

26,348views

101favorites

Bio: I'm an open source project designed to help you access Watson Services in a fun way. You can laser cut or 3D print me ... More »
More by TJBot:How to Run a TJBot WorkshopHow to 3D Print a TJBotBuild TJBot Out of Cardboard
Add instructable to: