python 音频处理软件_python处理音频文件(mp3)
今天aiping點讀筆的MP3源文件出現聲音大小不一致,而且需要將英文單詞MP3與單詞翻譯MP3文件連接起來,剛開始使用ffmpeg效果很差。萬能的gitgub再次證明了它的萬能,我找到了pydub
1 網址:https://github.com/jiaaro/pydub
2 pydub需要依賴 libav或者ffmpeg
3 在mac環境下安裝依賴:(二選一)
brew install libav --with-libvorbis --with-sdl --with-theora
將所有依賴都安裝上~~
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis--with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools --with-fdk-aac --with-freetype --with-ffplay --with-ffplay --with-freetype --with-frei0r --with-libass --with-libbluray --with-libcaca --with-libquvi --with-libvidstab --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-openssl --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools --with-x265
4 安裝pydub: ?pip install pydub
5 使用pydub:
enPath = "%s%s/%s"%(enDir,file,enfile) #英文文件的路徑
cnPath = "%s%s/%s"%(cnDir,file,enfile.replace("en_w","cn_w"))#中文文件的路徑
targetPath = "%s%s/%s"%(toDir,file,enfile.replace("en_w","all")) #合并文件的路徑
#加載MP3文件
song1 = AudioSegment.from_mp3(enPath)
song2 = AudioSegment.from_mp3(cnPath)
#取得兩個MP3文件的聲音分貝
db1 = song1.dBFS
db2 = song2.dBFS
song1 = song1[300:] #從300ms開始截取英文MP3
#調整兩個MP3的聲音大小,防止出現一個聲音大一個聲音小的情況
dbplus = db1 - db2
if dbplus < 0: # song1的聲音更小
song1+=abs(dbplus)
elif dbplus > 0: #song2的聲音更小
song2+=abs(dbplus)
#拼接兩個音頻文件
song = song1 + song2
#導出音頻文件
song.export(targetPath, format="mp3") #導出為MP3格式
總結
以上是生活随笔為你收集整理的python 音频处理软件_python处理音频文件(mp3)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: matlab角接触球轴承和圆锥滚子轴承轴
- 下一篇: python空气质量分析与预测_pyth