コード例 #1
0
ファイル: player.js プロジェクト: TooManyBees/djesbe
 mp3: function(cb) {
   var lame = new Lame;
   lame.on('format', function(format) {
     cb(format, lame);
   });
   return lame;
 },
コード例 #2
0
ファイル: server.js プロジェクト: epicmud7/GeoSpell
  request.get(url, function(err, resp, body) {
    body = JSON.parse(body).word;
    if(err) {
      throw err;
    } else if(req.query.type === "text") {
      console.log(body);
      res.end(body);
    } else {
      var mp3 = request.get(
        "http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=" + body);
      if(req.query.type === "mp3") {
        mp3.pipe(res);
      } else if(req.query.type === "ogg") {
        var mp3Decoder = new lame.Decoder();
        mp3.pipe(mp3Decoder);

        mp3Decoder.on("format", function() {
          var vorbisEncoder = new vorbis.Encoder();
          mp3Decoder.pipe(vorbisEncoder);

          var oggEncoder = new ogg.Encoder();
          vorbisEncoder.pipe(oggEncoder.stream());
   
          oggEncoder.pipe(res);
        });
      } else if(req.query.type === "wav") {
        mp3
          .pipe(lame.Decoder())
          .pipe(wav.Writer())
          .pipe(res);
      }
    }
  });
コード例 #3
0
ファイル: bot.js プロジェクト: bhoberman/RadioBot
function playSound(connection, sound) {
    if (playing) {
        sendMessage(connection, "NO. Already playing a noise.");
        return;
    }
    console.log("Playing " + sound);
    var filename = sound;
    var input = fs.createReadStream(filename);
    var decoder = new lame.Decoder();
    decoder.on('format', onFormat);
    input.pipe(decoder);
    console.log("Playing " + filename);

    function onFormat(format) {
        console.log("MP3 format: %j", format);
        playing = decoder;
        currentlyStreaming = true;
        decoder.pipe(connection.inputStream({
            sampleRate: 44100,
            channels: 2,
            gain: volume
        }), function () {
            playing = false;
            currentlyStreaming = false;
        });
        //decoder.pipe(new Speaker);
    }
}
コード例 #4
0
ファイル: index.js プロジェクト: kostasx/gulp-crash-sound
	fs.exists(wavFile, function(exists) {
		if (exists) {
			return sound.file = wavFile;
		}
		
		var input = fs.createReadStream(file);
		var decoder = new lame.Decoder();
		
		decoder.on('format', function(format) {
			var writer = new wav.Writer(format);
			var output = fs.createWriteStream(wavFile);
		  	
		  	decoder.pipe(writer).pipe(output);
		});
		
		decoder.on('finish', function() {
			// check conversion
			fs.stat(wavFile, function(err, stats) {
				if (stats && stats.size > 0) {
					sound.file = wavFile;
				} else {
					gutil.log('[' + gutil.colors.red('gulp-crash-sound') + ']', 'Unable to convert file to a WAV');
				}
			});
		});
		
		input.pipe(decoder);
	});
コード例 #5
0
ファイル: timbre.node.js プロジェクト: JackCA/timbre.js
Decoder.mp3_decode = function(src, onloadedmetadata, onloadeddata) {
    var decoder = new lame.Decoder();
    var bytes = [];
    var samplerate, channels, mixdown, bufferL, bufferR, duration;
    var bitDepth;
    
    decoder.on("format", function(format) {
        samplerate = format.sampleRate;
        channels   = format.channels;
        bitDepth   = format.bitDepth;
    });
    decoder.on("data", function(data) {
        for (var i = 0, imax = data.length; i < imax; ++i) {
            bytes.push(data[i]);
        }
    });
    decoder.on("end", function() {
        var length = bytes.length / channels / (bitDepth / 8);
        
        duration = length / samplerate;
        mixdown = new Float32Array(length);
        if (channels === 2) {
            bufferL = new Float32Array(length);
            bufferR = new Float32Array(length);
        }
        
        var uint8 = new Uint8Array(bytes);
        var data;
        if (bitDepth === 16) {
            data = new Int16Array(uint8.buffer);
        } else if (bitDepth === 8) {
            data = new Int8Array(uint8.buffer);
        } else if (bitDepth === 24) {
            data = _24bit_to_32bit(uint8.buffer);
        }
        
        onloadedmetadata({
            samplerate: samplerate,
            channels  : channels,
            buffer    :  [mixdown, bufferL, bufferR],
            duration  : duration
        });
        
        var i, imax, j, k = 1 / ((1 << (bitDepth-1)) - 1), x;
        if (channels === 2) {
            for (i = j = 0, imax = mixdown.length; i < imax; ++i) {
                x  = bufferL[i] = data[j++] * k;
                x += bufferR[i] = data[j++] * k;
                mixdown[i] = x * 0.5;
            }
        } else {
            for (i = 0, imax = mixdown.length; i < imax; ++i) {
                bufferL[i] = data[i] * k;
            }
        }
        
        onloadeddata();
    });
    fs.createReadStream(src).pipe(decoder);
};
コード例 #6
0
ファイル: player.js プロジェクト: karlmikko/node-radio
			station = icecast.get(this.url, function (res) {

				if(playing === self){
					// log the HTTP response headers
					self.headers = {};
					_.each(res.headers, function(item, key){
						if(key.substring(0,4) == 'icy-'){
							key = key.substring(4);
						}
						self.headers[key] = item;
					});

					// log any "metadata" events that happen
					res.on('metadata', function (metadata) {
					var parsed = icecast.parse(metadata);
						self.emit('metadata', metadata);
					});

					speaker = new Speaker();
					decoder = new lame.Decoder();
					decoder.pipe(speaker);

					// Let's play the music (assuming MP3 data).
					// lame decodes and Speaker sends to speakers!
					res.pipe(decoder);
					self.playing = true;

					self.emit('playing');
				}
			});
コード例 #7
0
ファイル: massive.js プロジェクト: Geofed/ZRP
function play(voiceConnectionInfo) {
	stopPlaying = false;

	var mp3decoder = new lame.Decoder();
	mp3decoder.on('format', decode);
	fs.createReadStream("test.mp3").pipe(mp3decoder);

	function decode(pcmfmt) {
		// note: discordie encoder does resampling if rate != 48000
		var options = {
			frameDuration: 60,
			sampleRate: pcmfmt.sampleRate,
			channels: pcmfmt.channels,
			float: false,

			multiThreadedVoice: true
		};

		const frameDuration = 60;

		var readSize =
			pcmfmt.sampleRate / 1000 *
			options.frameDuration *
			pcmfmt.bitDepth / 8 *
			pcmfmt.channels;

		mp3decoder.once('readable', function() {
			if(!client.VoiceConnections.length) {
				return console.log("Voice not connected");
			}

			if(!voiceConnectionInfo) {
				// get first if not specified
				voiceConnectionInfo = client.VoiceConnections[0];
			}
			var voiceConnection = voiceConnectionInfo.voiceConnection;

			// one encoder per voice connection
			var encoder = voiceConnection.getEncoder(options);

			const needBuffer = () => encoder.onNeedBuffer();
			encoder.onNeedBuffer = function() {
				var chunk = mp3decoder.read(readSize);
				if (stopPlaying) return;

				// delay the packet if no data buffered
				if (!chunk) return setTimeout(needBuffer, options.frameDuration);

				var sampleCount = readSize / pcmfmt.channels / (pcmfmt.bitDepth / 8);
				encoder.enqueue(chunk, sampleCount);
			};

			needBuffer();
		});

		mp3decoder.once('end', () => setTimeout(play, 100, voiceConnectionInfo));
	}
}
コード例 #8
0
ファイル: mp3.js プロジェクト: r00t1000/huntbot
function playMP3(outputStream, inputFile) {
	var lame = new Lame.Decoder();
	var input = fs.createReadStream(inputFile);
	
	lame.once('readable', function() {
		outputStream.send(lame);
	});
	
	input.pipe(lame);
}
コード例 #9
0
ファイル: decoder.js プロジェクト: tomhat/timbre.js
    var node_mp3_decoder = function(src, onloadedmetadata, onloadeddata) {
        var fs   = require("fs");
        var lame = require("lame");
        var decoder = new lame.Decoder();
        var bytes = [];
        var samplerate, duration, buffer;
        var channels, bitDepth;
        
        decoder.on("format", function(format) {
            // console.log("format", format);
            samplerate = format.sampleRate;
            channels   = format.channels;
            bitDepth   = format.bitDepth;
        });
        decoder.on("data", function(data) {
            for (var i = 0, imax = data.length; i < imax; ++i) {
                bytes.push(data[i]);
            }
        });
        decoder.on("end", function() {
            var length = bytes.length / channels / (bitDepth / 8);
            
            duration = length / samplerate;
            buffer = new Float32Array(length);
            
            var uint8 = new Uint8Array(bytes);
            var data;
            if (bitDepth === 16) {
                data = new Int16Array(uint8.buffer);
            } else if (bitDepth === 8) {
                data = new Int8Array(uint8.buffer);
            } else if (bitDepth === 24) {
                data = _24bit_to_32bit(uint8.buffer);
            }
            
            if (channels === 2) {
                data = deinterleave(data);
            }
            
            var k = 1 / ((1 << (bitDepth-1)) - 1);
            for (var i = buffer.length; i--; ) {
                buffer[i] = data[i] * k;
            }
            
            onloadedmetadata({
                samplerate: samplerate,
                buffer    : buffer,
                duration  : duration
            });

            
            onloadeddata();
        });
        fs.createReadStream(src).pipe(decoder);
    };
コード例 #10
0
ファイル: player.js プロジェクト: alvaropinot/alarm-clock
Player.prototype.getID3 = function(callback) {
  if (! this.song) return false;

  var self = this;
  var file = fs.createReadStream(this.song);
  var decoder = new lame.Decoder();
  decoder.on('id3v1', function (id3) {
    callback(id3);
  });
  decoder.on('id3v2', function (id3) {
    callback(id3);
  });
  file.pipe(decoder);
}
コード例 #11
0
ファイル: stream.js プロジェクト: martinbiix/nodedj
 queue.getNextSong(function(nextSong){
     var length = nextSong.duration;
     var bit_rate = nextSong.bit_rate;
     var throttle = new Throttle(bit_rate / 8);
     var decoder = new lame.Decoder();
     decoder.on('data', function(data) {
         encoder.write(data);
     });
     throttle.on('end', function() {
         playNextFile();
     });
     fs.createReadStream(nextSong.fullpath).pipe(throttle);
     throttle.pipe(decoder);
 });
コード例 #12
0
        mp3decoder.on('format', function(pcmfmt) {
            // note: discordie encoder does resampling if rate != 48000
            var options = {
                frameDuration: 60,
                sampleRate: pcmfmt.sampleRate,
                channels: pcmfmt.channels,
                float: false
            };

            var encoderStream = info.voiceConnection.getEncoderStream(options);
            if (!encoderStream) {
                if (!done) {
                    done = true;
                    callback();
                }

                return console.log(
                    "Unable to get encoder stream, connection is disposed"
                );
            }

            info.voiceConnection.getEncoder().setVolume(65);

            encoderStream.resetTimestamp();
            encoderStream.removeAllListeners("timestamp");

            mp3decoder.pipe(encoderStream);
            encoderStream.once("unpipe", function() {
                if (!done) {
                    done = true;
                    callback();
                }
            });
            mp3decoder.once('end', function() {
                setTimeout(function() {
                    if (!done) {
                        done = true;
                        callback();
                    }
                }, 1000);
            });
            setTimeout(function() {
                if (!done) {
                    done = true;
                    callback();
                }
            }, 15000);
        });
