简体   繁体   中英

Convert Raw to Wav Streams in NodeJS

I am using a nodeJS library naudiolink — to record sound from a 2 microphones (total 4 channel audio with each microphone being stereo). This library spits out a .raw file in the following specs: 16 BIT, 48000Hz Sample Rate, Channel Count 4

// var portAudio = require('../index.js');
var portAudio = require('naudiodon');
var fs = require('fs');

//Create a new instance of Audio Input, which is a ReadableStream
var ai = new portAudio.AudioInput({
  channelCount: 4,
  sampleFormat: portAudio.SampleFormat16Bit,
  sampleRate: 48000,
  deviceId: 13
});

ai.on('error', console.error);

//Create a write stream to write out to a raw audio file
var ws = fs.createWriteStream('rawAudio_final.raw');

//Start streaming
ai.pipe(ws);
ai.start();

process.once('SIGINT', ai.quit);

Instead of the .raw file, I am trying to convert this to two individual .wav files. With the above encoding and information, what would be the best way to do so? I tried to dig around for easy ways to deinterleaving and getting .wav but seem to be hitting a wall.

The addon is a wrapper around a C++ library called portaudio which according to its documentation supports writing to a WAV file.

What you could do is extend the addon and bind a NodeJS function to the underlying C++ function that write to WAV . This will give you a good performance if it is an issue.

If you want something easier you could look up utilities that do the conversion and call them from within your script using ex like this

Look similar to this question .

You may also take a look here to know how to create wav file from javascript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM