zero-shot-audio-classification · audio + language · WASM · ~160 MB
CLAP is CLIP for sound. It learned one shared space for audio and words, so you can hand it a
clip and a handful of labels you make up on the spot — a dog barking,
rain, applause, a guitar — and it scores how well each one
matches what it hears. No fixed class list, no training, nothing leaves your device.
| Model | Xenova/clap-htsat-unfused |
|---|---|
| Task / pipeline | zero-shot-audio-classification |
| Architecture | HTSAT audio encoder + RoBERTa text encoder → shared 512-d space (LAION CLAP) |
| Input | 48 kHz mono audio → 64-band log-mel spectrogram · free-text labels |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; WebGPU used when an adapter exists) |
| Download | ~160 MB (model_quantized.onnx), cached after first load |
| License | Apache-2.0 (LAION CLAP) |
| Web APIs | WebAssembly, Web Workers, Web Audio, MediaRecorder, Canvas — all Baseline widely available |
Pick a sample, drop an audio file, or record from your mic; type comma-separated labels; hit Classify. The bars are a softmax over CLAP's similarity between the sound and each label.
CLAP turns your clip into one 512-number vector and each label into its own 512-number vector, then measures the cosine similarity (the angle) between the audio vector and every label vector. Those similarities are scaled into logits, and a softmax turns them into the percentages above. Same sound, different words → different winner. The audio encoder itself reads a 64-band log-mel spectrogram — the real image of your clip is below (time left→right, frequency low→high, brightness is energy).
← earlier · time · later → · ↓ low frequency · high frequency ↑
| Label | cosine sim | logit (×scale) | softmax |
|---|
Every other audio classifier is stuck with the classes it was trained on (AudioSet's 527, say). CLAP isn't: the label set is an input, decided at runtime, in the browser, for free. That turns "collect a labelled dataset and fine-tune" into "write a list of words" — for sound.
glass breaking, a baby crying, a smoke alarm) with no training pipeline and no audio leaving the device.gunshot, screaming, music, safe) client-side before anything is uploaded.calm, chaotic, ominous) that no fixed classifier has a class for.One sound, your labels — feel zero-shot audio classification first-hand.
Sound-event tagging & content-moderation triage against a policy vocabulary.
Match a sound to emojis and moods — a synaesthesia machine for audio.
CLAP triages, then Whisper transcribes anything it hears as speech.
The whole thing is three lines with Transformers.js. The label list is just an argument:
import { pipeline } from "@huggingface/transformers";
const classify = await pipeline(
"zero-shot-audio-classification",
"Xenova/clap-htsat-unfused",
{ dtype: "q8" }, // downloads + caches ~160 MB once
);
const output = await classify(audio, ["a dog barking", "rain", "applause"]);
// audio = Float32Array @ 48 kHz mono (decode with the Web Audio API)
// → [{ label: "a dog barking", score: 0.94 }, { label: "rain", score: 0.05 }, … ]
// score is the softmax over CLAP's audio↔label cosine similarities
This page goes one level deeper for "See inside": it reuses the pipeline's own model, processor,
and tokenizer to read the raw logits_per_audio and the audio_embeds /
text_embeds tensors from a single forward pass — the same call, just keeping the
intermediate numbers. Inference runs in a Web Worker so the page never janks.