Ejemplo n.º 1
0
var start = function(options) {
    options = options || {};
    var alsa_format = options.alsa_format || 'dat',
        alsa_device = options.alsa_device || 'plughw:1,0',
        alsa_addn_args = options.alsa_addn_args || [],
        sox_format = options.sox_format || 'dat',
        sox_addn_args = options.sox_addn_args || [],
        mp3_channels = options.mp3_channels || 2,
        mp3_bitDepth = options.mp3_bitDepth || 16,
        mp3_sampleRate = options.mp3_sampleRate || 44100;

    if(ps == null) {
        ps = isMacOrWin
        ? spawn('sox', ['-d', '-t', sox_format, '-p'].concat(sox_addn_args))
        : spawn('arecord', ['-D', alsa_device, '-f', alsa_format].concat(alsa_addn_args));

        if(options.mp3output === true) {
            var encoder = new lame.Encoder( {
                channels: mp3_channels,
                bitDepth: mp3_bitDepth,
                sampleRate: mp3_sampleRate
            });

            ps.stdout.pipe(encoder);
            encoder.pipe(audio);
            ps.stderr.pipe(info);

        } else {
            ps.stdout.pipe(audio);
            ps.stderr.pipe(info);

        }
    }
};
Ejemplo n.º 2
0
    var fn = function(err, buffer){
        if (err){
            if (typeof callback == 'function') callback(err, null);
            else throw err;
        }
        
        if (typeof messageHandler == 'function'){
            messageHandler({
                cmd: 'mp3',
                value: buffer
            });
        }
        
        fs.writeFileSync(filename + '.tmp', new Buffer(buffer), 'binary');
        var reader = fs.createReadStream(filename + '.tmp');
        
        // create the Encoder instance
        var encoder = new lame.Encoder({
            // input
            channels: 2,        // 2 channels (left and right)
            bitDepth: 16,       // 16-bit samples
            sampleRate: 49700,  // 49,700 Hz sample rate

            // output
            bitRate: 128,
            outSampleRate: 22050,
            mode: lame.MONO // STEREO (default), JOINTSTEREO, DUALCHANNEL or MONO
        });
        
        var file = fs.createWriteStream(filename);
        reader.pipe(encoder);
        encoder.pipe(file);
        
        var pos = 0;
        reader.on('data', function(chunk){
            pos += chunk.length;
            if (typeof messageHandler == 'function'){
                messageHandler({
                    cmd: 'encode',
                    value: pos / buffer.length * 100
                });
            }
        });
        reader.on('end', function(){
            fs.unlinkSync(filename + '.tmp');
            file.end();
            encoder.end();
            if (typeof callback == 'function') callback(null, buffer);
        });
    };
Ejemplo n.º 3
0
app.post('/export/', function(req, res) {
  var wavPath = req.files.track.path
    , wavFile = fs.createReadStream(wavPath)
    , mp3Path = wavPath + '.mp3'
    , mp3File = fs.createWriteStream(mp3Path)
    , encoder = new lame.Encoder();

  wavFile.pipe(encoder);
  encoder.pipe(mp3File)

  encoder.on('end', function() {
    res.send("/download/" + path.basename(mp3Path));
    fs.unlink(wavPath);
  });
});
Ejemplo n.º 4
0
function start(app) {
    var clients = [];
    var encoder = new lame.Encoder({
        channels: 2, // 2 channels (left and right)
        bitDepth: 16, // 16-bit samples
        sampleRate: 44100   // 44,100 Hz sample rate
    });

    encoder.on('data', function(data) {
        clients.forEach(function(val, idx) {
            val.write(data);
        });
    });

    function playNextFile() {
        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);
        });
    }

    app.get("/stream", function(request, response) {
        var host = request.headers;
        response.writeHead(200, {"Content-Type": "audio/mpeg"});
        console.log("Client " + host['user-agent'] + " connected from: " + host.host);
        clients.push(response);
        request.on('close', function() {
            var index = clients.indexOf(response);
            clients.splice(index, 1);
            console.log("Client " + host['user-agent'] + " disconnected");
        });
    });
    console.log("Stream Server Now Running...");
    playNextFile();
}
Ejemplo n.º 5
0
var start = function(options) {
    options = options || {};

    if(ps == null) {
        ps = spawn('arecord', ['-D', 'plughw:1,0', '-f', 'dat']);

        if(options.mp3 === true) {
            var encoder = new lame.Encoder( {
                channels: 2,
                bitDepth: 16,
                sampleRate: 44100
            });

            ps.stdout.pipe(encoder);
            encoder.pipe(audio);
            ps.stderr.pipe(info);

        } else {
            ps.stdout.pipe(audio);
            ps.stderr.pipe(info);

        }
    }
};
Ejemplo n.º 6
0
Archivo: index.js Proyecto: kumarak/IOT
var start = function(options) {
    if(ps == null) {
        ps = spawn('arecord', ['-D', 'plughw:1,0', '-f', 'dat']);
        
        if(options.mp3output === true) {
            ps.stdout.pipe(encoder);
            encoder.pipe(audio);
            ps.stderr.pipe(info);
            
        } else {
            ps.stdout.pipe(audio);
            ps.stderr.pipe(info);
            
        }
    }
};
Ejemplo n.º 7
0
// Module lame.js

var lame = require('lame');

// create the Encoder instance
var encoder = new lame.Encoder({
  // input
  channels: 2,        // 2 channels (left and right)
  bitDepth: 16,       // 16-bit samples
  sampleRate: 44100,  // 44,100 Hz sample rate

  // output
  bitRate: 128,
  outSampleRate: 22050,
  mode: lame.STEREO // STEREO (default), JOINTSTEREO, DUALCHANNEL or MONO
});

// raw PCM data from stdin gets piped into the encoder
process.stdin.pipe(encoder);

// the generated MP3 file gets piped to stdout
encoder.pipe(process.stdout);
Ejemplo n.º 8
0
 reader.on('end', function(){
     fs.unlinkSync(filename + '.tmp');
     file.end();
     encoder.end();
     if (typeof callback == 'function') callback(null, buffer);
 });
Ejemplo n.º 9
0
var inputStream = fs.createReadStream('drozerix_-_mecanum_overdrive.xm');

// This is how we create the chiptune stream
// Let's not specify any options
var chiptuneDecoder = chiptune({
    channels: 2, // 2 channels (stereo)
    sampleRate: 48000 // 48,000 Hz sample rate
});

// Now we create the encoder. We will generate a mp3 of the chiptune
var lameEncoder = new lame.Encoder({
    // input
    channels: 2,
    bitDepth: 16,
    sampleRate: 48000,

    // output
    bitRate: 128,
    outSampleRate: 48000,
    mode: lame.STEREO
});

// Let's create a file writable stream
// "drozerix_-_mecanum_overdrive.mp3" is the file name
var outputStream = fs.createWriteStream('drozerix_-_mecanum_overdrive.mp3');

// We should be able to pipe the file stream to the chiptune decoder
inputStream.pipe(chiptuneDecoder);
// the chiptune decoder to the lame encoder
chiptuneDecoder.pipe(lameEncoder);
// and finally the lame encoder to the output file