Mixing two audio files together with python

前端 未结 6 464
故里飘歌
故里飘歌 2020-12-05 00:41

I have two wav files that I want to mix together to form one wav file. They are both the same samples format etc...

Been searching google endlessly.

I would

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 01:14

    A python solution which requires both numpy and audiolab, but is fast and simple:

    import numpy as np
    from scikits.audiolab import wavread
    
    data1, fs1, enc1 = wavread("file1.wav")
    data2, fs2, enc2 = wavread("file2.wav")
    
    assert fs1 == fs2
    assert enc1 == enc2
    result = 0.5 * data1 + 0.5 * data2
    

    If sampling rate (fs*) or encoding (enc*) are different, you may need some audio processing (the assert are strictly speaking too strong, as wavread can handle some cases transparantly).

提交回复
热议问题