ArtskydJ / node-sox-stream

:mega: A stream-friendly wrapper around SoX
53 stars 14 forks source link

How to connect additional output streams? #7

Closed mk-pmb closed 6 years ago

mk-pmb commented 7 years ago

Hi, thanks for maintaining this wrapper! While it's obvious how to pipe audio input and audio output, how do I attach my streams for additional output like spectrogram or noiseprof? I run node.js from within a bash shell, so I could probably solve the sox side by giving filenames like /dev/fd/14 and /dev/fd/15 (at least I hope that feature passes though node.js), but the wrapper would have to spawn the sox process with these file descriptiors connected to either my streams, or its own streams that I can pipe to mine.

ArtskydJ commented 7 years ago

Sorry, I'm not quite sure what you're asking...

If you want to pipe one transcode to multiple places, you can do

var soxOutput = fs.createReadStream('song.wav').pipe( sox({ output: { type: 'flac' } }) )
soxOutput.pipe(stream1)
soxOutput.pipe(stream2)

sox-stream does not currently support multiple inputs files. Is that what you're wanting?


The easiest solution might be to launch sox using child_process, and maybe it would be easiest to handle arguments with hash-to-array.

// untested
var childProcess = require('child_process')

var sox = childProcess .spawn('sox', '--type=wav inputfile.wav --type=flac outputfile.flac')
ArtskydJ commented 6 years ago

@mk-pmb since I haven't heard from you regarding this, I'm going to close this issue now. Reply with a comment (and @-reply me?) with any follow-up questions, and I can re-open.