Python Processing audio files (mp3)

Source: Internet
Author: User

Today aiping Point reading pen MP3 source files appear inconsistent sound size, and need to be English word MP3 and Word translation MP3 file connection, just start using ffmpeg effect is poor. The Almighty Gitgub proved its omnipotence again, and I found Pydub.

1 Website: https://github.com/jiaaro/pydub

2 Pydub need to rely on LIBAV or ffmpeg

4 Installing PYDUB:PIP Install Pydub

5 Using Pydub:

            Enpath = "%s%s/%s"% (endir,file,enfile) #英文文件的路径            cnpath = "%s%s/%s"% (Cndir,file,enfile.replace ("En_w", "Cn_w")) # The path of the Chinese file            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的声音大小 to prevent a sound from appearing large one sound small case            Dbplus = db1 -DB2            if Dbplus < 0: # song1 sounds smaller                song1+=abs (dbplus)            elif dbplus > 0: #song2的声音更小                song2+=abs ( Dbplus)            #拼接两个音频文件            song = song1 + song2            #导出音频文件            song.export (TargetPath, format= "MP3") #导出为MP3格式

  

Python Processing audio files (mp3)

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.