-
-
Save creationix/490990 to your computer and use it in GitHub Desktop.
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
//usage: $ node wav2mp3.js file1.wav file2.wav | |
// converts to .mp3 format and deletes original .wav file | |
var fs = require('fs'); | |
var sys = require('sys'); | |
var Step = require('step'); | |
var spawn = require('child_process').spawn; | |
var exec = require('child_process').exec; | |
function convert(file, callback){ | |
if (file.slice(-4) === ".mp3") { | |
callback(new Error('file ' + file + ' already converted ')); | |
return; | |
} | |
Step( | |
function checkFile() { | |
fs.stat(file, this); | |
}, | |
function convertFile(err) { | |
if (err) { callback(err); return; } | |
var conversion = exec('soundconverter -b -m ' + | |
'audio/mpeg -s .mp3 ' + file, this); | |
}, | |
function deleteOriginal(err) { | |
if (err) { callback(err); return; } | |
exec('rm -f ' + file, this); | |
}, | |
callback | |
); | |
}; | |
Step( | |
function () { | |
var group = this.group(); | |
process.argv.splice(2).forEach(function (file) { | |
convert(file, group()); | |
}); | |
}, | |
function (err, results) { | |
if (err) throw err; | |
sys.puts(results.length + " successfully converted."); | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment