wav-decoder-ts
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

wav-decoder-ts

NPM Version License: MIT

promise-based wav decoder

Installation

npm install wav-decoder-ts

API

  • decode(src: ArrayBuffer, [opts: object]): Promise<AudioData>
    • if provide an instance of Buffer, it is converted to ArrayBuffer like Uint8Array.from(src).buffer implicitly.
    • opts.symmetric decode to symmetrical values
  • decode.sync(src: ArrayBuffer, [opts: object]): 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

Readme

Keywords

Package Sidebar

Install

npm i wav-decoder-ts

Weekly Downloads

5

Version

1.0.3

License

MIT

Unpacked Size

10.4 kB

Total Files

5

Last publish

Collaborators

  • uglymon