xxxxxxxxxx
var bar = new p5.SpeechRec('en-US'); // this is a speech recognition object
bar.onResult = gotspeech; // this is a callback function
bar.continuous = true; // continuous recognition
bar.interimResults = true; // fragmented recognition
var x;
var y;
var xi=0;
var yi=0;
var sp=1;
var r = 60;
var g = 60;
var b = 60;
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
textSize(80);
bar.start(); // start the speech recognition
x = width/2;
y = height/2;
strokeWeight(20);
stroke(r, g, b, 20);
}
function draw() {
r = constrain(r + random(-5,5), 0, 255);
g = constrain(g + random(-5,5), 0, 255);
b = constrain(b + random(-5,5), 0, 255);
stroke(r, g, b, 20);
point(x,y);
x+=xi;
y+=yi;
if(x>width) x = 0;
if(x<0) x=width;
if(y>height) y = 0;
if(y<0) y=height;
}
function mousePressed()
{
}
function gotspeech() {
s = bar.resultString.split(' ').pop().toLowerCase(); // get the last word you heard
if(s=='up')
{
yi=-sp;
xi=0;
}
if(s=='down')
{
yi=sp;
xi=0;
}
if(s=='left')
{
xi=-sp;
yi=0;
}
if(s=='right')
{
xi=sp;
yi=0;
}
if(s=='faster')
{
sp*=2;
xi*=2;
yi*=2;
}
if(s=='slower')
{
sp/=2;
xi/=2;
yi/=2;
}
if(s=='stop')
{
xi=0;
yi=0;
}
if(s=='s***')
{
background(255);
x=width/2;
y=height/2;
}
if(s=='clear')
{
background(255);
}
}