Skip to content

Instantly share code, notes, and snippets.

@nicolamontecchio
Created January 19, 2011 18:28
Show Gist options
  • Save nicolamontecchio/786596 to your computer and use it in GitHub Desktop.
Save nicolamontecchio/786596 to your computer and use it in GitHub Desktop.
convert an mp3 to wav using lame -- useful for converting whole directories
#!/usr/bin/env python
import os
import optparse
def processfile(fi, fo) :
print 'lame --decode --quiet %s %s' % (fi,fo)
if __name__ == '__main__':
# parse options
parser = optparse.OptionParser()
parser.add_option('-d', '--dir', dest='dir', default=False, action='store_true', help='convert whole directories')
(options, args) = parser.parse_args()
if len(args) != 2 :
print 'wrong usage'
exit(1)
if options.dir :
dirin = args[0]
dirout = args[1]
infiles = os.listdir(dirin)
for fi in infiles :
if fi[-4:] == '.mp3' or fi[-4:] == '.MP3' :
print 'echo processing %s' % os.path.join(dirin,fi)
fo = fi[:-4] + '.wav'
processfile(os.path.join(dirin,fi), os.path.join(dirout,fo))
else :
processfile(args[0],args[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment