xxxxxxxxxx
136
const myRec = new p5.SpeechRec();
myRec.continuous = true;
myRec.interimResults = true;
let Fortune;
let score;
let noscore;
let img;
let img1;
let img2;
let img3;
let myFont;
function preload() {
Fortune = loadJSON("Fortune.json");
img = loadImage('cookie.png');
img1 = loadImage('happy.png');
img2 = loadImage('sad.png');
img3 = loadImage('Break.png');
myFont = loadFont('font.ttf');
}
function setup() {
createCanvas(600, 600);
myRec.start();
score = 0;
noscore = 0;
textFont(myFont);
textSize(30);
fill(182, 186, 166);
}
function draw() {
background(222, 226, 206);
image(img, width / 2 - 90, height / 2 - 200, 600, 750);
let string = myRec.resultString;
if (string != null) {
//text(string, 50, 50, 300, height);
} else {
text("Would you like a fortune?", 50, 200, 400, 400);
noscore = int(random(9));
}
switch (string) {
case 'yes':
case 'yeah':
case 'yep':
case 'okay':
case 'fine':
case 'sure':
SaidYes();
break;
case 'no':
SaidNo();
break;
case 'good':
case 'interesting':
case 'nice':
case 'cool':
case 'sweet':
case 'love':
case 'cute':
case 'agree':
case 'smart':
case 'funny':
case 'true':
case 'wise':
case 'correct':
case 'great':
case 'awesome':
case 'amazing':
SaidGood();
break;
case 'bad':
case 'disagree':
case 'confusing':
case 'weird':
case 'strange':
case 'random':
case 'wrong':
case 'false':
SaidBad();
break;
case 'stupid':
case 'lame':
case 'boring':
case 'ugly':
case 'hate':
SaidMean();
break;
case 'sorry':
SaidSorry();
break;
}
fill(182, 186, 166);
}
function SaidYes() {
text(Fortune.Fortune.general[score] + "...what do you think?", 50, 200, 400, 400);
noscore = int(random(9));
}
function SaidNo() {
text(Fortune.Fortune.refuse[noscore], 50, 200, 400, 400);
score = int(random(16));
image(img2, width / 2 - 90, height / 2 - 200, 600, 750);
}
function SaidGood() {
text("I knew you'd like it! Do you want another?", 50, 200, 400, 400);
score = int(random(16));
noscore = int(random(9));
image(img1, width / 2 - 90, height / 2 - 200, 600, 750);
}
function SaidBad() {
text("Oh...would you like a different one?", 50, 200, 400, 400);
score = int(random(16));
noscore = int(random(9));
image(img2, width / 2 - 90, height / 2 - 200, 600, 750);
}
function SaidMean() {
fill(182, 186, 166);
text("Ouch...", 50, 200, 400, 400);
fill(222, 226, 206);
noStroke();
rect(450,300,200,400);
image(img3, width / 2 - 90, height / 2 - 200, 600, 750);
}
function SaidSorry() {
text("I forgive you. Would you like another fortune?", 50, 200, 400, 400);
}