Im making a program like the amazon echo using p5.speech. My code is not only messy and confusing but every time it hears speech it runs the else instead of what is supposed to happen
let carl = 'hey carl';
var value = 220;
let time = 'what time is it';
function setup() {
createCanvas(400, 400);
let hours = hour();
let min = minute();
if (hours<=12){
let hr = hour;
}else{
let hr = hour%12;
}
}
function draw() {
background(value);
textSize(50);
//Fill();
strokeWeight(4);
text("Hello I am Carl", 35,200);
textSize(25);
text("Click to start", 130, 300);
rect(400,400,0,0);
}
function mousePressed(){
if(value===220){
value = 0;
carlBegins();
} }
function carlBegins() {
let lang = navigator.language || 'en-US';
let speechRec = new p5.SpeechRec(lang, gotSpeech)
speechRec.continuous = true;
speechRec.start();
let heyCarl = speechRec
function gotSpeech() {
if (speechRec == carl){
startLis();
var myVoice = new p5.Speech();
myVoice.speak('yes?',hasSpoken);
}else{
console.log('oops');
}
}
function startLis() {
console.log('yes?')
times();
}
function hasSpoken() {
if(heyCarl===time){
myVoice.speak(hour);
myVoice.speak(minute);
}
}
}