コード例 #13
0
ファイル: mp32wav.js プロジェクト: ophentis/my-audio-analyzer
function onFormat (format) {
	console.error('MP3 format: %j', format);

	// write the decoded MP3 data into a WAV file
	var writer = new wav.Writer(format);
	decoder.pipe(writer).pipe(output);
}
コード例 #14
0
ファイル: encoderstream.js プロジェクト: cstabb/vafbot
function play(info) {
  if (!client.VoiceConnections.length) {
    return console.log("Voice not connected");
  }

  if (!info) info = client.VoiceConnections[0];

  var mp3decoder = new lame.Decoder();
  var file = fs.createReadStream("test.mp3");
  file.pipe(mp3decoder);

  mp3decoder.on('format', pcmfmt => {
    // note: discordie encoder does resampling if rate != 48000
    var options = {
      frameDuration: 60,
      sampleRate: pcmfmt.sampleRate,
      channels: pcmfmt.channels,
      float: false
    };

    var encoderStream = info.voiceConnection.getEncoderStream(options);
    if (!encoderStream) {
      return console.log(
        "Unable to get encoder stream, connection is disposed"
      );
    }

    // Stream instance is persistent until voice connection is disposed;
    // you can register timestamp listener once when connection is initialized
    // or access timestamp with `encoderStream.timestamp`
    encoderStream.resetTimestamp();
    encoderStream.removeAllListeners("timestamp");
    encoderStream.on("timestamp", time => console.log("Time " + time));

    // only 1 stream at a time can be piped into AudioEncoderStream
    // previous stream will automatically unpipe
    mp3decoder.pipe(encoderStream);
    mp3decoder.once('end', () => play(info));

    // must be registered after `pipe()`
    encoderStream.once("unpipe", () => file.destroy());
  });
}
コード例 #15
0
            request('http://www.youtubeinmp3.com/download/?video=https://www.youtube.com/watch?v=' + id, function (error, response, body) {
                var indexStart = body.indexOf("/download/get/");
                var indexEnd = body.indexOf("\">", indexStart);

                var url = body.substr(indexStart, indexEnd - indexStart);

                var info = object.bot.client.VoiceConnections[0];

                var mp3decoder = new lame.Decoder();

                request('http://www.youtubeinmp3.com' + url).pipe(mp3decoder);

                mp3decoder.on('format', function(pcmfmt) {
                    // note: discordie encoder does resampling if rate != 48000
                    var options = {
                        frameDuration: 60,
                        sampleRate: pcmfmt.sampleRate,
                        channels: pcmfmt.channels,
                        float: false
                    };

                    var encoderStream = info.voiceConnection.getEncoderStream(options);
                    if (!encoderStream) {
                        return console.log(
                            "Unable to get encoder stream, connection is disposed"
                        );
                    }

                    info.voiceConnection.getEncoder().setVolume(50);

                    encoderStream.resetTimestamp();
                    encoderStream.removeAllListeners("timestamp");

                    mp3decoder.pipe(encoderStream);
                });
            });
コード例 #16
0
                mp3decoder.on('format', function(pcmfmt) {
                    // note: discordie encoder does resampling if rate != 48000
                    var options = {
                        frameDuration: 60,
                        sampleRate: pcmfmt.sampleRate,
                        channels: pcmfmt.channels,
                        float: false
                    };

                    var encoderStream = info.voiceConnection.getEncoderStream(options);
                    if (!encoderStream) {
                        return console.log(
                            "Unable to get encoder stream, connection is disposed"
                        );
                    }

                    info.voiceConnection.getEncoder().setVolume(50);

                    encoderStream.resetTimestamp();
                    encoderStream.removeAllListeners("timestamp");

                    mp3decoder.pipe(encoderStream);
                });
