npm integration
Use the sidespread package from Node.js, browser bundles, and Web Audio.
The sidespread package publishes Web and Node.js WASM builds behind one conditional export. Both
environments expose the same synchronous processing API after initialization.
Install
Bashnpm install sidespread
Node.js
JavaScriptimport { init, process } from 'sidespread';await init();const { audio, report } = process( interleavedStereo, 48_000, { dspStrength: 2, bandwidthExtension: true }, ({ stage, progress }) => console.log(stage, Math.round(progress * 100)));
Node selects the node export and initializes the WASM module when it is imported. Keep the
await init() call so code can move between Node and Web without branching.
Browser and Web Audio
JavaScriptimport { deinterleave, init, interleave, process } from 'sidespread';await init();const source = await audioContext.decodeAudioData(arrayBuffer);if (source.numberOfChannels !== 2) throw new Error('Stereo audio is required');const input = interleave(source.getChannelData(0), source.getChannelData(1));const { audio, report } = process(input, source.sampleRate, {}, ({ stage, progress }) => { self.postMessage({ stage, progress });});const { left, right } = deinterleave(audio);const output = audioContext.createBuffer(2, left.length, source.sampleRate);output.copyToChannel(left, 0);output.copyToChannel(right, 1);
Run long files in a Web Worker. process() is CPU-bound and synchronous inside the calling thread.
Its fourth argument receives real stage progress from Rust. The live demo forwards those
events from its worker and never uploads audio.
The engine bounds STFT memory by processing long repair stages in 8-second chunks with 250 ms of surrounding context. The demo also transfers the decoded source to its Worker and keeps only compact frequency summaries on the main thread.
Result handling
process() always returns an interleaved Float32Array. Check report.processed before deciding
whether to replace the original file. A false value means no stage produced an accepted change.
JavaScriptif (result.report.processed) { await saveAudio(result.audio);}
See the npm API reference for every option and report field.