按ms分割
from pydub import AudioSegment
file_name = "denoise_0306.wav"
sound = AudioSegment.from_mp3(file_name)
# 单位:ms
sound1 = sound[:1000]
sound2 = sound[1550:1900]
sound3 = sound[2300:2600]
sound4 = sound[3050:3340]
sound5 = sound[3650:3970]
sound6 = sound[4400:4760]
sound7 = sound[5100:5400]
sound8 = sound[6200:6540]
sound9 = sound[7100:]
crop_audio = sound1 + sound2 + sound3 + sound4 + sound5 + sound6 + sound7 + sound8 + sound9
save_name = "crop_"+file_name
print(save_name)
crop_audio.export(save_name, format="wav",tags={'artist': 'AppLeU0', 'album': save_name})
按开始时间和结束时间分割
from pydub import AudioSegment
file_name = "denoise_0306.wav"
sound = AudioSegment.from_mp3(file_name)
start_time = "9:19"
stop_time = "9:27"
print("time:",start_time,"~",stop_time)
start_time = (int(start_time.split(':')[0])*60+int(start_time.split(':')[1]))*1000
stop_time = (int(stop_time.split(':')[0])*60+int(stop_time.split(':')[1]))*1000
print("ms:",start_time,"~",stop_time)
crop_audio = sound[start_time:stop_time]
save_name = "Cut_"+file_name
print(save_name)
crop_audio.export(save_name, format="wav",tags={'artist': 'AppLeU0', 'album': save_name})