audio-classification · audio · WASM · ~90 MB
The Audio Spectrogram Transformer turns a sound into a 128-band log-mel spectrogram and reads that spectrogram like an image — the same trick a Vision Transformer plays on photos. Give it a clip and it returns the most likely sounds from 527 AudioSet classes — speech, a dog, a siren, applause, a guitar — entirely on your device.
| Model | Xenova/ast-finetuned-audioset-10-10-0.4593 |
|---|---|
| Task / pipeline | audio-classification |
| Architecture | Audio Spectrogram Transformer (ViT over a log-mel spectrogram), fine-tuned on AudioSet |
| Classes | 527 AudioSet labels (speech, music, animals, vehicles, alarms, environment…) |
| Input | 16 kHz mono audio → 128×~1024 log-mel spectrogram |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; WebGPU used when an adapter exists) |
| Download | ~90 MB, cached after first load |
| License | BSD-3-Clause (MIT/ast-finetuned-audioset) |
| 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, then hit Classify. AST returns the sounds it hears, most confident first.
The bundled Speech clip (not the tone or whistle) is a JFK inaugural excerpt (20 January 1961), spoken by John F. Kennedy — public domain, U.S. government work · JFK audio source and attribution record.
AST doesn't hear a waveform — it looks at a picture of it. Every clip becomes a log-mel spectrogram: time runs left→right, frequency runs bottom→top (low to high), and brightness is energy. The transformer cuts that image into patches and attends over them, exactly like a Vision Transformer over an image. Below is the real spectrogram of your clip, plus the full top-15 the model returned.
← earlier · time · later → · ↓ low frequency · high frequency ↑
| # | AudioSet label | score |
|---|
Sound is a channel most apps ignore because "understanding audio" used to mean a cloud API and an upload. AST makes it a local function call — private, offline, free per call — so the microphone becomes a sensor your page can actually reason about.
Classify a sample sound and read the top AudioSet labels — feel what the model does.
A live sound-event monitor / accessibility alerter that watches the mic for a chosen sound.
"What's that sound?" — hold something up to the mic and let AST guess in real time.
AST routes audio: speech → Whisper transcribes it; everything else gets tagged.
Classification is one call with Transformers.js. Feed a 16 kHz mono Float32Array:
import { pipeline } from "@huggingface/transformers";
const classify = await pipeline(
"audio-classification",
"Xenova/ast-finetuned-audioset-10-10-0.4593",
{ dtype: "q8" }, // downloads + caches ~90 MB once
);
const output = await classify(audio, { top_k: 5 });
// audio = Float32Array @ 16 kHz mono (decode with the Web Audio API)
// → [{ label: "Speech", score: 0.71 }, { label: "Music", score: 0.06 }, … ]
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 computes the log-mel spectrogram
you see — the same representation AST classifies.