xxxxxxxxxx
let font;
let span = 120;
var points;
let speed = 300;
let sizeOfMovement = 10;
var myRec = new p5.SpeechRec(); // New P5.SpeechRec object
myRec.continuous = true; // Do continuous recognition
myRec.interimResults = true; // Allow partial recognition (faster, less accurate)
var mostrecentword; //Variable to hold the spoken words
function preload() {
font = loadFont('Outfit.ttf');
}
function setup() {
createCanvas(windowWidth, windowHeight);
myRec.start(); //Start speech recognition
// Get the point array.
points = font.textToPoints('say something', windowWidth / 4 - span, windowHeight / 2, span, {
sampleFactor: 1
});
}
function draw() {
let bg_shift = 30 - sin(millis() / 5000) * 25;
background(0, bg_shift);
if(myRec.resultValue==true) {
let p_map=1-map(myRec.resultString.length,0,100,0.1,1.0);
// print("p_map "+p_map+" rec length: "+myRec.resultString.length);
points = font.textToPoints( myRec.resultString, windowWidth / 4 - span, windowHeight / 2, span, {
sampleFactor: p_map
});
}
beginShape(TESS);
for (let i = 0; i < points.length; i++) {
let animX = sin(millis() / (speed + (points.length - i) * 0.05)) * (sizeOfMovement);
let animY = cos(millis() / (speed + i * 0.05)) * (sizeOfMovement);
stroke(255);
strokeWeight(2);
noFill();
vertex(points[i].x + animX, points[i].y + animY);
}
endShape(OPEN);
print(points.length)
}