我正在从windows命令提示符运行python脚本。它调用下面的函数,该函数使用LAME将MP3文件转换为波形文件。
def convert_mp3_to_wav(input_filename, output_filename):
"""
converts the incoming mp3 file to wave file
"""
if not os.path.exists(input_filename):
raise AudioProcessingException, "file %s does not exist" % input_filename
command = ["lame", "--silent", "--decode", input_filename, output_filename]
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = process.communicate()
if process.returncode != 0 or not os.path.exists(output_filename):
raise AudioProcessingException, stdout
return output_filename
不幸的是,LAME总是在某个MP3s上崩溃(并且名副其实)。Windows的“您的程序已崩溃”对话框出现,冻结我的脚本。关闭窗口对话框后,将引发AudioProcessingException。我只想让脚本抛出异常,然后转到下一个MP3,而不是让Windows闭嘴。
有什么办法可以解决这个问题吗?优选地,通过改变脚本而不是用Unix运行它。
我使用的是Windows 7和Python 2.6
https://stackoverflow.com/questions/5069224
复制相似问题