Dividing audio clips or splitting them using Python and moviepy

Free Python Code - Aug 21 '23 - - Dev Community

Hi πŸ™‚πŸ–

Today, I will show you how to divide audio clips or split them using Python and moviepy.

step 1

install moviepy pip install moviepy

step 2

Choose any audio file to test the code. I will choose my favorite song for this test. πŸ€—


import moviepy.editor as mp

audio_path = 'Dirty Backseat - S.S.S (feat. AZZI).mp3'


def split_audio(audio_path, every = 10):
    audio = mp.AudioFileClip(audio_path)

    for index, i in enumerate(range(0, int(audio.duration) - every, every)):
        out_audio = audio.subclip(i, i + every)
        out_audio.write_audiofile(f"out/audio-{index}.mp3")

split_audio(audio_path)

Enter fullscreen mode Exit fullscreen mode

Result

Image description

Now we're done πŸ€—

Don't forget to like and follow πŸ™‚

Support me on PayPal πŸ€—
https://www.paypal.com/paypalme/amr396

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .