Reputation: 1542
I'm in dire need of help understanding how to read volume-levels for a WAV-file. Basically, I need a way to figure out the volume at specific times in an audio file (0.01s seconds in for example), in order to find specific "peaks".
I'm using node-wav (https://github.com/TooTallNate/node-wav) and the following code:
var file = fs.createReadStream('test.wav'),
reader = new wav.Reader(),
bufSize = 4410;
reader.on('readable', function() {
while (null !== (chunk = reader.read(bufSize))) {
// I'M TOTALLY LOST HERE
}
});
Basically, I have no idea what bufSize to use (I'm pretty sure it depends on how "fine-tuned" i want the results.. Also I know I have to average the data in every chunk somehow, and I tried taking the average values etc. but can't seem to get any useful data..
Any help would be appreciated!
Upvotes: 1
Views: 4625
Reputation: 14897
I don't think you need the bufSize
here, just follow the example of wav.Reader
:
var fs = require('fs');
var wav = require('wav');
var file = fs.createReadStream('track01.wav');
var reader = new wav.Reader();
// the "format" event gets emitted at the end of the WAVE header
reader.on('format', function (format) {
// do your calculation here, using format
});
// pipe the WAVE file to the Reader instance
file.pipe(reader);
Anyway, according to the WAV file format, the size and the number of the data chunks can be extracted from the header block of a WAV file.
Upvotes: 1