I've been trying to create a Node.js audio streaming script using Socket.io and Node.js microphone library.
The problem is that Socket.io does not pipe the audio to a remote server when SoX/ALSA is still recording the audio.
audio-stream-tx (client):
var io = require('socket.io-client');
var ss = require('socket.io-stream');
var mic = require('microphone');
var fs = require('fs');
var socket = io.connect('ws://localhost:25566');
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.');
});
audio-stream-rx (server):
var io = require('socket.io')();
var ss = require('socket.io-stream');
var fs = require('fs');
var port = 25566;
io.on('connection', function (socket) {
ss(socket).on('stream-data', function(stream, data) {
console.log('Incoming> Receiving data stream.');
stream.pipe(fs.createWriteStream(Date.now() + ".wav", { flags: 'a' }));
});
});
io.listen(port);
The microphone library spawns either a SoX/ALSA command (depending on the platform) to record the microphone's audio. The scripts above work fine though. Just that the audio data is only piped to the stream once mic.stopCapture()
is called.
Is there a workaround to force socket.io-stream to stream audio data the moment mic.startCapture()
is called?
Aucun commentaire:
Enregistrer un commentaire