Skip to content

Instantly share code, notes, and snippets.

@stpettersens
Created March 20, 2016 18:25
Show Gist options
  • Save stpettersens/453ae07abd8630a4fc28 to your computer and use it in GitHub Desktop.
Save stpettersens/453ae07abd8630a4fc28 to your computer and use it in GitHub Desktop.
Server which listens for PCM stream and outputs a WAVE file.
'use strict';
const wav = require('wav');
const BinaryServer = require('binaryjs').BinaryServer;
let server = BinaryServer({port: 8080});
let out = null;
server.on('connection', function(client) {
client.on('stream', function(stream, meta) {
out = new wav.FileWriter('out.wav', {
channels: 1,
sampleRate: 48000,
bitDepth: 16
});
stream.pipe(out);
stream.on('end', function() {
out.end();
});
});
client.on('close', function() {
if(out != null) {
out.end();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment