npm install wav-encoder> promise-based wav encoder
```
$ npm install wav-encoder
- encode(audioData: AudioData, [opts: object]): PromiseaudioData
- should contain two fields sampleRate and channelData.opts
- is an optional parameter which used to design the output wav format.opts.bitDepth
- the number of bits of information in each sampleopts.float
- encode to float valuesopts.symmetric
- encode to symmetrical values (see #10){ float: false, bitDepth: 16 }
- The default format is encode.sync(audioData: AudioData, [opts: object]): ArrayBuffer
-
- synchronous version
`js`
interface AudioData {
sampleRate: number;
channelData: Float32Array[];
}
`js
const fs = require("fs");
const WavEncoder = require("wav-encoder");
const whiteNoise1sec = {
sampleRate: 44100,
channelData: [
new Float32Array(44100).map(() => Math.random() - 0.5),
new Float32Array(44100).map(() => Math.random() - 0.5)
]
};
WavEncoder.encode(whiteNoise1sec).then((buffer) => {
fs.writeFileSync("noise.wav", new Buffer(buffer));
});
``