The
ml5.soundClassifier()
allows you to classify audio. With the right pre-trained models, you can detect whether a certain noise was made (e.g. a clapping sound or a whistle) or a certain word was said (e.g. Up, Down, Yes, No). At this moment, with the
ml5.soundClassifier()
, you can use your own custom pre-trained speech commands or use the the "
SpeechCommands18w
" which can recognize "
the ten digits from "zero" to "nine", "
up", "
down", "
left", "
right", "
go", "
stop", "
yes", "
no", as well as the additional categories of "unknown word" and "background noise"."
Quickstart :
// Options for the SpeechCommands18w model, the default probabilityThreshold is 0
const options = { probabilityThreshold: 0.7 };
const classifier = ml5.soundClassifier('SpeechCommands18w', options, modelReady);
function modelReady() {
// classify sound
classifier.classify(gotResult);
}
function gotResult(error, result) {
if (error) {
console.log(error);
return;
}
// log the result
console.log(result);
}
Usage
Initialize :
const soundclassifier = ml5.soundClassifier(?model, ?options, ?callback)
By default the soundClassifier
will start the default microphone.
Parameters :
* model : Optional. Model name or URL path to a model.json
. Here are some options:
* SpeechCommands18w : loads the 18w speech commands
const classifier = ml5.soundClassifier('SpeechCommands18w', modelReady);
* Custom model made in Google's Teachable Machine :
const classifier = ml5.soundClassifier('path/to/model.json', modelReady);
* callback : Optional. A function to run once the model has been loaded.
* options : Optional. An object describing a model accuracy and performance. The available parameters are:
{
probabilityThreshold: 0.7, // probabilityThreshold is 0
};