function generate() { if (c < words.length) { console.log(words[c]); mic.startCapture({ }); var bufs = []; // don't write the header on the first wav if (!first) { bufs.push(header); } first = false; mic.audioStream.on('data', function(data) { bufs.push(data); }); setTimeout(function() { var buf = Buffer.concat(bufs); fs.writeFile('./audio/' + words[c] + '.wav', buf); c++; },1500); } else { process.exit(1); } }
/** * Project audio-stream-tx * @author Jia Jian (@jia_jian) * @license MIT */ var io = require('socket.io-client'); // why not just socket.io? var ss = require('socket.io-stream'); // Socket.io Stream. var mic = require('microphone'); var fs = require('fs'); // File system. var socket = io.connect('ws://localhost:25565'); var stream = ss.createStream(); ss(socket).emit('stream-data', stream); mic.startCapture(); mic.audioStream.pipe(stream); process.on('SIGINT', function () { mic.stopCapture(); console.log('Got SIGINT. Press Control-D to exit.'); });