python语音合成mp3文件_求python将两个MP3音频文件拼接成一个MP3文件的代码
展开全部可以使用pydub2 pydub需要依赖 libav或者ffmpeg3 在mac环境e69da5e887aa3231313335323631343130323136353331333339653636下安装依赖:(二选一)[plain]view plaincopybrewinstalllibav--with-libvorbis--with-sdl--with-theora将所有...
展开全部
可以使用pydub
2 pydub需要依赖 libav或者ffmpeg
3 在mac环境e69da5e887aa3231313335323631343130323136353331333339653636下安装依赖:(二选一)
[plain] view plaincopy
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
song1+=abs(dbplus)
elif dbplus > 0: #song2的声音更小
song2+=abs(dbplus)
#拼接两个音频文件
song = song1 + song2
#导出音频文件
song.export(targetPath, format="mp3") #导出为MP3格式
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)