beisu/main.py
2021-11-17 13:43:13 +08:00

41 lines
956 B
Python

# -*- coding:utf-8 -*-
import os
import re
from ffmpeg import audio
root_dir = r'I:\work\SVN\new_shenghua\chengxu\client\res\sound'
def get_files(path):
res = []
r = os.listdir(path) # 列出文件夹下所有的目录与文件
for i in r:
file_path = os.path.join(path, i)
if os.path.isfile(file_path) and file_path.endswith('mp3'):
if re.match(r'.*x[\d\.]+\.mp3$', file_path):
continue
res.append(file_path)
return res
def change_speed(file, x, error_info):
res = audio.a_speed(file, x, re.sub(r'(\.mp3$)', f'_x{x}.mp3', file))
if not res:
error_info.append(f'{file} to {x} error')
def run():
files = get_files(root_dir)
error_info = []
for file in files:
change_speed(file, '1.5', error_info)
change_speed(file, '3', error_info)
print('*'*20)
for i in error_info:
print(i)
if __name__ == "__main__":
run()