Pipe audio streams to your ears.
Dan Motzenbecker, MIT License
ear-pipe is a duplex stream that allows you to pipe any streaming audio data to your ears (by default), handling any decoding automatically for most formats. You can also leverage this built-in decoding by specifying an output encoding and pipe the output stream somewhere else.
ear-pipe relies on the cross-platform audio utility SoX, so make sure that's installed first.
$ npm install --save ear-pipe
var EarPipe = require'ear-pipe';ep = /* <type>, <bitrate>, <transcode-type> */;
When arguments are omitted (e.g.
ep = new EarPipe;), the type defaults to
'mp3', the bitrate defaults to
16, and the third argument is
that the pipe destination is your ears rather than a transcoded stream.
If your input encoding isn't mp3, make sure you set it to one of the formats supported by SoX:
8svx aif aifc aiff aiffc al amb au avr cdda cdr cvs cvsd cvu dat dvms f32 f4 f64f8 fssd gsm gsrt hcom htk ima ircam la lpc lpc10 lu maud mp2 mp3 nist prc raw s1s16 s2 s24 s3 s32 s4 s8 sb sf sl sln smp snd sndr sndt sou sox sph sw txw u1 u16u2 u24 u3 u32 u4 u8 ub ul uw vms voc vox wav wavpcm wve xa
Let's pipe some number station audio to our ears right as it comes off the wire:
If your connection and speakers work, you should hear it as it downloads.
Let's send multiple audio streams to the same ear-pipe:
var ep =telstar = fscreateReadStream'./telstar.mp3'cream = fscreateReadStream'./cream.mp3';httpget'' respipeep ;telstarpipeep;creampipeep;
Since only one chunk passes through at a time, this DJ set should have plenty of cuts.
Since we're decoding the audio on the fly, we can specify that we'd like to use that output for another destination besides our ears:
// null arguments mean defaults, true implies default output encoding (wav)var ep = new EarPipe(null, null, true),hotel = fs.createReadStream('./hotel.mp3');hotel.pipe(ep).pipe(fs.createWriteStream('./hotel.wav'));
Or pipe to another process:
var ep = new EarPipe('wav'),epTrans = new EarPipe(null, null, true),audio = someStreamingNetworkData();audio.pipe(epTrans).pipe(ep);epTrans.pipe(anotherStreamingAudioConsumer);
Kill an ear-pipe instance by calling its
kill() method. If you're interested
in the underlying SoX process, access