Reputation: 1683
It's probably something simple and stupid, but the module doesn't have enough documentation in neither the github page or the npm page.
Can someone write a code example of using the .Write function for writing a wav file
Upvotes: 5
Views: 4188
Reputation: 203304
Here's a very simple example using tonegenerator
to generate raw PCM data:
var tone = require('tonegenerator');
var wav = require('wav');
var writer = new wav.FileWriter('output.wav');
writer.write(new Buffer(tone(220, 5))); // 220Hz for 5 seconds
writer.end();
wav.FileWriter()
is a simple wrapper around wav.Writer()
to write to a file directly, similar to this:
var writer = new wav.Writer();
writer.pipe(require('fs').createWriteStream('output.wav'));
writer.write(new Buffer(tone(220, 5)));
writer.end();
Long story short: wav.Writer()
creates a writable stream that you can .write()
raw PCM data to. Most WAVE properties are hardcoded.
Upvotes: 7