Combine Multiple Audio with Crossfade Using pydub: A Step Guide – Python Tutorial

By | April 6, 2022

It is very easy to combine multiple audio files to one in python. Here is an example tutorial:

Combine WAV Files to One File Using Python – Python Tutorial

However, in order to get a better effect, we should process the splice of two audio. In this tutorial, we will introduce you how to process with crossfade and combine audios.

We will use python pydub library to implement it.

Combine Multiple Audio with Crossfade

Here is an example code:

from pydub import AudioSegment

audio_1 = AudioSegment.from_wav(r"F:\TKCHX9d6fbf78f22b45c88cf829\1253399_0_0.wav")
audio_2 = AudioSegment.from_wav(r"F:\TKCHX9d6fbf78f22b45c88cf829\1253399_1_0.wav")

# 1.5 second crossfade
audio_3 = audio_1.append(audio_2, crossfade=1500)

audio_3.export("audio_3.wav", format="wav")

In this code, we will use AudioSegment.append() function to join two audio files, meanwhile, we use crossfade parameter to determine how long will be processed.

Here is 1500 = 1.5 second, you also can change it in your python script.

Run this code, we will get an audio_3.wav, its effect is perfect.

Leave a Reply