xxxxxxxxxx
52
let topics = ['birds', 'cats', 'dogs', 'cooking', 'netflix', 'social media', 'food', 'restaurants', 'movies', 'traveling', 'hobbies', 'books', 'drunk stories'];
let taboo = ['covid', 'Coronavirus', 'coronavirus', 'pandemic'];
let speechRecognition;
let voice;
let playedFlag = true;
let fade = 0;
let currentTopic;
function setup() {
createCanvas(600, 400);
voice = new p5.Speech();
speechRecognition = new p5.SpeechRec();
speechRecognition.onResult = showResult;
speechRecognition.start(true, false);
}
function showResult()
{
console.log(speechRecognition.resultString);
}
function draw() {
background('#000');
textSize(16);
fill(255, 0, 0, fade);
if(speechRecognition.resultString) {
if (taboo.some(v => speechRecognition.resultString.includes(v)) || mouseIsPressed) {
fade = 255;
voice.speak('STOP');
currentTopic = random(topics)
speechRecognition.resultString = '';
playedFlag = false;
}
}
text('STOP',width/2-10, height/2);
if(fade > 0) fade -= 2;
fill(255, 0, 0, 255);
if(fade < 0) {
let suggestion = 'Try talking about ' + currentTopic + '.';
if (!playedFlag) voice.speak(suggestion);
playedFlag = true;
text(suggestion, width/2-85, height/2);
}
// showResult();
// print(currentTopic);
}