audio-classification Β· audio Β· WASM Β· ~95 MB
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.
| Model | onnx-community/Musical-Instrument-Classification-ONNX |
|---|---|
| Task / pipeline | audio-classification |
| Architecture | wav2vec2-base with a sequence-classification head (Wav2Vec2ForSequenceClassification) β reads the raw 16 kHz waveform directly |
| Classes | 9 instruments: Acoustic guitar, Bass guitar, Drum set, Electric guitar, Flute, Hi-hats, Keyboard, Trumpet, Violin |
| Input | 16 kHz mono Float32Array, mean/variance normalised |
| Quantization | q8 (8-bit) ONNX β onnx/model_quantized.onnx |
| Backend | WebAssembly (runs anywhere; WebGPU used when an adapter exists) |
| Download | ~95 MB, cached after first load |
| License | Apache-2.0 (wav2vec2 base) |
| Web APIs | WebAssembly, 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.
Pick a sample, drop an audio clip, or record an instrument from your mic, then hit Identify instrument.
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).
| instrument | probability |
|---|
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.
Identify the instrument in a clip and see the full confidence distribution.
A sample-library sorter β classify several clips and group them into instrument buckets.
Instrument over time β slide a window across a clip and watch which instrument leads.
Instrument + note pitch together: what is playing, and which note.
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.
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).