Skip to content

Instantly share code, notes, and snippets.

@revolunet
Created September 3, 2014 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revolunet/368031b56dfed0237a10 to your computer and use it in GitHub Desktop.
Save revolunet/368031b56dfed0237a10 to your computer and use it in GitHub Desktop.
mp3 to ogg
/* mp3 to ogg
this gives :
events.js:72
throw er; // Unhandled 'error' event
^
Error: only signed `32-bit` float samples are supported, got "16"
*/
var opts = { channels: 2, bitDepth: 32, float: true };
var inStream = fs.createReadStream(process.argv[2]);
var outStream = fs.createWriteStream(new Date().getTime() + '.ogg');
var mp3Decoder = new lame.Decoder();
var mp3Encoder = new lame.Encoder(opts);
var oggEncoder = new ogg.Encoder();
var vorbisEncoder = new vorbis.Encoder(opts);
vorbisEncoder.pipe(oggEncoder);
// re-encode incoming mp3 to 32bits
var mp3_32 = inStream
.pipe(mp3Decoder)
.pipe(mp3Encoder)
.pipe(mp3Decoder);
// convert to vorbis and save
mp3_32.pipe(vorbisEncoder)
.pipe(oggEncoder)
.pipe(outStream);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment