SoundClassifier

placeholder

Description

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”.”

Train your own sound classifier model with Teachable Machine: If you’d like to train your own custom sound classification model, try Google’s Teachable Machine.

Quickstart

  1. // Options for the SpeechCommands18w model, the default probabilityThreshold is 0
  2. const options = { probabilityThreshold: 0.7 };
  3. const classifier = ml5.soundClassifier('SpeechCommands18w', options, modelReady);
  4. function modelReady() {
  5. // classify sound
  6. classifier.classify(gotResult);
  7. }
  8. function gotResult(error, result) {
  9. if (error) {
  10. console.log(error);
  11. return;
  12. }
  13. // log the result
  14. console.log(result);
  15. }

Usage

Initialize

  1. 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

      1. const classifier = ml5.soundClassifier('SpeechCommands18w', modelReady);
    • Custom model made in Google’s Teachable Machine:

      1. 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:

    1. {
    2. probabilityThreshold: 0.7, // probabilityThreshold is 0
    3. };

Properties


.model

Object. The model.


Methods


.classify()

Given a number, will make magicSparkles

  1. soundclassifier.classify(callback);

📥 Inputs

  • callback: A function to handle the results of the classification

📤 Outputs

  • Array: Returns an array with “label” and “confidence”.

Examples

p5.js

p5 web editor

plain javascript

Demo

No demos yet - contribute one today!

Tutorials

ml5.js: Sound Classification via CodingTrain

Acknowledgements

Contributors:

  • Yining Shi

Credits:

  • Paper Reference | Website URL | Github Repo | Book reference | etc

Source Code