Created
October 24, 2012 17:42
-
-
Save TooTallNate/3947591 to your computer and use it in GitHub Desktop.
node.js command line MP3 player in 9 lines of code!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var lame = require('lame'); | |
var Speaker = require('speaker'); | |
fs.createReadStream(process.argv[2]) | |
.pipe(new lame.Decoder()) | |
.on('format', function (format) { | |
this.pipe(new Speaker(format)); | |
}); |
Is there a correct way to stop playing the stream?
I'm wondering this too notcoffeetable ever figure it out?
That's a lame 9 lines of code.
To get this to work I needed to first run:
sudo apt-get install libasound2-dev
npm install --save speaker lame
Just to make that explicit...
Thanks I use yarn and don't need to install any other packages other than lame and speaker. Very neat code by the way.
is there a way to accommodate an URL stream in this snippet?
@eslin You can use https://github.com/jimlawless/cmdmp3 and child_process play short mp3 voice
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Im writing an application that is supposed to build sentences out of short mp3's with words.
the complete sound is not played when playing these short (0.55s) mp3 files.
I can't really figure out why.
when playing the sounds in mplayer the complete samples are played.