How do I mix audio files using python?

后端 未结 3 1669
情深已故
情深已故 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")
    
    0 讨论(0)
  • 2021-02-19 19:23

    You could check out some of the code in the python audiotools project. It is a collection of command-line utilities which make use of a common python package. There is a utility included with audiotools (trackcat) which can con*cat*enate two or more audio tracks; another (tracksplit) can split an audio track (using a .cue file). These, as well as the numerous other included utilities, can work with audio files of various encodings, including mp3.

    0 讨论(0)
  • 2021-02-19 19:44

    The way I've done this in the past is just use subprocess. and call sox.

    E.g. subprocess.call(["sox", "in.1.mp3", "in.2.mp3", "out.mp3"])

    0 讨论(0)
提交回复
热议问题