Package Exports
- wav-decoder
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (wav-decoder) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
wav-decoder
promise-based wav decoder
Installation
$ npm install wav-decoderAPI
decode(src: ArrayBuffer): Promise<AudioData>- if provide an instance of
Buffer, it is converted toArrayBufferlikeUint8Array.from(src).bufferimplicitly.
- if provide an instance of
decode.sync(src: ArrayBuffer): AudioData- synchronous version
Returns
interface AudioData {
sampleRate: number;
channelData: Float32Array[];
}Usage
const fs = require("fs");
const WavDecoder = require("wav-decoder");
const readFile = (filepath) => {
return new Promise((resolve, reject) => {
fs.readFile(filepath, (err, buffer) => {
if (err) {
return reject(err);
}
return resolve(buffer);
});
});
};
readFile("foobar.wav").then((buffer) => {
return WavDecoder.decode(buffer);
}).then(function(audioData) {
console.log(audioData.sampleRate);
console.log(audioData.channelData[0]); // Float32Array
console.log(audioData.channelData[1]); // Float32Array
});License
MIT