Skip to content

Instantly share code, notes, and snippets.

@weihanchen
Created March 27, 2018 01:35
Show Gist options
  • Save weihanchen/ec4ba339b2ce6c3f43b90954562c4661 to your computer and use it in GitHub Desktop.
Save weihanchen/ec4ba339b2ce6c3f43b90954562c4661 to your computer and use it in GitHub Desktop.
audio
const portAudio = require('naudiodon');
const fs = require('fs');
const wav = require('wav');
const request = require('request');
const ai = new portAudio.AudioInput({
channelCount: 1,
sampleFormat: portAudio.SampleFormat16Bit,
sampleRate: 8000,
deviceId: -1
});
// const ws = new fileWriter('test.wav', {
// sampleRate: 8000,
// channels: 1
// });
const Writable = require('stream').Writable;
const ws = Writable();
const bufs = [];
ws._write = function (data, enc, next) {
bufs.push(data);
process.nextTick(next);
}
ws.on('finish', () => {
const buf = Buffer.concat(bufs);
fs.writeFileSync('audio.raw', buf);
console.log(buf);
console.log(buf.length);
})
ai.pipe(ws);
ai.start();
ai.on('error', err => console.error);
process.on('SIGINT', () => {
console.log('Received SIGINT. Stopping recording.');
ai.quit();
ws.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment