WASM package to create Waveforms in-browser, processing takes around 1-2ms for most samples as opposed to 20-50ms in raw JS
Supports all codecs except for MKV (.webm), thanks to amazing Project Symfonia
Available on NPM.js
npm i --save-dev waveform-rs
You need to proc the init()
method which calls WebAssembly.instantiate
, it can be wrapped as below to avoid snake_case'ing
import init, { audio_to_waveform } from "waveform-rs";
const processAudioData = async (
data: Uint8Array,
samplesPerSecond?: number,
): Promise<Float32Array> => {
await init();
const waveform = audio_to_waveform(data, samplesPerSecond);
return waveform;
};
In case you are dealing with blobs, you can, the file format is going to be determined automatically
const response = await fetch(sample);
const arrayBuffer = await response.arrayBuffer();
const data = await processAudioData(
new Uint8Array(arrayBuffer),
samplesPerSecond,
);