Created
March 20, 2016 18:25
-
-
Save stpettersens/453ae07abd8630a4fc28 to your computer and use it in GitHub Desktop.
Server which listens for PCM stream and outputs a WAVE file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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