DEV Community

Free Python Code
Free Python Code

Posted on • Edited on

how to add keyboard sound effects to your videos easily with Python and MoviePy


how to add keyboard sound effects to your videos easily with Python and MoviePy.

In this video, I'll show you how to add keyboard sound effects to your videos using Python and MoviePy. This is a great way to add some extra flair and excitement to your videos, and it's also a lot of fun.


import moviepy.editor as mp

def add_keyboard_sound(video_path, sound_path):
    video = mp.VideoFileClip(video_path)
    sound = mp.AudioFileClip(sound_path)
    audio_list = []

    if video.duration > sound.duration:

        vd = video.duration
        ad = 0
        while ad < vd:
            ad += sound.duration
            audio_list.append(sound)

    # write audio file
    final_audio = mp.concatenate_audioclips(audio_list)
    final_audio.write_audiofile('audio.mp3')

    ## add this audio to the video
    video.audio = mp.AudioFileClip('audio.mp3')
    video.write_videofile('out.mp4')



add_keyboard_sound('test.mp4', 'keyboard-typing.mp3')

Enter fullscreen mode Exit fullscreen mode

Top comments (0)