ArtskydJ / node-sox-stream

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

How create realtime reading stream ? #22

Closed zababurinsv closed 4 years ago

zababurinsv commented 4 years ago

Hi. I have createing radio stream.

in your exmple i see how convert file.

var src = fs.createReadStream('radio.mp3')
var transcode = sox({
    input: {
      type: 'radio.mp3'.split(".").pop()
    },
    output: {
        bits: 16,
        rate: 44100,
        channels: 2,
        type: 'wav'
    }
})
var dest = fs.createWriteStream('song.wav')
src.pipe(transcode).pipe(dest)

but how can I start playing the file, receive interest until the end of playback, samples if possible and transfer to the stream. So that people would open the channel and hear what is currently playing ?

ArtskydJ commented 4 years ago

This library buffers the input so that sox is more reliable. When it has all the input, it streams it through sox, which streams it out. So you can't do realtime transcoding with this library.

I recommend opening up the source code, and copying the relevant child_process commands to get you started.

Sox will handle some realtime transcoding, I think, but has trouble with certain input types or output types.