Skip to main content

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.

License

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

Metadata

Release files for pipecat-resampler 0.1.0

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.0
File Size Uploaded Provenance Actions
pipecat_resampler-0.1.0.tar.gz 21.4 kB With provenance Details for pipecat_resampler-0.1.0.tar.gz

Built distributions (wheels)

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

Total release size: 295.1 kB

Release files / pipecat_resampler-0.1.0.tar.gz

Download URL pipecat_resampler-0.1.0.tar.gz
Size 21.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e72c531b7883eaf6c57d0d45020eac928cae897a581a9d98f6c9a13a75817869
BLAKE2b-256 checksum
How to use checksums
f85381366ec71cd83d85919444556141888aa2e8f53d986a8c18234b6e4519b1
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.0-cp311-abi3-win_amd64.whl

Download URL pipecat_resampler-0.1.0-cp311-abi3-win_amd64.whl
Size 25.2 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
e336dc3fa2a8ae1ad94200117a650baec1a50d72aa7968f53d3ffd13341490a5
BLAKE2b-256 checksum
How to use checksums
01e04464c57d40e8f2823fcbd475d885c9e9fc9d682849c211b5f77785bf470e
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.0-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL pipecat_resampler-0.1.0-cp311-abi3-musllinux_1_2_x86_64.whl
Size 53.0 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
4053e306d09ffffac31c1b5925f28f1ac5a6768571948978cf812f2a4cec6531
BLAKE2b-256 checksum
How to use checksums
17f55be8325aacb6af70520d42ab723ac2e85f62651a0b83fb27b1b257280ba6
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.0-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL pipecat_resampler-0.1.0-cp311-abi3-musllinux_1_2_aarch64.whl
Size 45.3 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
a31d298e5944b6b9d5c0d04a79b8ae79145b6005e93eacf0ea19e470a071ebed
BLAKE2b-256 checksum
How to use checksums
8f819e0668c5307345f557ee4e27aa5602cfd62420cb37ee3f5885a431ff46f1
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.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL pipecat_resampler-0.1.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 53.7 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
0ed39fda463f6540ff382885aa89297961a6de099a299045960656d14b7e443a
BLAKE2b-256 checksum
How to use checksums
04583188b72b1429b6b2326adfe969a6bfc23adaeb2ed6eaff1e75582e0a76de
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.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL pipecat_resampler-0.1.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 46.5 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
e4912876147cdc5088560d259251e3bc5ab7a4f007933d01fc50abbc37f9444d
BLAKE2b-256 checksum
How to use checksums
cb57a33a7fff25b8b178173a74e91ffa1d92393fe3383d7fb80309be74e46bac
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.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL pipecat_resampler-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Size 23.5 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
95d6009869b8db02330ec901d5a98a7548e7c018b449374ba58b5a242ceeb70f
BLAKE2b-256 checksum
How to use checksums
aa7a0baa6fcecfb69dde226a5c6b56bf58e4dd09b9eabbc28b645f75018671b1
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.0-cp311-abi3-macosx_10_9_x86_64.whl

Download URL pipecat_resampler-0.1.0-cp311-abi3-macosx_10_9_x86_64.whl
Size 26.5 kB
Tags CPython 3.11 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
872ae09fd9904995ec4310d0325e4bcbf9268a575a04536d8940c93af2a77fd1
BLAKE2b-256 checksum
How to use checksums
2297ea043839afd9c6bd9553421f818884be132c6087de64362fc8325b98ec28
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.0

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.0.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