xxxxxxxxxx
// this is a BCP-47 language model:
// https://cloud.google.com/speech-to-text/docs/languages
var bar = new p5.SpeechRec('en-US'); // this is a new p5.speech recognition object bound to the variable bar
var x, y, xdir, ydir;
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
bar.onResult = showIt; // this function runs when it recognizes speech
bar.continuous = true; // turn on continous recognition (gotta do this before you hit start)
bar.interimResults = true; // this will give you zippier but less accurate transcription
bar.start(); // start it
x = width/2;
y = height/2;
xdir = 0;
ydir = 0;
strokeWeight(10); // thick line
}
function draw() {
point(x, y);
x+=xdir;
y+=ydir;
if(x>width) x = 0;
if(y>height) y = 0;
if(x<0) x=width;
if(y<0) y=height;
}
function showIt()
{
let s = bar.resultString.split(' ').pop(); // this is gonna give us the last word
switch(s) {
case 'up':
xdir = 0;
ydir = -1;
break;
case 'down':
xdir = 0;
ydir = 1;
break;
case 'left':
xdir=-1;
ydir=0;
break;
case 'right':
xdir=1;
ydir=0;
break;
case 'clear':
background(255);
default:
break;
}
}