promise-based wav decoder
$ npm install wav-decoder
decode(src: ArrayBuffer, [opts: object]): Promise<AudioData>
- if provide an instance of
Buffer
, it is converted toArrayBuffer
likeUint8Array.from(src).buffer
implicitly. opts.symmetric
decode to symmetrical values (see #14)
- if provide an instance of
decode.sync(src: ArrayBuffer, [opts: object]): AudioData
- synchronous version
interface AudioData {
sampleRate: number;
channelData: Float32Array[];
}
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
});
MIT