-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
60 lines (48 loc) · 1.07 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
let label = 'waiting ...';
let classifier;
//load model here
function preload() {
classifier = ml5.soundClassifier('https://teachablemachine.withgoogle.com/models/h9pHxe-8B/'+'model.json');
}
function setup(){
createCanvas(640, 520);
//classification starts here
classifyAudio();
}
//classify
function classifyAudio(){
classifier.classify(gotResults);
}
function draw(){
background(0);
textAlign(CENTER, CENTER);
//fill(25);
//text(label, width/2, height - 16);
// Background noise
let emoji = "🔭";
// Pick an emoji based on label
if (label == "GO") {
emoji = "🚀";
} else if (label == "D1") {
emoji = "🌟";
} else if (label == "G3") {
emoji = "🛰️";
}
// Draw the emoji
textSize(256);
text(emoji, width / 2, height / 2);
}
// STEP 3: Get the classification!
function gotResults(error, results) {
if (error) {
console.error(error);
return;
}
// Store the label
label = results[0].label;
}
/*
links
https://teachablemachine.withgoogle.com/models/h9pHxe-8B/
https://editor.p5js.org/adri8/sketches/4StWbCWugZ
*/