Images, Audio & Video

pydub

Cuts, splices, and remixes audio files with the same ease as trimming a sentence in a text editor.

Install it: pip install pydub

What does it do?

Pydub lets you treat a sound file almost like a string of text: slice out a section, glue two clips together, fade them in and out, adjust volume, or convert between formats like MP3 and WAV with barely any code. Under the hood it leans on a separate tool called ffmpeg to handle the actual decoding of different audio formats. Picture a sound editor’s core moves, cut, paste, fade, boiled down into plain, readable commands. It was built specifically so audio manipulation feels simple rather than requiring you to understand waveforms and sample rates first.

See it in action

This loads a song, cuts out a ten-second section from it, smooths the start and end with a fade, and saves that snippet as its own audio file.

from pydub import AudioSegment

song = AudioSegment.from_mp3("path/to/song.mp3")
clip = song[10000:20000]
clip = clip.fade_in(1000).fade_out(1000)
clip.export("path/to/clip.mp3", format="mp3")

Why would a non-developer care?

Every podcast that trims out dead air, every app that shortens a voice memo, and every system that stitches spoken clips together is doing something pydub was built to make easy. It matters to anyone who’s ever wished editing sound didn’t require expensive, specialized software.

Real-world examples

Podcast production pipelines, voicemail transcription systems, and automated audiobook assembly tools have used pydub to programmatically chop and reassemble audio. Text-to-speech projects often use it to stitch generated speech clips into a single file. Without a library like this, developers would have to write low-level audio-format parsing themselves, which is notoriously fiddly.

Who uses it

Podcast automation developers, voice assistant builders, and anyone scripting bulk audio conversions or edits.

How it compares to alternatives

Pydub trades raw performance and analytical depth for simplicity compared to librosa, which is built for audio analysis rather than editing, and it’s far easier to pick up than working directly with ffmpeg’s command-line syntax.

Fun fact

Pydub deliberately mimics Python’s own string-slicing syntax for audio, so trimming five seconds off a track looks almost identical to trimming characters out of a sentence.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries