Skip to content

Instantly share code, notes, and snippets.

@mpppk
Last active March 18, 2017 04:57
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 mpppk/b0749ee57aafe885e81fe152abbbbc29 to your computer and use it in GitHub Desktop.
Save mpppk/b0749ee57aafe885e81fe152abbbbc29 to your computer and use it in GitHub Desktop.
wav2mp3
// execute 'brew install lame' before use this script
const fs = require('fs'),
path = require('path'),
execSync = require('child_process').execSync,
srcDir = process.argv[2] || '.',
dstDir = process.argv[3] || 'mp3';
try{ fs.mkdirSync(dstDir); }catch(e){}
fs.readdir(srcDir, (err, files) => {
if (err) throw err;
files
.filter(f => fs.statSync(f).isFile() && /.*\.wav$/.test(f))
.map(f => `lame --preset extreme '${f}' '${dstDir}/${path.basename(f, '.wav')}.mp3'`)
.forEach(cmd => { console.log(cmd); execSync(cmd);});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment