from pydub import AudioSegment
"""
http://builds.libav.org/windows/nightly-lgpl/ 下載libav
解壓 添加環境變量 ..../usr/bin
"""
# 音頻剪切
def cut(main_wav_path, start_time, end_time, part_wav_path):
start_time = int(start_time)
end_time = int(end_time)
sound = AudioSegment.from_mp3(main_wav_path)
word = sound[start_time:end_time]
word.export(part_wav_path, format="wav")
# 音頻合併 def merge(will_merge_file_1, will_merge_file_2,out_file_name='output.wav'): input_1 = AudioSegment.from_wav(will_merge_file_1) input_2 = AudioSegment.from_wav(will_merge_file_2) input_1_db = input_1.dBFS input_2_db = input_2.dBFS # input_1_time = len(input_1) # input_2_time = len(input_2) db = input_1_db-input_2_db if db>0: input_1+=abs(db) elif db<0: input_2+=abs(db) out_put = input_1+input_2 out_put.export(out_file_name,format='wav')