← All models

audio-classification · audio · WASM · ~83 MB

Speech Commands — spot a spoken keyword on-device

Wake-words and voice control don't need the cloud. This is an Audio Spectrogram Transformer — the same model that names 527 general sounds — but fine-tuned on Google Speech Commands v2 to do one narrow thing extremely well: recognise 35 short spoken keywords like yes, no, up, down, left, right, on, off, stop, go and the digits. Say a word into your mic and it tells you which command it heard, with a confidence — entirely on your device.

At a glance

ModelXenova/ast-finetuned-speech-commands-v2
Task / pipelineaudio-classification
ArchitectureAudio Spectrogram Transformer (ViT over a log-mel spectrogram), fine-tuned on Speech Commands v2
Classes35 keywords — yes, no, up, down, left, right, on, off, stop, go, zero–nine, plus bed, bird, cat, dog, happy, house, marvin, sheila, tree, wow, backward, forward, follow, learn, visual
Input16 kHz mono audio, ~1 second per command → 128-band log-mel spectrogram
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; WebGPU used when an adapter exists)
Download~83 MB, cached after first load
LicenseBSD-3-Clause (MIT AST); Speech Commands dataset CC-BY-4.0 (Google)
Web APIsWebAssembly, Web Workers, Web Audio, MediaRecorder, Canvas — all Baseline widely available

Run it

Pick a sample command, drop an audio clip, or record yourself saying a single word, then hit Recognise. Keep it to about one second — these are short-utterance commands, not sentences.

Drop an audio file here, or click to choose

See inside — the short-utterance spectrogram

The model doesn't hear a waveform — it looks at a picture of it. Each ~1-second command becomes a log-mel spectrogram: time runs left→right, frequency runs bottom→top, brightness is energy. A spoken word is a compact shape — the sweep of a vowel, the burst of a consonant — and the transformer attends over that little image to pick a keyword. Below is the real spectrogram of your clip, plus every one of the 35 commands ranked by score.

← earlier · time · later → · ↓ low frequency · high frequency ↑

Recognise a clip to see the spectrogram and full ranking.

Why it matters

Keyword spotting is the piece of voice UI that has to be always-on, private, and cheap — you can't stream every second of mic audio to a server just to notice someone said "stop". A tiny on-device classifier makes hands-free control a local function call: no key, no bill, no audio leaving the page.

Use cases

Basics

Classify a sample command and read the ranked keywords — feel what the model does.

Practical

A hands-free voice control pad: say up/down/left/right/stop and watch a dot move.

Wild

Live wake-word meter — pick a word and watch the confidence spike when you say it.

Multi-model

Command router: "go" wakes Whisper to transcribe whatever you say next.

How the API works

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

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

const recognise = await pipeline(
  "audio-classification",
  "Xenova/ast-finetuned-speech-commands-v2",
  { dtype: "q8" },              // downloads + caches ~83 MB once
);

const output = await recognise(audio, { top_k: 5 });
// audio = Float32Array @ 16 kHz mono, ~1 s (decode with the Web Audio API)
// → [{ label: "stop", score: 0.99 }, { label: "up", score: 0.004 }, … ]

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 the model classifies.

References