xxxxxxxxxx
97
//original sketches by Moon: body pixelation: https://editor.p5js.org/MOQN/sketches/7RRrCwWtB
//speech recognition: https://editor.p5js.org/MOQN/sketches/eWfDS_fVt
//----------------------------
//----------------------------
// INSTRUCTIONS
// PICK A NUMBER BETWEEN 1-7
// OR SAY THE WORDS
// YES
// NO
// UP
// DOWN
// LEFT
// RIGHT
// MOVE AROUND IN THE SKETCH
//----------------------------
//----------------------------
let cam;
let classifier;
let options = { probabilityThreshold: 0.7 };
let label = "listening";
let confidence = 0.0;
let outputs = [];
console.log("ml5 version: " + ml5.version);
function setup() {
createCanvas(640, 480);
cam = createCapture(VIDEO);
cam.hide();
classifier = ml5.soundClassifier("SpeechCommands18w", options, modelReady);
}
function draw() {
background(0, 0.8);
// fill('lightblue');
cam.loadPixels();
console.log(label, confidence);
let gridSize = 10;
noStroke();
for (let y = 0; y < cam.height; y += gridSize) {
for (let x = 0; x < cam.width; x += gridSize) {
let index = (x + y * cam.width) * 4;
let r = cam.pixels[index + 0];
let g = cam.pixels[index + 1];
let b = cam.pixels[index + 2];
let a = cam.pixels[index + 3];
if (label == "one" || label == "zero" && confidence > 0.8) {
fill(r, g, b, (a / y) * 4); //red wavy tint
} else if (label == "two" || label == "no" && confidence > 0.8) {
fill(r, 0, 0, (a / y) * 4); //red wavy tint
} else if (label == "three" || label == "yes" && confidence > 0.8) {
fill(r, 0, b, (a / y) * 4); //purple wavy tint
} else if (label == "four" || label == "left" && confidence > 0.8) {
fill(0, g, b, (a / y) * 4); //teal wavy tint
} else if (label == "five" || label == "right" && confidence > 0.8) {
fill(r, g, 0, (a / y) * 4); //yellow wavy tint
} else if (label == "six" || label == "down" && confidence > 0.8) {
fill(0, g, 0, (a / y) * 4); //green wavy tint
} else if (label == "seven" || label == "up" && confidence > 0.8) {
fill(0, 0, b, (a / y) * 4); //blue wavy tint
} else {
fill(r, g, b, a);
}
rect(x, y, gridSize, gridSize);
}
}
}
function modelReady() {
console.log("Model ready");
classifier.classify(gotResults);
}
function gotResults(error, results) {
if (error) {
console.error(error);
}
// console.log(results);
// outputs = results;
if (results.length > 0) {
label = results[0].label;
confidence = results[0].confidence;
}
}