Python processes audio files (mp3)

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.