用python截取mp3

时间:2024-03-06 07:15:30

首先:pip install pydub

然后:新建cutmp3.py

from pydub import AudioSegment
sourceName = \'music01\'
# 加载mp3文件
input_music = AudioSegment.from_mp3(sourceName + \'.mp3\')
sound_time = input_music.duration_seconds
# 截取音频最后3000毫秒前的内容
output_music = input_music[:sound_time - 3000]
# 保存音频 前面为保存的路径,后面为保存的格式
output_music.export(sourceName + \'_.mp3\', format=\'mp3\')