Skip to content

Instantly share code, notes, and snippets.

@jeancarl
Created October 31, 2018 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeancarl/fbb807f1f5edae805250785afcdb41d1 to your computer and use it in GitHub Desktop.
Save jeancarl/fbb807f1f5edae805250785afcdb41d1 to your computer and use it in GitHub Desktop.
TJBot Pumpkin
/**
* TJBot Pumpkin
*
* Three IBM Watson services are needed, Speech to Text, Text to Speech, and Tone Analyzer. Create these services at https://bluemix.net. Copy the corresponding API keys into the code below.
*/
var TJBot = require("tjbot");
var tj = new TJBot(
["microphone","led","speaker"],
{
robot: {
gender: "male",
},
speak: {
language: "en-US"
}
},
{
speech_to_text: {
apikey: "" // TODO: API Key from https://ibm.biz/catalog-speech-to-text
},
tone_analyzer: {
apikey: "" // TODO: API Key from https://ibm.biz/catalog-tone-analyzer
},
text_to_speech: {
apikey: "" // TODO: API Key from https://ibm.biz/catalog-text-to-speech
}
}
);
function processText(text) {
console.log(text);
tj.analyzeTone(text).then(response => {
console.log(response);
var emotions = response.document_tone.tone_categories[0].tones;
var top = emotions[Object.keys(emotions).reduce((a, b) => {
return emotions[a].score > emotions[b].score ? a : b
})];
console.log(top);
var colors = {
"anger": "red",
"disgust": "green",
"fear": "magenta",
"joy": "yellow",
"sadness": "blue"
};
tj.shine(colors[top.tone_id]);
if(top.tone_id == "fear") {
tj.stopListening();
tj.speak("booooooo").then(() => {
tj.listen(processText);
});
}
});
}
tj.listen(processText);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment