TooTallNate / node-wav

`Reader` and `Writer` streams for Microsoft WAVE audio files
MIT License
181 stars 37 forks source link

Audio drastically slowed down? #30

Open behrendCoreysGIT opened 5 years ago

behrendCoreysGIT commented 5 years ago

When I run the "Example usage with mic:" code for saving the stream as a .wav the resulting file is drastically slowed down. So a 5-second recording is a minimum of 10s. Note that if I speed this audio up in a video editing software it sounds perfect. (Windows 10 / SoX 14.4.1)

//The code var FileWriter = require('wav').FileWriter; var mic = require('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);

sergejkurbanov commented 1 year ago

I ran into the same issue. Recorded .wav file was ~twice as long, slowed down, way deeper voice.

After a bunch of random tinkering, what fixed it for me was putting the FileWriter's sampleRate to double the mic's.

For example like this:

var micInstance = mic({
  rate: '16000',
  channels: '1',
  debug: true
});

var micInputStream = micInstance.getAudioStream();

var outputFileStream = new FileWriter('./test.wav', {
  sampleRate: 32000, // double the rate above
  channels: 1
});