xxxxxxxxxx
var foo = new p5.SpeechRec(); // speech recognition object (will prompt for mic access)
foo.onResult = showResult; // bind callback function to trigger when speech is recognized
foo.start(); // start listening
function setup() {
createCanvas(400,400);
background(225);
}
function showResult()
{
typeWriter(foo.resultString, 0, 20, 30, 100); // log the result
}
function draw() {
}
function typeWriter(sentence, n, x, y, speed) {
if (n < (sentence.length)) {
text(sentence.substring(0, n+1), x, y);
n++;
setTimeout(function() {
typeWriter(sentence, n, x, y, speed)
}, speed);
}
}