Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mohayonao/wav-decoder
promise-based wav decoder
https://github.com/mohayonao/wav-decoder
Last synced: 4 months ago
JSON representation
promise-based wav decoder
- Host: GitHub
- URL: https://github.com/mohayonao/wav-decoder
- Owner: mohayonao
- Archived: true
- Created: 2015-03-16T14:20:04.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-10T21:02:19.000Z (over 7 years ago)
- Last Synced: 2024-08-18T16:27:38.820Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 2.49 MB
- Stars: 40
- Watchers: 4
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# wav-decoder
[![Build Status](https://img.shields.io/travis/mohayonao/wav-decoder.svg?style=flat-square)](https://travis-ci.org/mohayonao/wav-decoder)
[![NPM Version](https://img.shields.io/npm/v/wav-decoder.svg?style=flat-square)](https://www.npmjs.org/package/wav-decoder)
[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://mohayonao.mit-license.org/)> promise-based wav decoder
## Installation
```
$ npm install wav-decoder
```## API
- `decode(src: ArrayBuffer, [opts: object]): Promise`
- if provide an instance of `Buffer`, it is converted to `ArrayBuffer` like `Uint8Array.from(src).buffer` implicitly.
- `opts.symmetric` decode to symmetrical values (see [#14](https://github.com/mohayonao/wav-decoder/issues/14))
- `decode.sync(src: ArrayBuffer, [opts: object]): AudioData`
- synchronous version##### Returns
```js
interface AudioData {
sampleRate: number;
channelData: Float32Array[];
}
```## Usage
```js
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