node-wav2
Reader
and Writer
streams for Microsoft WAVE audio files
This module offers streams to help work with Microsoft WAVE files.
Credits
This repo is just a fork from node-wav with few fixes.
Installation
Install through npm:
$ npm install wav2
Example
Here's how you would play a standard PCM WAVE file out of the speakers using
node-wav
and node-speaker
:
var fs = ;var wav = ;var Speaker = ;var file = fs;var reader = ;// the "format" event gets emitted at the end of the WAVE headerreader;// pipe the WAVE file to the Reader instancefile;
API
Reader()
The Reader
class accepts a WAV audio file written to it and outputs the raw
audio data with the WAV header stripped (most of the time, PCM audio data will
be output, depending on the audioFormat
property).
A "format"
event gets emitted after the WAV header has been parsed.
Writer()
The Writer
class accepts raw audio data written to it (only PCM audio data is
currently supported), and outputs a WAV file with a valid WAVE header at the
beginning specifying the formatting information of the audio stream.
Note that there's an interesting problem, because the WAVE header also
specifies the total byte length of the audio data in the file, and there's no
way that we can know this ahead of time. Therefore the WAVE header will contain
a byte-length if 0
initially, which most WAVE decoders will know means to
just read until EOF
.
Optionally, if you are in a situation where you can seek back to the beginning
of the destination of the WAVE file (like writing to a regular file, for
example), then you may listen for the "header"
event which will be emitted
after all the data has been written, and you can go back and rewrite the new
header with proper audio byte length into the beginning of the destination
(though if your destination is a regular file, you should use the the
FileWriter
class instead).
FileWriter()
The FileWriter
class.