← All models

audio-classification Β· audio Β· WASM Β· ~95 MB

Musical Instrument Classification β€” name the instrument by ear

Play a few seconds of an instrument and this model names it β€” violin, trumpet, flute, acoustic or electric guitar, bass, keyboard, drum set, or hi-hats. It's a wav2vec2 network that reads the raw 16 kHz waveform (no spectrogram step) and outputs a probability for each of its nine instrument classes β€” running entirely on your device.

At a glance

Modelonnx-community/Musical-Instrument-Classification-ONNX
Task / pipelineaudio-classification
Architecturewav2vec2-base with a sequence-classification head (Wav2Vec2ForSequenceClassification) β€” reads the raw 16 kHz waveform directly
Classes9 instruments: Acoustic guitar, Bass guitar, Drum set, Electric guitar, Flute, Hi-hats, Keyboard, Trumpet, Violin
Input16 kHz mono Float32Array, mean/variance normalised
Quantizationq8 (8-bit) ONNX β€” onnx/model_quantized.onnx
BackendWebAssembly (runs anywhere; WebGPU used when an adapter exists)
Download~95 MB, cached after first load
LicenseApache-2.0 (wav2vec2 base)
Web APIsWebAssembly, Web Workers, Web Audio, MediaRecorder, Canvas β€” all Baseline widely available

An honest caveat: this is a compact model trained on a limited instrument set, so it is confident but not infallible β€” a breathy flute can read as a trumpet, an overdriven electric guitar as something else. Read the full confidence distribution below the headline, not just the top label β€” and treat it as a signal, not a verdict. It only knows the nine instruments it was trained on; anything else is forced into the closest class.

Run it

Pick a sample, drop an audio clip, or record an instrument from your mic, then hit Identify instrument.

Drop an audio file here, or click to choose

See inside

The model outputs a probability for every instrument class β€” a distribution, not a single answer. When the top two are close, the timbre is ambiguous (or two instruments share the clip). Below are the raw class probabilities from your clip, and the waveform the network actually read (wav2vec2 works on the raw signal β€” there's no spectrogram in between).

Identify a clip to see its full instrument distribution.

Why it matters

Recognising timbre β€” which instrument is sounding β€” on-device means an app can tag, route, or react to audio without shipping it to a server. It's private by construction and works offline once the model is cached.

Use cases

Basics

Identify the instrument in a clip and see the full confidence distribution.

Practical

A sample-library sorter β€” classify several clips and group them into instrument buckets.

Wild

Instrument over time β€” slide a window across a clip and watch which instrument leads.

Multi-model

Instrument + note pitch together: what is playing, and which note.

How the API works

Classification is one call with Transformers.js. Feed a 16 kHz mono Float32Array:

import { pipeline } from "@huggingface/transformers";

const classify = await pipeline(
  "audio-classification",
  "onnx-community/Musical-Instrument-Classification-ONNX",
  { dtype: "q8" },              // downloads + caches ~95 MB once
);

const output = await classify(audio, { top_k: 9 });
// audio = Float32Array @ 16 kHz mono (decode with the Web Audio API)
// β†’ [{ label: "Violin", score: 0.30 }, { label: "Acoustic_Guitar", score: 0.15 }, … ]

This page decodes files / mic recordings to 16 kHz mono with an OfflineAudioContext, runs the pipeline inside a Web Worker so the UI never janks, and renders the full probability distribution across all nine instruments β€” not just the winner.

References

Sample audio (bundled, 16 kHz mono, ≀6 s), via Wikimedia Commons β€” see SAMPLES.md: Violin (Clngre, CC BY-SA 3.0), Trumpet (Ovinus Real, CC BY-SA 4.0), Guitar (Silcon, CC BY-SA 3.0), Flute (hokuspokus, Public domain).