经常批量处理文件,这里有个python的模板,保存一下
这个例子是把目录里面所有子目录的wav文件放大12db并改成-processed.wav
#coding=utf-8 import sys,os ,shutil import struct import glob import time import subprocess def amplify_wav(file_name): command=‘c:\\tools\\sox\\sox.exe {} {} gain 12‘.format(file_name,file_name.replace(‘.wav‘,‘-processed.wav‘)) print(command) os.system(command) def process_file(file_name): if not file_name.endswith(‘.wav‘): return; amplify_wav(file_name) def process_dir(folder): for sub_node in glob.glob ( folder+‘/*‘ ): if os.path.isdir(sub_node): process_dir(sub_node) else: process_file(sub_node) node=sys.argv[1] if os.path.isdir(node): process_dir(node) for pcm_file in glob.glob ( node+‘/*‘ ): process_file(pcm_file) if os.path.isfile(node): with open(node, ‘r‘) as file_to_read: for line in file_to_read.readlines(): process_file(line)
原文:https://www.cnblogs.com/shinedream/p/12248661.html