ArtskydJ / node-sox-stream

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

sox-stream does not work with file descriptor #20

Open prostosergey opened 4 years ago

prostosergey commented 4 years ago

I'm trying to pass the 'raw' audio-stream from fd: to nodejs sox-stream, but transcode result are always empty, without any warn/errors messages ((

stream = fs.createReadStream(null, {fd: 3, autoClose: false }); 
var transcode = sox({
     global:  { guard: true,  'no-dither': true, norm: true, temp: '/tmpfs' },
     input:   { type: 'raw', 'ignore-length': true, encoding: 'signed-integer', bits: 16, rate: 8000, channels: 1 },
     output:  { type: 'raw' },
});
var dest  = fs.createWriteStream('/tmpfs/song.raw');
stream.pipe(transcode).pipe(dest);

But if I divide into 2 operations, all is well:

// 1 - 'from fd: to file'

stream.pipe(dest);

// 2 - 'from file to transcode'


 var src  = fs.createReadStream('/tmpfs/song.raw'); 
           src.pipe( transcode ).pipe(dest2);

Why sox-stream doesn't work with file descriptor (only with file) ? How to make it work? Thank you!

ArtskydJ commented 4 years ago

I recommend copying the index.js file contents and pasting it into your project. Then maybe change this line to var tmpFile = fs.createReadStream(...) and see if that works.