wavify-audiobuffer
v1.0.1
Published
convert an AudioBuffer to .wav format
Maintainers
Readme
wavify-audiobuffer
Encodes the contents of an AudioBuffer from the WebAudio API as WAVE. Supports 16-bit PCM, 24bit PCM and 32-bit float data.
This project is a fork and extension/rewrite of the audiobuffer-to-wav npm library.
The package is designed to work in both web, Node.js, and Embedded environments, considering that the web audio api is available or polyfilled.
Installation:
npm i wavify-audiobufferUsage:
wavArrayBuffer = wavifyBuffer(audioBuffer, { ...options });Encodes the AudioBuffer instance as WAV, returning a new array buffer. Interleaves multi-channel data, if necessary.
By default, the function exports with 16-bit PCM.
You can optionally specify 24 or 32-bit bit depth.
Example(s):
import { wavifyBuffer } from "wavify-audiobuffer";
fetch("https://www.example.audio/track.mp3")
.then((response) => {
if (!response.ok) {
throw new Error("Couldn't fetch the track data.");
} else {
return response.arrayBuffer();
}
})
.then((arrayBuffer) => {
audioContext.decodeAudioData(arrayBuffer, (audioBuffer) => {
const waveData = wavifyBuffer(audioBuffer, { bitDepth: 24 });
//consume the waveData buffer
});
})
.catch((error) => {
//handle errors
});See this example for an example of loading an MP3, decoding it, and re-encoding it as a WAV file (in Node.js).
License:
This project is licensed under the terms of MIT, please see the LICENSE.md file for details.
