xxxxxxxxxx
// Global variable to store the classifier
let classifier;
// Label
let label = 'listening...';
let confidence;
let Nachricht = 0;
let Gruppe = 0;
// Teachable Machine model URL:
let soundModel = 'https://teachablemachine.withgoogle.com/models/UFsls6ZM2/';
function preload() {
// Load the model
classifier = ml5.soundClassifier(soundModel + 'model.json');
}
function setup() {
createCanvas(windowWidth, windowHeight);
// Start classifying
// The sound model will continuously listen to the microphone
classifier.classify(gotResult);
}
function draw() {
background(200,30,70);
// Draw the label in the canvas
fill(255);
textSize(50);
textAlign(CENTER, CENTER);
text("Nachricht: " + Nachricht, width / 2, height / 3);
text("Gruppe: " + Gruppe, width / 2, height / 2);
}
// The model recognizing a sound will trigger this event
function gotResult(error, results) {
if (error) {
console.error(error);
return;
}
// The results are in an array ordered by confidence.
// console.log(results[0]);
label = results[0].label;
confidence = nf(results[0].confidence, 0, 2);
//print(label + " / " + confidence);
if (label.indexOf("Nachricht") > -1 && confidence > 0.9)
Nachricht += 1;
else if (label.indexOf("Gruppe") > -1 && confidence > 0.9)
Gruppe += 1;
}