Python processes audio files (mp3)
Today, the MP3 source file of the aiping point reader has different sound sizes and needs to connect the English word MP3 with the word translation MP3 file. The effect of using ffmpeg is very poor at the beginning. The omnipotent gitgub once again proved its omnipotent. I found pydub.
1 web site: https://github.com/jiaaro/pydub
2 pydub depends on libav or ffmpeg
3. Install dependencies in a mac environment: (either)
Brew install libav -- with-libvorbis -- with-sdl -- with-theora install all dependencies ~~ Brew install ffmpeg -- with-fdk-aac -- with-ffplay -- with-freetype -- with-frei0r -- with-libass -- with-libvo-aacenc -- with-libvorbis -- with-libvpx --- opencore-amr -- with-openjpeg -- with-opus -- with-rtmpdump -- with-schroedinger -- with-speex -- with-theora -- with-tools -- with-fdk-aac --- freetype -- 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 install pydub: pip install pydub
5 Use pydub:
EnPath = "% s/% s" % (enDir, file, enfile) # path of the English file cnPath = "% s/% s" % (cnDir, file, enfile. replace ("en_w", "cn_w") # path of the Chinese file: targetPath = "% s/% s" % (toDir, file, enfile. replace ("en_w", "all") # merge file path # Load MP3 file song1 = AudioSegment. from_mp3 (enPath) song2 = AudioSegment. from_mp3 (cnPath) # obtain the sound of two MP3 files db1 = song1.dBFS db2 = song2.dBFS song1 = song1 [300:] # capture an English MP3 file starting from MS # adjust the sound size of the two MP3 files, dbplus = db1-db2 if dbplus <0: # less song1 song1 + = abs (dbplus) elif dbplus> 0: # song2 sound smaller song2 + = abs (dbplus) # splice two audio files song = song1 + song2 # export the audio file song. export (targetPath, format = "mp3") # export to MP3 format