Skip to main content

pipecat-resampler

PyPI Tests Docs Discord

pipecat-resampler

A small C extension for Python that converts 16-bit PCM audio, mono or with interleaved channels, from one sample rate to another, chunk by chunk. It's made for real-time audio, such as voice pipelines built with Pipecat. Equal chunks in give equal chunks out: 40 ms of audio in always gives 40 ms out, the first chunk included.

from pipecat_resampler import Resampler

resampler = Resampler(24000, 16000)
chunk_16k = resampler.process(chunk_24k)  # bytes in, bytes out
tail = resampler.flush()  # the audio the filter is delaying

stereo = Resampler(48000, 16000, channels=2)
frames_16k = stereo.process(frames_48k)  # interleaved frames in and out

Platforms

The extension uses Python's stable ABI, so one wheel per platform covers Python 3.11 and later.

Platform Wheels
Linux x86-64 and ARM64 manylinux (glibc 2.17 or later) and musllinux (Alpine 3.13 or later)
macOS x86-64 and ARM64
Windows x86-64

Why it exists

A real-time voice pipeline has to resample whenever its parts run at different rates. WebRTC audio arrives at 48 kHz while a speech recognizer might want 16 kHz, or a TTS voice that only comes at 24 kHz has to go out on an 8 kHz phone call. When that happens, the conversion runs chunk by chunk, every 10 to 40 ms, for every stream the process is handling.

We wanted a resampler built for that:

  • Sinc quality. A band-limited polyphase sinc filter, flat to 90% of the band, with about 90 dB of aliasing rejection.
  • Fast. C with SIMD, so one process can carry many streams at once.
  • Small. About 0.1 MB installed, with no runtime dependencies.
  • Steady output. The same input size gives the same output size on every call, so nothing downstream has to absorb bursts of audio or wait for audio that's held back.
  • Low latency. A fixed delay of a few milliseconds.
  • Easy to ship. BSD 2-Clause licensed, like Pipecat, with wheels for Linux (glibc 2.17 or later, and Alpine), macOS and Windows.

Each library we tried covers part of this list, and none covered all of it.

Comparison

Each resampler converted 24 kHz noise to 16 kHz in 40 ms chunks, called from Python, on an Intel i9-10920X. Aliasing is how loud a 10 kHz tone comes out after it folds down to 6 kHz; lower is better.

Resampler Samples per 40 ms chunk (640 expected) Aliasing CPU per chunk Install size
soxr VHQ 0 to 1100 -93 dB 13.5 µs 0.5 MB
soxr QQ 639 to 640 -3 dB 6.5 µs 0.5 MB
samplerate (libsamplerate) sinc_medium 640, first chunk 594 -100 dB 198 µs 1.8 MB
PyAV (FFmpeg) 640, first chunk 624 -88 dB 33.7 µs 127 MB
Speex resampler, quality 7 640 -100 dB 26.9 µs no PyPI binding
pipecat-resampler 640 -98 dB 9.1 µs 0.1 MB

How each one fits this use:

  • soxr reaches its quality cheaply by filtering with FFTs over large blocks. Fed small chunks, that means its output arrives in bursts. Its quick setting, QQ, is steady and the fastest option here; it uses cubic interpolation instead of a long filter, so content above the new rate folds back into the speech. soxr is licensed under the LGPL 2.1, and its Linux wheels need glibc 2.27 or later (2.26 on ARM), with none for Alpine.
  • samplerate (libsamplerate) is steady after its first chunk and very clean. Its sinc converters compute the filter for each output sample, which handles any ratio and costs about 15 times soxr's CPU here.
  • PyAV wraps FFmpeg's resampler, which is steady after its first chunk and fast. It brings FFmpeg along, 127 MB installed, and each call from Python costs about 30 µs whatever the chunk size.
  • Speex has a steady, clean resampler. It has no Python binding on PyPI (the speexdsp package covers its echo canceller), so we measured the system library through ctypes. It uses about twice soxr's CPU here, and more at 44.1 kHz, where it computes the filter on the fly.

Performance

Called from Python, in microseconds per chunk, from the same run as the comparison; lower is better.

At 24 → 16 kHz, by chunk size:

Resampler 10 ms 20 ms 40 ms
pipecat-resampler 2.4 4.7 9.1
soxr VHQ 5.7 8.1 13.5
soxr QQ 3.3 4.6 6.5
samplerate sinc_medium 55.0 103.0 198.1
PyAV 29.0 31.3 33.7
Speex quality 7 9.2 14.9 26.9

At 40 ms chunks, the size Pipecat's output transport sends, by rate pair:

Resampler 24 → 16 kHz 24 → 8 kHz 16 → 8 kHz 8 → 16 kHz 48 → 16 kHz 44.1 → 16 kHz
pipecat-resampler 9.2 8.6 6.1 7.9 17.0 17.0
soxr VHQ 13.8 9.2 6.1 6.9 15.1 18.0
soxr QQ 7.0 4.8 4.6 6.9 7.2 7.1
samplerate sinc_medium 198.8 184.0 127.8 145.1 357.0 388.8
PyAV 33.5 32.8 31.8 31.2 36.0 35.6
Speex quality 7 27.4 29.7 19.6 19.0 55.5 217.3

At 24 → 16 kHz, pipecat-resampler is the fastest of the filtered options at every chunk size, and its lead grows as chunks get smaller, because each call costs less. With 40 ms chunks, soxr VHQ is a little faster on 8 → 16 and 48 → 16 kHz, where its multistage FFT design is very cheap. Even pipecat-resampler's slowest case here, 17 µs per 40 ms chunk, is under 0.05% of one core per stream.

Run uv run python scripts/bench.py to measure on your machine. It times soxr, and also samplerate, PyAV and the Speex library when they're installed.

How it works

It's a polyphase Kaiser-windowed sinc filter, the design WebRTC and Speex use. The filter keeps the lower rate's band flat up to 90% of its Nyquist frequency and attenuates aliasing and images by about 90 dB.

Each call works out how many output samples its input is worth and carries any fraction of a sample into the next call. That's what keeps the output steady, for any pair of rates and any chunk size. Instead of holding output back, the filter delays the audio by a few milliseconds; flush() returns that delayed end, and reset() discards it.

With several channels, the audio is interleaved frames, and each channel is filtered on its own with the same filter. The cost grows with the channel count, so stereo costs twice what mono does.

The inner loop picks the fastest kernel the CPU supports when a resampler is created: AVX2 with FMA or SSE2 on x86-64, NEON on ARM64, and plain C elsewhere. Filter phases with symmetric taps add mirrored samples before multiplying, which halves the multiplications. Set PIPECAT_RESAMPLER_KERNEL to generic, sse2, avx2 or neon to force a kernel.

Development

uv sync
uv run pytest
uv run python scripts/bench.py

Wheels are built and tested with cibuildwheel on every pull request and every push to main.

Add a line under ## [Unreleased] in CHANGELOG.md for every change users will notice. A release renames that section to the new version and date, and its GitHub release notes are taken from it.

License

pipecat-resampler is released under the BSD 2-Clause License.

Metadata

Release files for pipecat-resampler 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pipecat-resampler 0.1.1
File Size Uploaded Provenance Actions
pipecat_resampler-0.1.1.tar.gz 24.0 kB With provenance Details for pipecat_resampler-0.1.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pipecat-resampler 0.1.1
File Actions
pipecat_resampler-0.1.1-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for pipecat_resampler-0.1.1-cp311-abi3-win_amd64.whl
pipecat_resampler-0.1.1-cp311-abi3-musllinux_1_2_x86_64.whl CPython 3.11 abi3 Linux musl 1.2+ x86-64 Details for pipecat_resampler-0.1.1-cp311-abi3-musllinux_1_2_x86_64.whl
pipecat_resampler-0.1.1-cp311-abi3-musllinux_1_2_aarch64.whl CPython 3.11 abi3 Linux musl 1.2+ ARM64 Details for pipecat_resampler-0.1.1-cp311-abi3-musllinux_1_2_aarch64.whl
pipecat_resampler-0.1.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for pipecat_resampler-0.1.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
pipecat_resampler-0.1.1-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for pipecat_resampler-0.1.1-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
pipecat_resampler-0.1.1-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for pipecat_resampler-0.1.1-cp311-abi3-macosx_11_0_arm64.whl
pipecat_resampler-0.1.1-cp311-abi3-macosx_10_9_x86_64.whl CPython 3.11 abi3 macOS 10.9+ x86-64 Details for pipecat_resampler-0.1.1-cp311-abi3-macosx_10_9_x86_64.whl

