xxxxxxxxxx
44
//https://idmnyu.github.io/p5.js-speech/
foo = new p5.SpeechRec(); // speech recognition object (will prompt for mic access)
function setup() {
c = color(255, 204, 0);
createCanvas(400,400);
background(0);
foo.start(); // start listening
foo.onResult = showResult; // bind callback function to trigger when speech is recognized
foo.onStart = showStart;
foo.onEnd = showEnd;
foo.continous = true;
foo.interimResults = true;
}
function draw() {
background(c);
}
function showResult()
{
console.log(foo.resultString); // log the result
if (foo.resultString==="red") {
c = color(255, 0, 0);
}
if (foo.resultString==="blue") {
c = color(0, 0, 255);
}
}
function showEnd()
{
console.log("Ending"); // log the result
foo.start();
}
function showStart()
{
console.log("Starting"); // log the result
}