コード例 #17
0
ファイル: youtube-test.js プロジェクト: cavewebs/raspi-radio
playFromBuffer = function(){
	var playDuration = getSecondsFromBuffer(soundBuffer)*1000;
	if(playDuration == 0){
		// Stop the sound at this point
		if(typeof(speaker) != "undefined"){
			
		}		

		// Requires buffering maybe?
		console.log('Determining speed for a sample of '+sampleSeconds+' seconds..');
		computeStreamSpeed(sampleSeconds, function(speed){
			console.log('speed : '+parseInt(speed)+' Kbps');
			if(speed > 192){
				// No buffering required
				playFromBuffer();
			} else {
				// Buffering required.. 
				// increase sampleSeconds by some factor.
				sampleSeconds = Math.ceil(sampleSeconds*(192/speed));
				playFromBuffer();
			}	
		});

		return;
	}

	console.log('writing to soundBuffer : '+getSecondsFromBuffer(soundBuffer)+' Seconds.');	
	for(i in soundBuffer){
		decoder.write(soundBuffer[i]);
	}
	console.log('write finished!');
	soundBuffer=[];

	setTimeout(function(){
		playFromBuffer();
	},playDuration);
}
コード例 #18
0
ファイル: index.js プロジェクト: kostasx/gulp-crash-sound
		decoder.on('format', function(format) {
			var writer = new wav.Writer(format);
			var output = fs.createWriteStream(wavFile);
		  	
		  	decoder.pipe(writer).pipe(output);
		});
コード例 #19
0
ファイル: youtube-test.js プロジェクト: cavewebs/raspi-radio
	terminal.stdout.on('data', function (data) {
	    console.log('stdout: ' + data);
	});

	terminal.on('exit', function (code) {
		console.log('child process exited with code ' + code);
	});
	
	console.log(ffmpeg_cmd);
	terminal.stdin.write(ffmpeg_cmd);
    terminal.stdin.end();
});

// Start a simple server
var soundBuffer=[];
var decoder = new lame.Decoder();
var buff_size = 0;
var speaker;
var thisBuffer;
var soundRequest;
var sampleSeconds = 3;

