import moviepy.editor as mp
import os
if __name__ == "__main__":
# 指定文件目录
current_address = r"C:\Users\dumpling\Desktop\音乐\周杰伦"
# 获取指定目录下的所有文件
file_list = os.listdir(current_address)
for file_address in file_list:
# 获取文件名(不包含后缀.flv)
file_name = file_address.split('.')[0]
# 拼接文件的绝对路径(dir+xxx.flv)
file_address = os.path.join(current_address, file_address)
print("需要转换的文件 >>>>> " + file_address)
# 调用moviepy库的方法
clip = mp.AudioFileClip(file_address)
# 拼接转换后的文件路径
file_name = file_name + '.mp3'
out_address = os.path.join(current_address, file_name)
print("转换后的文件 >>>>> " + out_address)
###
clip.write_audiofile(out_address)
标签:__,name,flv,current,mp3,file,address
From: https://www.cnblogs.com/clement-chiu/p/18422073