下载了一堆音频编辑软件,最后在合并的时候都提示要收费,所以只好写代码搞定了
首先用QQ影音确定需要裁减音乐的地方,比如我需要裁掉11:08到11:48,12:51到13:05,那么python编码如下:
from pydub import AudioSegment
song = AudioSegment.from_wav("our.wav")
first = song[:(11*60+6)*1000]
first.export("first.wav", format="wav")
second = song[(11*60+48)*1000:(12*60+51)*1000]
second.export("second.wav", format="wav")
third = song[(13*60+5)*1000:]
third.export("third.wav", format="wav")
ring_lists = AudioSegment.empty()
ring_lists += first
ring_lists += second
ring_lists += third
ring_lists.export("ring_lists.wav", format="wav")
前提是安装pip install pydub
我没有安装ffmpeg,因为去ffmpeg发现文件好大,下载太耗时
如果改mp3就是下面的方式:
from pydub import AudioSegment
song = AudioSegment.from_mp3("our.mp3")
first = song[:(8*60+0)*1000]
first.export("first.wav", format="mp3")
third = song[(8*60+16)*1000:]
third.export("third.wav", format="mp3")
ring_lists = AudioSegment.empty()
ring_lists += first
ring_lists += third
ring_lists.export("ring.mp3", format="mp3")
记得在path中增加设置:C:\ffmpeg\bin
参考文章
1、把多个音频文件合成一个文件,并且中间加10s的静音的间隔
2、pydub简单介绍
网友评论