WASM package to create Waveforms in-browser, processing takes around 1-2ms for most samples as opposed to 20-50ms in raw JS
Thanks to amazing Project Symfonia
Available on NPM.js
npm i --save-dev audio-rsYou need to proc the init() method which calls WebAssembly.instantiate somewhere in your code. Then you usage is as follows:
import { AudioMetadata, processAudio as audioRsProcessAudio } from "audio-rs";
export const processAudio = (
data: Uint8Array,
waveformResolution: number = 100
): AudioData => {
const { metadata, waveform } = audioRsProcessAudio(
data,
true,
waveformResolution
);
const sharedBuffer = waveform
? new SharedArrayBuffer(waveform.length * Int32Array.BYTES_PER_ELEMENT)
: null;
if (sharedBuffer && waveform) {
new Float32Array(sharedBuffer).set(waveform);
}
const x = {
waveformBuffer: sharedBuffer,
waveformResolution,
metadata,
} as AudioData;
return x;
};
export const getAudioMetadata = (data: Uint8Array): AudioMetadata => {
const { metadata } = audioRsProcessAudio(data, false);
return metadata;
};