Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

audio-rs

image

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

Installation

Available on NPM.js

npm i --save-dev audio-rs

Usage

You 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;
};

About

generate waveform from any audio file

Resources

Stars

8 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages