# Python audio processing libraries

Python audio processing libraries read, write, and transform sound files and sample arrays. Most decode audio into a NumPy array of samples that analysis and resampling code can operate on. These libraries let speech pipelines, music apps, and machine learning models prepare audio for analysis.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [PyAV](#av) | 52.3M | 3.3K | Oct 2026 | BSD-3-Clause |
| [SoundFile](#soundfile) | 35.5M | 874 | Jun 2026 | BSD-3-Clause |
| [pydub](#pydub) | 17.2M | 9.8K | Mar 2021 | MIT |
| [Python-SoXR](#soxr) | 13.9M | 119 | May 2026 | LGPL-2.1-or-later |
| [ffmpeg-python](#ffmpeg-python) | 11.1M | 11.0K | Jul 2019 | Apache-2.0 |
| [librosa](#librosa) | 11.1M | 9.0K | Nov 2026 | ISC |
| [audioread](#audioread) | 7.4M | 540 | Oct 2025 | MIT |
| [TorchAudio](#torchaudio) | 5.8M | 3.0K | Oct 2026 | BSD-2-Clause |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[PyAV](#av), whose count also covers video work, has the most monthly downloads in this comparison, at 52.3M.

## Capabilities

| Library | Audio file encoding | Sample-rate conversion |
| --- | --- | --- |
| [PyAV](#av) | Yes | Yes |
| [SoundFile](#soundfile) | Yes | No |
| [pydub](#pydub) | Yes | Yes |
| [Python-SoXR](#soxr) | No | Yes |
| [ffmpeg-python](#ffmpeg-python) | Yes | Yes |
| [librosa](#librosa) | No | Yes |
| [audioread](#audioread) | No | No |
| [TorchAudio](#torchaudio) | Via plugin | Yes |

## Libraries

### PyAV

[GitHub](https://github.com/PyAV-Org/PyAV) · [PyPI](https://pypi.org/project/av) · [Docs](https://pypi.org/project/av/)

Binds the FFmpeg libraries for Python.

- Downloads / mo: 52.3M
- Stars: 3.3K
- Last release: 19.0.2
- License: BSD-3-Clause
- Capabilities: [From the PyAV docs](https://pypi.org/project/av/)

```sh
pip install av
```

**ManimCommunity/manim** (42.6K stars)

[ManimCommunity/manim](https://github.com/ManimCommunity/manim) 

```python
def convert_audio(input_path: Path, output_path: Path, codec_name: str):
    with (
        av.open(input_path) as input_audio,
        av.open(output_path, "w") as output_audio,
    ):
        input_audio_stream = input_audio.streams.audio[0]
        output_audio_stream = output_audio.add_stream(codec_name)
        for frame in input_audio.decode(input_audio_stream):
            for packet in output_audio_stream.encode(frame):
                output_audio.mux(packet)

        for packet in output_audio_stream.encode():
            output_audio.mux(packet)
```

[manim/scene/scene_file_writer.py](https://github.com/ManimCommunity/manim/blob/c2dfb597ff470f0cdb01ce9074edb426f45000bc/manim/scene/scene_file_writer.py#L62-L74) · [More projects using PyAV →](https://dashboard.exa.ai/playground/search?q=av%20GitHub%20projects)

**Quickstart**

```python
import av
with av.open('input.wav') as container:
    frame = next(container.decode(audio=0))
    samples = frame.to_ndarray()

```

From [container.html](https://pyav.basswood-io.com/docs/stable/api/container.html)

### SoundFile

[GitHub](https://github.com/bastibe/python-soundfile) · [PyPI](https://pypi.org/project/soundfile) · [Docs](https://pypi.org/project/soundfile/)

Reads and writes audio files.

- Downloads / mo: 35.5M
- Stars: 874
- Last release: 0.14.0
- License: BSD-3-Clause
- Runs on: libsndfile
- Capabilities: [From the SoundFile docs](https://pypi.org/project/soundfile/)

**Strengths**

- **Reads and writes sound files.** Use soundfile.read and soundfile.write for supported audio formats.
- **Processes audio in blocks.** Read short overlapping blocks without loading the entire recording.

**Watch out for**

- **Raw audio needs format details.** Specify the sample rate, channel count, and subtype when opening headerless audio.

```sh
pip install soundfile
```

**librosa/librosa** (9.0K stars)

[librosa/librosa](https://github.com/librosa/librosa) 

```python
def __soundfile_load(path, offset, duration, dtype):
    """Load an audio buffer using soundfile."""
    if isinstance(path, sf.SoundFile):
        # If the user passed an existing soundfile object,
        # we can use it directly
        context = path
    else:
        # Otherwise, create the soundfile object
        context = sf.SoundFile(path)

    with context as sf_desc:
        sr_native = sf_desc.samplerate
        if offset != 0:
            if offset > 0:
                # Seek to the start of the target read
                sf_desc.seek(int(offset * sr_native))
            else:
                sf_desc.seek(-int(abs(offset) * sr_native), whence=sf.SEEK_END)

        if duration is not None:
            frame_duration = int(duration * sr_native)
        else:
            frame_duration = -1

        # Load the target number of frames, and transpose to match librosa form
        y = sf_desc.read(frames=frame_duration, dtype=dtype, always_2d=False).T

    return y, sr_native
```

[librosa/core/audio.py](https://github.com/librosa/librosa/blob/76f10b8d2d00870fed47b4698927a4e7e78d1fb4/librosa/core/audio.py#L171-L198) · [More projects using SoundFile →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20soundfile%20for%20mel%20filters%2C%20silence%20trimming%2C%20partial%20audio%20decoding%20and%20timeline%20mixing&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
import soundfile as sf
samples, sample_rate = sf.read('input.wav')

```

From [latest.md](https://python-soundfile.readthedocs.io/en/latest/)

### pydub

[GitHub](https://github.com/jiaaro/pydub) · [PyPI](https://pypi.org/project/pydub) · [Docs](https://pypi.org/project/pydub/)

Represents audio with immutable AudioSegment objects.

- Downloads / mo: 17.2M
- Stars: 9.8K
- Last release: 0.25.1
- License: MIT
- Capabilities: [From the pydub docs](https://pypi.org/project/pydub/)

**Strengths**

- **Slices clips by time.** Select a section of audio using millisecond-based slices.
- **Mixes clips on a timeline.** Overlay clips at a chosen position with background-gain control.

**Watch out for**

- **Compressed formats need ffmpeg.** Install ffmpeg to open or save formats such as MP3.

```sh
pip install pydub
```

**ManimCommunity/manim** (42.6K stars)

[ManimCommunity/manim](https://github.com/ManimCommunity/manim) 

```python
def add_audio_segment(
    self,
    new_segment: AudioSegment,
    time: float | None = None,
    gain_to_background: float | None = None,
):
    """
    This method adds an audio segment from an
    AudioSegment type object and suitable parameters.

    Parameters
    ----------
    new_segment
        The audio segment to add

    time
        the timestamp at which the
        sound should be added.

    gain_to_background
        The gain of the segment from the background.
    """
    if not self.includes_sound:
        self.includes_sound = True
        self.create_audio_segment()
    segment = self.audio_segment
    curr_end = segment.duration_seconds
    if time is None:
        time = curr_end
    if time < 0:
        raise ValueError("Adding sound at timestamp < 0")

    new_end = time + new_segment.duration_seconds
    diff = new_end - curr_end
    if diff > 0:
        segment = segment.append(
            AudioSegment.silent(int(np.ceil(diff * 1000))),
            crossfade=0,
        )
    self.audio_segment = segment.overlay(
        new_segment,
        position=int(1000 * time),
        gain_during_overlay=gain_to_background,
    )
```

[manim/scene/scene_file_writer.py](https://github.com/ManimCommunity/manim/blob/c2dfb597ff470f0cdb01ce9074edb426f45000bc/manim/scene/scene_file_writer.py#L297-L340) · [More projects using pydub →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20pydub%20for%20mel%20filters%2C%20silence%20trimming%2C%20partial%20audio%20decoding%20and%20timeline%20mixing&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
from pydub import AudioSegment
audio = AudioSegment.from_wav('input.wav')

```

From [README.markdown](https://github.com/jiaaro/pydub)

### Python-SoXR

[GitHub](https://github.com/dofuuz/python-soxr) · [PyPI](https://pypi.org/project/soxr) · [Docs](https://python-soxr.readthedocs.io)

Converts one-dimensional audio between sample rates.

- Downloads / mo: 13.9M
- Stars: 119
- Last release: 1.1.0
- License: LGPL-2.1-or-later
- Capabilities: [From the Python-SoXR docs](https://python-soxr.readthedocs.io)

```sh
pip install soxr
```

**CPJKU/beat_this** (489 stars)

[CPJKU/beat_this](https://github.com/CPJKU/beat_this) 

```python
def signal2spect(self, signal, sr):
    if signal.ndim == 2:
        signal = signal.mean(1)
    elif signal.ndim != 1:
        raise ValueError(f"Expected 1D or 2D signal, got shape {signal.shape}")
    if sr != 22050:
        signal = soxr.resample(signal, in_rate=sr, out_rate=22050)
    signal = torch.tensor(signal, dtype=torch.float32, device=self.device)
    return self.spect(signal)
```

[beat_this/inference.py](https://github.com/CPJKU/beat_this/blob/b95c8ab0c58c2d9fcfd40508ae8dffbc05ac4f5c/beat_this/inference.py#L269-L277) · [More projects using Python-SoXR →](https://dashboard.exa.ai/playground/search?q=soxr%20GitHub%20projects)

**Quickstart**

```python
import numpy as np
import soxr
samples = np.zeros(48000, dtype=np.float32)
converted = soxr.resample(samples, 48000, 16000)

```

From [soxr.html](https://python-soxr.readthedocs.io/en/stable/soxr.html)

### ffmpeg-python

[GitHub](https://github.com/kkroening/ffmpeg-python) · [PyPI](https://pypi.org/project/ffmpeg-python) · [Docs](https://pypi.org/project/ffmpeg-python/)

Builds FFmpeg commands with complex filtering from Python.

- Downloads / mo: 11.1M
- Stars: 11.0K
- Last release: 0.2.0
- License: Apache-2.0
- Capabilities: [From the ffmpeg-python docs](https://pypi.org/project/ffmpeg-python/)

```sh
pip install ffmpeg-python
```

**openai/whisper** (113.0K stars)

[openai/whisper](https://github.com/openai/whisper) 

```python
def load_audio(file: str, sr: int = SAMPLE_RATE):
    """
    Open an audio file and read as mono waveform, resampling as necessary

    Parameters
    ----------
    file: str
        The audio file to open

    sr: int
        The sample rate to resample the audio if necessary

    Returns
    -------
    A NumPy array containing the audio waveform, in float32 dtype.
    """
    try:
        # This launches a subprocess to decode audio while down-mixing and resampling as necessary.
        # Requires the ffmpeg CLI and `ffmpeg-python` package to be installed.
        out, _ = (
            ffmpeg.input(file, threads=0)
            .output("-", format="s16le", acodec="pcm_s16le", ac=1, ar=sr)
            .run(cmd=["ffmpeg", "-nostdin"], capture_stdout=True, capture_stderr=True)
        )
    except ffmpeg.Error as e:
        raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e

    return np.frombuffer(out, np.int16).flatten().astype(np.float32) / 32768.0
```

[whisper/audio.py](https://github.com/openai/whisper/blob/28769fcfe50755a817ab922a7bc83483159600a9/whisper/audio.py#L22-L49) · [More projects using ffmpeg-python →](https://dashboard.exa.ai/playground/search?q=ffmpeg-python%20GitHub%20projects)

**Quickstart**

```python
import ffmpeg
ffmpeg.input('input.wav').output('output.flac').run()

```

From [README.md](https://kkroening.github.io/ffmpeg-python/)

### librosa

[GitHub](https://github.com/librosa/librosa) · [PyPI](https://pypi.org/project/librosa) · [Docs](https://librosa.org/doc)

Provides algorithms for audio and music signal processing.

- Downloads / mo: 11.1M
- Stars: 9.0K
- Last release: 1.0.1
- License: ISC
- Capabilities: [From the librosa docs](https://librosa.org/doc)

**Strengths**

- **Analyzes rhythm and onset strength.** Estimate beat positions and build onset-strength features from audio.
- **Loads audio for analysis.** Decode audio into a floating-point waveform.

**Watch out for**

- **Loading resamples audio by default.** Pass sr=None to keep the file’s original sample rate.
- **Loading mixes channels by default.** Pass mono=False when each input channel must stay separate.

```sh
pip install librosa
```

**coqui-ai/TTS** (46.2K stars)

[coqui-ai/TTS](https://github.com/coqui-ai/TTS) 

```python
def build_mel_basis(
    *,
    sample_rate: int = None,
    fft_size: int = None,
    num_mels: int = None,
    mel_fmax: int = None,
    mel_fmin: int = None,
    **kwargs,
) -> np.ndarray:
    """Build melspectrogram basis.

    Returns:
        np.ndarray: melspectrogram basis.
    """
    if mel_fmax is not None:
        assert mel_fmax <= sample_rate // 2
        assert mel_fmax - mel_fmin > 0
    return librosa.filters.mel(sr=sample_rate, n_fft=fft_size, n_mels=num_mels, fmin=mel_fmin, fmax=mel_fmax)
```

[TTS/utils/audio/numpy_transforms.py](https://github.com/coqui-ai/TTS/blob/dbf1a08a0d4e47fdad6172e433eeb34bc6b13b4e/TTS/utils/audio/numpy_transforms.py#L14-L31) · [More projects using librosa →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20librosa%20for%20mel%20filters%2C%20silence%20trimming%2C%20partial%20audio%20decoding%20and%20timeline%20mixing&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
import librosa
samples, sample_rate = librosa.load('input.wav', sr=None)

```

From [README.md](https://raw.githubusercontent.com/librosa/librosa/1.0.1/librosa/core/audio.py)

### audioread

[GitHub](https://github.com/beetbox/audioread) · [PyPI](https://pypi.org/project/audioread) · [Docs](https://pypi.org/project/audioread/)

Decodes audio across platforms through several backend libraries.

- Downloads / mo: 7.4M
- Stars: 540
- Last release: 3.1.0
- License: MIT
- Capabilities: [From the audioread docs](https://pypi.org/project/audioread/)

```sh
pip install audioread
```

**lhotse-speech/lhotse** (1.2K stars)

[lhotse-speech/lhotse](https://github.com/lhotse-speech/lhotse) 

```python
def audioread_info(path: Pathlike) -> LibsndfileCompatibleAudioInfo:
    """
    Return an audio info data structure that's a compatible subset of ``pysoundfile.info()``
    that we need to create a ``Recording`` manifest.
    """
    import audioread

    # We just read the file and compute the number of samples
    # -- no other method seems fully reliable...
    with audioread.audio_open(
        str(path), backends=_available_audioread_backends()
    ) as input_file:
        shape = audioread_load(input_file)[0].shape
        if len(shape) == 1:
            num_samples = shape[0]
        else:
            num_samples = shape[1]
        return LibsndfileCompatibleAudioInfo(
            channels=input_file.channels,
            frames=num_samples,
            samplerate=int(input_file.samplerate),
            duration=num_samples / input_file.samplerate,
        )
```

[lhotse/audio/backend.py](https://github.com/lhotse-speech/lhotse/blob/3a4f0971f4f05c3d012e36b85097ddb5cb235c33/lhotse/audio/backend.py#L1383-L1405) · [More projects using audioread →](https://dashboard.exa.ai/playground/search?q=audioread%20GitHub%20projects)

**Quickstart**

```python
import audioread
with audioread.audio_open('input.wav') as audio:
    sample_rate = audio.samplerate

```

From [README.md](https://github.com/beetbox/audioread)

### TorchAudio

[GitHub](https://github.com/pytorch/audio) · [PyPI](https://pypi.org/project/torchaudio) · [Docs](https://pypi.org/project/torchaudio/)

Provides audio processing tools for the PyTorch ecosystem.

- Downloads / mo: 5.8M
- Stars: 3.0K
- Last release: 2.11.1
- License: BSD-2-Clause
- Runs on: PyTorch
- Capabilities: [From the TorchAudio docs](https://pypi.org/project/torchaudio/)

**Strengths**

- **Resamples PyTorch waveforms.** Resample waveform tensors through functional or reusable transform APIs.
- **Runs resampling on GPUs.** Use tensor convolution to resample audio on compatible GPU hardware.

**Watch out for**

- **Audio decoding needs TorchCodec.** Install TorchCodec for load and save, or use its classes directly.

```sh
pip install torch==2.11.1 torchaudio==2.11.1
```

**embeddings-benchmark/mteb** (3.5K stars)

[embeddings-benchmark/mteb](https://github.com/embeddings-benchmark/mteb) 

```python
@staticmethod
def resample_audio(
    audio: dict[str, Any],
    *,
    target_sampling_rate: int,
    max_samples: int | None = None,
) -> np.typing.NDArray[np.floating]:
    """Resample an audio input to a target sampling rate and optionally truncate to a maximum number of samples.

    Args:
        audio: A list of dictionaries containing audio data under the "audio" key, where each audio is a dictionary with "array" and "sampling_rate" keys.
        target_sampling_rate: The sampling rate to resample the audio to.
        max_samples: The maximum number of samples to keep for each audio. If None, no truncation is applied.
    """
    import torchaudio

    audio = audio["audio"]
    if audio["sampling_rate"] != target_sampling_rate:
        logger.debug(
            f"Resampling audio from {audio['sampling_rate']} Hz to {target_sampling_rate} Hz."
        )
        resampler = torchaudio.transforms.Resample(
            orig_freq=audio["sampling_rate"],
            new_freq=target_sampling_rate,
        )
        audio_array = resampler(torch.from_numpy(audio["array"]).float()).numpy()
    else:
        audio_array = audio["array"]

    # Convert to mono if needed
    if audio_array.ndim > 1 and audio_array.shape[0] > 1:
        audio_array = np.mean(audio_array, axis=0)

    if max_samples is not None:
        num_samples = audio_array.shape[-1]
        if num_samples > max_samples:
            audio_array = audio_array[..., :max_samples]

    audio_array = cast(
        "np.ndarray[tuple[Any, ...], np.dtype[np.floating[Any]]]",
        audio_array,
    )
    return audio_array
```

[mteb/models/modality_collators.py](https://github.com/embeddings-benchmark/mteb/blob/cd1828837acc188bde2a483e1dca177ba9ed260a/mteb/models/modality_collators.py#L78-L120) · [More projects using TorchAudio →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20torchaudio%20for%20mel%20filters%2C%20silence%20trimming%2C%20partial%20audio%20decoding%20and%20timeline%20mixing&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
import torch
from torchaudio.transforms import Resample
waveform = torch.zeros(1, 16000)
converted = Resample(orig_freq=16000, new_freq=8000)(waveform)

```

From [audio_resampling_tutorial.py](https://docs.pytorch.org/audio/stable/generated/torchaudio.transforms.Resample.html)

## FAQ

### Which Python audio processing library should I use?

[SoundFile](#soundfile) suits reading and writing audio files as NumPy arrays. [librosa](#librosa) suits music and audio analysis. [pydub](#pydub) suits slicing, joining, and converting audio clips.

### What is librosa?

[librosa](#librosa) provides algorithms for audio and music signal processing, such as spectrograms, beat tracking, and pitch features.

### What is pydub?

[pydub](#pydub) represents audio as immutable AudioSegment objects that support slicing, concatenation, and format conversion. It uses FFmpeg to read formats other than WAV.

### What is torchaudio?

[TorchAudio](#torchaudio) provides audio loading, transforms, and models for PyTorch. Its transforms run on tensors inside training pipelines.

### How do I use FFmpeg from Python?

[ffmpeg-python](#ffmpeg-python) builds FFmpeg command lines with filter graphs from Python. [PyAV](#av) binds the FFmpeg libraries directly for frame-level access.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python audio processing libraries librosa soundfile pydub torchaudio resampling features editing code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
