xxxxxxxxxx
83
// create an array of keywords
let keywords = ["love", "death", "die", "rich", "health",
"wintershow", "ITP", "happy", "money", "friends", "job", "boyfriend", "girlfriend", "mum", "dad", "mother", "father", "sister", "brother", "family", "happy", "future", "technology", "lucky", "should", "do", "go", "marry", "meet", "friends", "friend", "buy", "house", "home", "luck", "travel", "I", "me", "him", "her", "them", "year", "month", "week", "next", "pcomp", "ICM", "career", "successful", "success", "country", "homeland", "them", "if"];
let fortune = ["You are gonna soon regret things you did for love. Think twice.", "Death is not that bad, trust me.", "You are not gonna die in a week. The rest is unclear.","You can be happy and poor at the same time.", "Something concerning your mental heath is going to happen soon. Are you an ITP student? If so, do not worry so much, it is dangerous.", "You’re not gonna feel well next week", "Not everyone is supposed to be a winner. You know what I mean?", "Watch your back while you’re here", "People are not born to be happy. You know what I mean?", "Money is not everything", "Keep you enemies close, and friends… Are you sure you have any of those?", "It is not necessarily that you’re gonna find a good job some day. Sorry about it", "Sometimes it is better to be all alone. You know what I mean, right?", "Sometimes it is better to be all alone. You know what I mean, right?", "You should have listened to her. Now it is too late", "You should have listened to him. Now it is too late.", "You should have listened to her. Now it is too late.", "You should have listened to him. Now it is too late.", "You should have listened to her. Now it is too late.", "You should have listened to him. Now it is too late.", "Get your own life!", "Your future is dark.", "Technology is cold and cruel. Leave for good.", "You’re not supposed to be lucky, sorry.", "No, you shouldn’t. You shouldn’t even think about that.", "No, you shouldn’t. You shouldn’t even think about that.", "No, you shouldn’t. You shouldn’t even think about that.", "No, you shouldn’t. You shouldn’t have even asked about it.", "The answer is simply NO. Yes, you got me right.", "This person is not your friend.", "You don’t have enough money for that!", "Home is NOT where your heart is.", "You don’t wanna go there, trust me.", "You are so self-absorbed!", "You are so self-absorbed!", "He doesn’t need you.", "She doesn’t need you.", "They don’t need you.", "You don’t have that mach time.", "You don’t have that mach time.", "You don’t have that mach time.", "Pcomp is not your thing, sorry.", "ICM is not your thing, sorry.", "Not everybody should have a beautiful career, you know.", "Not everybody is supposed to be successful, you know.", "Not everybody is supposed to be successful, you know.", "Leave. Immediately.", "Run. Fast.", "It is never gonna happen and you know that.", "You don’t have enough money.", "Why don’t you just get a life? You know what I mean, right?"];
//here will be answers for questions without key words
let abstractAnswers = ["I have no clue about your future, it is way too dark", "You future is uncertain, YOLO", "Be a New Yorker, walk fast and get out of the way", "Jaywalking is a way of life in NYC", "Do not ask silly questions, okay? You know the answer!"];
let serial;
//verify this line portName might be different
let portName = "/dev/tty.usbmodem14201";
let inData;
let outByte = 0;
let speechRec;
let robot;
function setup() {
noCanvas();
//This is part is for initiate serial communication to Arduino
serial = new p5.SerialPort();
serial.on('data',serialEvent);
serial.on('error',serialError);
serial.open(portName);
//Robot speak
robot = new p5.Speech();
//this is the part for detecting speech
let lang=navigator.language||'en-US';
speechRec=new p5.SpeechRec(lang,gotSpeech);
let continuous=true;
let interim=false;
speechRec.start(continuous,interim);
}
function gotSpeech(){
if(speechRec.resultValue){
let foundAnswer = false;
if(speechRec.resultString.length < 3 ) {
// not enough words to send any answer
return;
}
console.log("You asked: " + speechRec.resultString);
//Trying to find a keywords that match to what was said
for(var i = 0; i<keywords.length; i++){
if(speechRec.resultString.includes(keywords[i])){
//Yay, we found a keyword now let's just show the fortune message.
foundAnswer = true;
showFortune(fortune[i]);
break;
}
}
//Didn't found any keywords
if(foundAnswer === false){
// abstract answers goes here, we randomly pick one setence from the array of abstrack answers
let r = int(random(0, abstractAnswers.length-1));
let msg = abstractAnswers[r];
showFortune(msg);
}
}
}
//Display in the console.log the fortune message and send it to the serial port
function showFortune(message){
console.log("The fortune teller answer: " + message);
serial.write (message);
//robot.speak(message);
}
function serialEvent(){
}
function serialError(err){
console.log(err);
}