Total release size: 302.9 kB

Release files / pipecat_resampler-0.1.1.tar.gz

Download URL pipecat_resampler-0.1.1.tar.gz
Size 24.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a8006ae5e44fdae3a8ec09d91fd19effee27bc71a226454b5a3dd14b07d22777
BLAKE2b-256 checksum
How to use checksums
e4448424333dc344b5c38e363ff2020725c0de4942d112648e30a9640e48e36e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / pipecat_resampler-0.1.1-cp311-abi3-win_amd64.whl

Download URL pipecat_resampler-0.1.1-cp311-abi3-win_amd64.whl
Size 25.8 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
790bed1d4c723cd5b8c4ddcd552e52ace7d7507996e9fb13bf2669ad08c7e593
BLAKE2b-256 checksum
How to use checksums
9578762247c32f730c56747e3b71b94f3a05e0d67a9c2f0ee089cbf5656a9b7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / pipecat_resampler-0.1.1-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL pipecat_resampler-0.1.1-cp311-abi3-musllinux_1_2_x86_64.whl
Size 53.8 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
a5ef511bd650814480efe1f743bf273325b8c1b75b9130508b7afd00a822a108
BLAKE2b-256 checksum
How to use checksums
787cbf7f2991808f0c779e6693859c0abb3a5817c76ae2a8a2f239e2d4ee3adb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / pipecat_resampler-0.1.1-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL pipecat_resampler-0.1.1-cp311-abi3-musllinux_1_2_aarch64.whl
Size 46.1 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
7bb04b1b65b341e6e7829e66e1eec7a58df05e43e7d1238de988d783b52f187b
BLAKE2b-256 checksum
How to use checksums
05855f5d9561339e419ff77ddb1fafcafd526d009163aaad122d79d6e62763d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / pipecat_resampler-0.1.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL pipecat_resampler-0.1.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 54.5 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
2ef17183004c78dbbc0e45a80b513f0e3eef131849221b6e16f01360c506c8ba
BLAKE2b-256 checksum
How to use checksums
9aeb3fdd3b3194a805b88d6d6cc130fc87f740aa05178c6d3286de467cca470d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / pipecat_resampler-0.1.1-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL pipecat_resampler-0.1.1-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 47.3 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
b75ffbd7d5ee8d896e9ede4705595f7dcff9128e46685e6d40a1ef045f505690
BLAKE2b-256 checksum
How to use checksums
6a112644abae79a0ae4d91f7a2878cd8e9b5447f08affb98eaef0fc47748eb46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / pipecat_resampler-0.1.1-cp311-abi3-macosx_11_0_arm64.whl

Download URL pipecat_resampler-0.1.1-cp311-abi3-macosx_11_0_arm64.whl
Size 24.2 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f7d5150744210fbd126bd95364bb17d11286db34719b15d15758f4688ab52cac
BLAKE2b-256 checksum
How to use checksums
61d87c2aa43e7469f56c1e626060913ec5fe91077776eb690208e886327bac35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / pipecat_resampler-0.1.1-cp311-abi3-macosx_10_9_x86_64.whl

Download URL pipecat_resampler-0.1.1-cp311-abi3-macosx_10_9_x86_64.whl
Size 27.2 kB
Tags CPython 3.11 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
5ceb819bb1da6f62f9bdba7fb7875b6665666436a9417d8d0101d7c56ce3e88c
BLAKE2b-256 checksum
How to use checksums
b457726a0c7f30c0f4ef7a175b0f0c744bc2c76b187604523ffdfb91bf8408bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Security for pipecat-resampler 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for pipecat_resampler-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page