Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pydub mix 2 sounds with different energy levels

I use Pydub Library. I want to mix 2 sounds with different decibel levels incorporating dB data (different energy level). For example, I have the sound of two species.

sound1 = AudioSegment.from_file("species_a.wav")

sound2 = AudioSegment.from_file("species_b.wav")

combined = sound1.overlay(sound2)

And I want, for example, species "a" speak up than species species "b" in my new sound "combined".

Do this with different energy level (-18 dB, -12 dB, -6dB,- 0dB).

It is possible ?

Thanks !

like image 658
Marion Poupard Avatar asked Oct 21 '25 21:10

Marion Poupard


1 Answers

you can normalize them like (untested code, but it probably works)

def set_to_target_level(sound, target_level):
    difference = target_level - sound.dBFS
    return sound.apply_gain(difference)

sound1_adjusted = set_to_target_level(sound1, -12.0)
sound2_adjusted = set_to_target_level(sound2, -12.0)

combined = sound1_adjusted.overlay(sound2_adjusted)
like image 98
Jiaaro Avatar answered Oct 25 '25 20:10

Jiaaro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!