Skip to content
WebAI

HT-Demucs stem separation in a tab: 7.8-second chunks and a six-minute cap

Stem separation runs as a bare ONNX session in a Worker, cutting audio into overlapping 7.8-second segments and joining them back; the six-minute cap is forced by accumulator memory. The audio classification page has its own story: the smallest tier printed on the card is not the q8 file the page downloads.

The bare HT-Demucs ONNX graph runs inside a Worker, and the code caps input at six minutes. The comment next to that cap gives the reason without dressing it up: every stem and every channel needs a full-length float32 accumulator. Longer audio would need streaming output as inference goes. For now the track is split into 7.8-second segments and joined back with overlap-add.

CardMeasured sizeWhat loadsOutput
HT Demucs (4 stems)~158 MiB · fp16htdemucs_fp16weights.onnxVocals / drums / bass / other
HT Demucs (6 stems, default)~130 MiB · fp16htdemucs_6s_fp16weights.onnx4 stems plus guitar and piano
Open-UnmixNot measured (historic estimate ~60 MB)The 4-stem file, with an asteriskSame 4 stems
Measured sizes for the three catalogue cards and the weights actually loaded

The 6-stem file is about 28 MiB smaller than the 4-stem one. They are exports from two different repositories. The fp16 suffix on a card names the precision tier, and fp16 weights are what load, while the input tensor handed to the session is float32.

Inside the Worker

Input audio is decoded at 44.1 kHz into left and right Float32Arrays, and the buffers are transferred to the Worker with postMessage to avoid a copy. The model contract is mix [1, 2, 343980] to stems [1, N, 2, 343980], and 343980 samples is exactly 7.8 seconds. Overlap is one quarter, the stride is 257985 samples, and a linear fade window tapers both ends. Each stem and channel has its own full-length accumulator, normalised by weight at the end, before the result goes back to the main thread.

Segmentation and the session call in stems.worker.ts
const SEG = 343_980;              // 7.8 s @ 44.1 kHz
const OVERLAP = SEG / 4;
const STRIDE = SEG - OVERLAP;     // 257985
for (let i = 0; i < OVERLAP; i++) win[i] = win[SEG - 1 - i] = i / (OVERLAP - 1);
const res = await session.run({ mix: new ort.Tensor('float32', input, [1, 2, SEG]) });
const out = res.stems.data;        // [1, N, 2, SEG]

Choosing 2 stems on the demo takes the vocal stem and sums every other stem sample by sample into an instrumental track. With the default 6-stem card, that instrumental is a sum of five stems. The shift trick slider only affects demo mode and is not wired into the real-weights branch. Players are mono, so the two channels are averaged, and gain is reduced only when the peak exceeds 1. Otherwise the relative levels between stems are preserved.

The session is wasm, single-threaded, with the graph optimiser off. The slowest part of a first run is session creation, which the page labels as roughly 30 seconds. Weights go into Cache Storage, so a second run downloads nothing. There are two built-in samples, a Chinese vocal with backing and an English vocal with backing.

The audio classification page

audio/audio-classification uses the Transformers.js audio-classification pipeline. AST scores the 527 AudioSet classes, while Wav2Vec2 keyword spotting recognises 12 spoken commands such as yes, no, up and down. The two catalogue cards list ~49.0 MiB · q4f16 and ~63.5 MiB · q4f16 at their smallest tier, but the page loads q8, which means 86.6 MiB and 91.4 MiB files. The card shows the minimum tier and the result bar reports the bytes downloaded on that run. MediaPipe Audio Classifier is listed at ~3.9 MiB, but it needs a separate task asset, so the page loads AST instead and marks the substitute.

Top-K runs from 1 to 10 with a default of 5. The three built-in samples are English speech, vocals with music and a music bed. The last two are there to show whether a model counts the backing track as speech. The demo-mode fallback scores three classes (speech, music, ambient noise) from the energy ratio around a 500 Hz low-pass split and the zero-crossing rate, which has nothing to do with the 527 AudioSet labels.

All posts →

← Back to all posts