How do I mix audio files using python?

后端 未结 3 1642
情深已故
情深已故 2021-02-19 18:41

I would like to do basic audio mixing in python.

To give an example: I would like to take two mp3 files and add them together and return one mp3 file. Another example:

3条回答
  •  感动是毒
    2021-02-19 19:19

    You can do this pretty easily using pydub:

    from pydub import AudioSegment
    
    sound1 = AudioSegment.from_mp3("/path/to/file1.mp3")
    sound2 = AudioSegment.from_mp3("/path/to/file1.mp3")
    
    # mix sound2 with sound1, starting at 5000ms into sound1)
    output = sound1.overlay(sound2, position=5000)
    
    # save the result
    output.export("mixed_sounds.mp3", format="mp3")
    

提交回复
热议问题