4

I have an internet audio stream that's constantly being broadcast (accessible via http url), and I want to somehow record that with NodeJS and write files that consist of one-minute segments.

Every module or article I find on the subject is all about streaming from NodeJS to the browser. I just want to open the stream and record it (time block by time block) to files.

Any ideas?

mido
  • 24,198
  • 15
  • 92
  • 117
Danny Ackerman
  • 997
  • 1
  • 10
  • 25
  • If you could give me a url, I could whip up a demo for you! – bren Jul 24 '15 at 03:53
  • Could you use [this solution](http://stackoverflow.com/questions/20850396/stream-recorded-audio-from-browser-to-server) but instead of writing the data stream out, write it to file? – brandonscript Jul 24 '15 at 04:02

1 Answers1

1

I think the project at https://github.com/TooTallNate/node-icy makes this easy, just do what you need to with the res object, in the example it is sent to the audio system:

var icy = require('icy');
var lame = require('lame');
var Speaker = require('speaker');

// URL to a known ICY stream
var url = 'http://firewall.pulsradio.com';

// connect to the remote stream
icy.get(url, function (res) {

  // log the HTTP response headers
  console.error(res.headers);

  // log any "metadata" events that happen
  res.on('metadata', function (metadata) {
    var parsed = icy.parse(metadata);
    console.error(parsed);
  });

  // Let's play the music (assuming MP3 data).
  // lame decodes and Speaker sends to speakers!
  res.pipe(new lame.Decoder())
     .pipe(new Speaker());
});
centic
  • 15,565
  • 9
  • 68
  • 125