← All models

zero-shot-audio-classification · audio + language · WASM · ~160 MB

CLAP — name a sound with any labels you invent

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.

At a glance

ModelXenova/clap-htsat-unfused
Task / pipelinezero-shot-audio-classification
ArchitectureHTSAT audio encoder + RoBERTa text encoder → shared 512-d space (LAION CLAP)
Input48 kHz mono audio → 64-band log-mel spectrogram · free-text labels
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; WebGPU used when an adapter exists)
Download~160 MB (model_quantized.onnx), cached after first load
LicenseApache-2.0 (LAION CLAP)
Web APIsWebAssembly, Web Workers, Web Audio, MediaRecorder, Canvas — all Baseline widely available

Run it

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.

Drop an audio file here, or click to choose

See inside

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 ↑

Classify a clip to see the spectrogram and the raw numbers.

Why it matters

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.

Use cases

Basics

One sound, your labels — feel zero-shot audio classification first-hand.

Practical

Sound-event tagging & content-moderation triage against a policy vocabulary.

Wild

Match a sound to emojis and moods — a synaesthesia machine for audio.

Multi-model

CLAP triages, then Whisper transcribes anything it hears as speech.

How the API works

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.

References