# Python Pydub Module

Pydub lets you do stuff to audio in a way that isn't stupid. It provides a simple and high-level interface for audio manipulation.

## Installation

Pydub requires `ffmpeg` or `libav` to be installed on your system.

```bash
pip install pydub
```

## Loading Audio

```python
from pydub import AudioSegment

song = AudioSegment.from_mp3("song.mp3")
# song = AudioSegment.from_wav("song.wav")
# song = AudioSegment.from_file("song.m4a", format="m4a")
```

## Slicing and Concatenation

AudioSegments are immutable and support slicing (in milliseconds) and addition.

```python
# First 10 seconds
first_10_seconds = song[:10000]

# Last 5 seconds
last_5_seconds = song[-5000:]

# Concatenate
beginning = first_10_seconds + last_5_seconds
```

## Effects

```python
# Boost volume by 6dB
louder_song = song + 6

# Reduce volume by 3dB
quieter_song = song - 3

# Fade in/out
awesome = song.fade_in(2000).fade_out(3000)

# Reverse
backwards = song.reverse()
```

## Exporting

```python
awesome.export("mashup.mp3", format="mp3")
```

[[programming/python/python]]