isomorphic wav data encoder
$ npm install wav-encoder
constructor([format: object])
- format
bitDepth: number = 16
floatingPoint: boolean = false
- format
encode(audioData: AudioData, [format: object]): Promise<ArrayBuffer>
encode(audioData: AudioData, [format: object]): Promise<ArrayBuffer>
interface AudioData {
sampleRate: number;
channelData: Float32Array[];
}
var fs = require("fs");
var WavEncoder = require("wav-encoder");
var audioData = {
sampleRate: 44100,
channelData: [
new Float32Array(100),
new Float32Array(100),
]
};
WavDecoder.encode(audioData).then(function(buffer) {
// buffer is an instanceof Buffer
fs.writeFileSync("foobar.wav", buffer);
});
<script src="/path/to/wav-encoder.js"></script>
var audioData = {
sampleRate: 44100,
channelData: [
new Float32Array(100),
new Float32Array(100),
]
};
function arrayBufferToBase64(buffer) {
return btoa([].slice.call(new Uint8Array(buffer)).map(String.fromCharCode).join(""));
}
WavEncoder.encode(audioData).then(function(buffer) {
// buffer is an instance of ArrayBuffer
new Audio("data:audio/wav;base64," + arrayBufferToBase64(buffer)).play();
});
MIT