https://github.com/jiaaro/pydub#dependencies
from pydub import AudioSegment
import os
import re
# 循环目录下所有文件
for each in os.listdir('.'):
filename = re.findall(r"(.*?)\.mp3", each) # 取出.mp3后缀的文件名
if filename:
filename[0] += '.mp3'
mp3 = AudioSegment.from_mp3(filename[0]) # 打开mp3文件
mp3[10*1000:].export(filename[0], format="mp3") # 切割前10秒并覆盖保存
print(filename)
You may use libav or ffmpeg.
Mac (using homebrew):
# libav brew install libav --with-libvorbis --with-sdl --with-theora #### OR ##### # ffmpeg brew install ffmpeg --with-libvorbis --with-sdl2 --with-theora
Linux (using aptitude):
# libav apt-get install libav-tools libavcodec-extra #### OR ##### # ffmpeg apt-get install ffmpeg libavcodec-extra
Windows:
- Download and extract libav from Windows binaries provided here.
- Add the libav
/bin
folder to your PATH envvar pip install pydub