Closed VolodymyrTymets closed 7 years ago
Try using https://www.npmjs.com/package/wav:
var FileWriter = require('wav').FileWriter;
var mic = require('mic'); // requires arecord or sox, see https://www.npmjs.com/package/mic
var micInstance = mic({
rate: '16000',
channels: '1',
debug: true
});
var micInputStream = micInstance.getAudioStream();
var outputFileStream = new FileWriter('./test.wav', {
sampleRate: 16000,
channels: 1
});
micInputStream.pipe(outputFileStream);
micInstance.start();
setTimeout(function() {
micInstance.stop();
}, 5000);
I just put that together for https://github.com/TooTallNate/node-wav/pull/25, but it looks like it would also do what you want.
Yup the above is how I would do it as well. Thanks @nfriedly
I need make mathematical calculation with sound stream from microphone. For now it can be fft transforming. I made this before with .wav file by decoding via wav-decoder.
But when i try decode buffer from microphone as below, a have exeption
Invalid WAV file
.Even, when i tried write wav file format then decode it. I also had exeption.
I suppose, this because raw format have no header.
So can i some way decode micInputStream data directly or write wav file format via mic?