#一个无聊的程序#用python调用lame把一个目录下的wav全部转成高音质mp3

不解释,直接上代码。


#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      haow
#
# Created:     08/07/2013
# Copyright:   (c) haow 2013
# Licence:     
#-------------------------------------------------------------------------------


import os


def checkwav(filename):
    extension = filename[-3:]
    if extension == 'wav':
        return True
    else:
        return False


def execute(command):
    print command
    os.popen(command)


def assemble(filename,lamepath):
    dquotaion="\""
    space=" "
    slash="\\"
    quality="-h -V 0 --preset insane"
    lamepath = lamepath
    filewav = dquotaion+filename+dquotaion
    filemp3 = dquotaion+filename[:-3]+"mp3"+dquotaion
    command = lamepath+space+quality+space+filewav+space+filemp3
    return command


def main (lamepath,path):
    for root, dirs, files in os.walk( path ):
        for fn in files:
            filename = root +"\\"+fn
            if checkwav(filename):
                command=assemble(filename,lamepath)
                execute(command)


if __name__ == '__main__':
    try:
        main("C:\\Users\\haow\\Desktop\\lame.exe","C:\\New folder")
    except:
        pass


你可能感兴趣的:(Python)