Created
October 31, 2018 20:10
-
-
Save jeancarl/fbb807f1f5edae805250785afcdb41d1 to your computer and use it in GitHub Desktop.
TJBot Pumpkin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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