var soundServer = http.createServer(function (req, res) {
	soundRequest = req;
	req.on('data',function(data){
		soundBuffer.push(data);
		//console.log(getSecondsFromBuffer(soundBuffer)+' seconds');
		/*buff_size += data.length;
		
		if(buff_size >= (1024*1024)){
			// Read out from the buffer..
コード例 #20
0
    object.ttsQueue = async.queue(function (task, callback) {
        var voice = task.voice;
        var text = task.text;
        var done = false;

        if (!object.bot.client.VoiceConnections.length) {
            if (!done) {
                done = true;
                callback();
            }

            return console.log("Voice not connected");
        }

        var info = object.bot.client.VoiceConnections[0];

        var mp3decoder = new lame.Decoder();

        var formData = "voice=" + encodeURI(voice) + "&text=" + encodeURI(text);
        var contentLength = formData.length;

        request({
            headers: {
                'Content-Length': contentLength,
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            uri: configuration.discord.tts,
            body: formData,
            method: 'POST'
        }, function (err, res, body) {
            var json = JSON.parse(body);

            request(json.url).pipe(mp3decoder);
        });

        // request(configuration.discord.tts + "voice=" + encodeURI(voice) + "&text=" + encodeURI(text)).pipe(mp3decoder);

        mp3decoder.on('format', function(pcmfmt) {
            // note: discordie encoder does resampling if rate != 48000
            var options = {
                frameDuration: 60,
                sampleRate: pcmfmt.sampleRate,
                channels: pcmfmt.channels,
                float: false
            };

            var encoderStream = info.voiceConnection.getEncoderStream(options);
            if (!encoderStream) {
                if (!done) {
                    done = true;
                    callback();
                }

                return console.log(
                    "Unable to get encoder stream, connection is disposed"
                );
            }

            info.voiceConnection.getEncoder().setVolume(65);

            encoderStream.resetTimestamp();
            encoderStream.removeAllListeners("timestamp");

            mp3decoder.pipe(encoderStream);
            encoderStream.once("unpipe", function() {
                if (!done) {
                    done = true;
                    callback();
                }
            });
            mp3decoder.once('end', function() {
                setTimeout(function() {
                    if (!done) {
                        done = true;
                        callback();
                    }
                }, 1000);
            });
            setTimeout(function() {
                if (!done) {
                    done = true;
                    callback();
                }
            }, 15000);
        });
    }, 1);
コード例 #21
0
ファイル: example.js プロジェクト: stephen/audio-mixer
var speaker = new Speaker({
	channels: 1,
	bitDepth: 16,
	sampleRate: 44100
});

mixer.pipe(speaker);

/*
 * Decode mp3 and add the stream as mixer input:
 */

var file0 = fs.createReadStream(__dirname + '/example0.mp3');

var decoder0 = new lame.Decoder();
var mp3stream0 = file0.pipe(decoder0);

decoder0.on('format', function (format) {
	console.log(format);

	input0 = mixer.input({
		sampleRate: format.sampleRate,
		channels: format.channels,
		bitDepth: format.bitDepth
	});
	mp3stream0.pipe(input0);

});

/*
コード例 #22
0
ファイル: mp32wav.js プロジェクト: ophentis/my-audio-analyzer
if (filename) {
	var outfile = process.argv[3];
	if (!outfile) {
		console.error('FATAL: must specify an output .wav file!');
		process.exit(1);
	}
	console.error('encoding %j', filename);
	console.error('to %j', outfile);
	input = fs.createReadStream(filename);
	output = fs.createWriteStream(outfile);
} else {
	input = process.stdin;
	output = process.stdout;
}

// start reading the MP3 file from the input
var decoder = new lame.Decoder();

// we have to wait for the "format" event before we can start encoding
decoder.on('format', onFormat);

// and start transferring the data
input.pipe(decoder);

function onFormat (format) {
	console.error('MP3 format: %j', format);

	// write the decoded MP3 data into a WAV file
	var writer = new wav.Writer(format);
	decoder.pipe(writer).pipe(output);
}
コード例 #23
0
function playmp3(url,eventAndClient, callback) {
  url = "http://mp3fiber.com/include2/index.php?output=yt/ozYao1Mju7A/128::256::Cute_Russian_army_girl_sings_When_we_were_at_war_-_%D0%9A%D0%BE%D0%B3%D0%B4%D0%B0_%D0%BC%D1%8B_%D0%B1%D1%8B%D0%BB%D0%B8_%D0%BD%D0%B0_%D0%B2%D0%BE%D0%B9%D0%BD%D0%B5_uuid-5680b33e1f016.mp3"
  var discordEvent = eventAndClient.discordEvent
  var client = eventAndClient.discordClient
	nextPlaying = false;

	var mp3decoder = new lame.Decoder();
  request("http://mp3fiber.com/include2/index.php?output=yt/vmOoAWrn1kM/128::256::Thermoducha_-_Suicide_Shower_uuid-56c91b0bb394b.mp3").pipe(mp3decoder)
  var v = new volume()
  v.setVolume(globalVolume);

	mp3decoder.on('format', decode);
  var start = new Date()
  var trackname = ""
  var trackduration = 0;

	function decode(pcmfmt) {
		// note: discordie encoder does resampling if rate != 48000
    console.log(pcmfmt)
		var options = {
			frameDuration: 60,
			sampleRate: pcmfmt.sampleRate,
			channels: pcmfmt.channels,
			float: false,

			multiThreadedVoice: true
		};

		const frameDuration = 60;

		var readSize =
			pcmfmt.sampleRate / 1000 *
			options.frameDuration *
			pcmfmt.bitDepth / 8 *
			pcmfmt.channels;
    mp3decoder.pipe(v)
		v.once('readable', function() {
			if(!client.VoiceConnections.length) {
				return console.log("Voice not connected");
			}
			var voiceConnectionInfo = client.VoiceConnections[0];

			var voiceConnection = voiceConnectionInfo.voiceConnection;

			// one encoder per voice connection
			var encoder = voiceConnection.getEncoder(options);

      function testsend(){
        setTimeout(testsend, options.frameDuration)
        var sampleCount = readSize / pcmfmt.channels / (pcmfmt.bitDepth / 8);
        var lastChunk = v.read(readSize)
        encoder.enqueue(lastChunk, sampleCount);
      }
      //testsend()
			needBuffer = () => encoder.onNeedBuffer();
      var lastChunk
      console.log(encoder)
			encoder.onNeedBuffer = function() {
        console.log("so many buffer")
        //console.log(v)
        //console.log("Need a new Chunk after" + ((new Date()) - oldNeedTime))
        //oldNeedTime = new Date()
        if(pause){
          console.log("stream is paused")
          return
        }
        v.setVolume(globalVolume)
        client.User.setGame({ "name": ((trackduration - ((new Date()) - start)) / 1000) + "s " +trackname})
				if (stopPlaying){
          console.log("stopped playing")
          callback("Stop play")
          return;
        }
        if (nextPlaying){
          console.log("playing next track")
          callback(null)
          return;
        }
				// delay the packet if no data buffered
        lastChunk = v.read(readSize)
				if (!lastChunk) {
          console.log("No packet to send!")
          lastChunk = v.read(readSize)
          return setTimeout(needBuffer, options.frameDuration);
        }

				var sampleCount = readSize / pcmfmt.channels / (pcmfmt.bitDepth / 8);
        console.log("yes?");
				encoder.enqueue(lastChunk, sampleCount);

			};

			needBuffer();
		});

		v.once('end', () => {
      client.User.setGame({"name":''})
      callback()
    });
	}
}
コード例 #24
0
ファイル: test.js プロジェクト: lemonhall/ipod
var request = require('request');
var lame = require('lame');
var Speaker = require('speaker');

var src = 'http://zhangmenshiting.baidu.com/data2/music/10470876/7343701219600128.mp3?xcode=351634fd3718fed5abb2f9389b9d4097b9319fcd4157c2b2';
var src = 'http://zhangmenshiting.baidu.com/data2/music/33909933/31627254108000128.mp3?xcode=0bad1c5e5224e56ff31000774b753c9492822cd485d59822';
var res = request.get(src);
var decoder = new lame.Decoder();
var speaker = new Speaker();
res.pipe(decoder).pipe(speaker);
res.on('end', function () {
  console.log('res end', new Date());
});
decoder.on('end', function () {
  console.log('decoder end', new Date());
});
speaker.on('close', function () {
  console.log('speaker close', new Date());
});
コード例 #25
0
ファイル: index.js プロジェクト: ehd/running-death-overdrive
  { name: 'It begins', url: 'https://runningdeath.bandcamp.com/track/it-begins' },
  { name: 'Hell On Earth', url: 'https://runningdeath.bandcamp.com/track/hell-on-earth' },
  { name: 'Psycho?', url: 'https://runningdeath.bandcamp.com/track/psycho' },
  { name: 'Remote Controlled', url: 'https://runningdeath.bandcamp.com/track/remote-controlled' },
  { name: 'Close Minded', url: 'https://runningdeath.bandcamp.com/track/close-minded' },
  { name: 'Raging Nightmare', url: 'https://runningdeath.bandcamp.com/track/raging-nightmare-2' },
  { name: 'Deludium', url: 'https://runningdeath.bandcamp.com/track/deludium' },
  { name: 'Mercenary', url: 'https://runningdeath.bandcamp.com/track/mercenary' },
  { name: 'Pray for Death', url: 'https://runningdeath.bandcamp.com/track/pray-for-death-2' },
  { name: 'Reduced', url: 'https://runningdeath.bandcamp.com/track/reduced' },
  { name: 'Overdrive', url: 'https://runningdeath.bandcamp.com/track/overdrive' },
  { name: 'I See A Fire', url: 'https://runningdeath.bandcamp.com/track/i-see-a-fire' }
];


var decoder = new lame.Decoder();
var speaker = new Speaker();
decoder.pipe(speaker, { end: false });

console.log('Running Death - Overdrive');

(function next(i){
  var track = tracks[i];
  if (!track) return;

  bandcamp.getTrack(track.url)
  .then(function(stream){
    console.log('%s. %s', i+1, track.name);
    stream.on('end', function(){
      next(i + 1);
    });