Registry / data / samplerate

samplerate

JSON →
library0.2.4pypypi✓ verified 85d ago

Samplerate is a Python wrapper for Erik de Castro Lopo's `libsamplerate` (also known as Secret Rabbit Code), providing high-quality sample rate conversion for audio data in NumPy arrays. It implements all three APIs available in `libsamplerate`: Simple API, Full API, and Callback API. The library is currently at version 0.2.4 and maintains an active development status with regular releases.

pip install samplerate
INSTALL
IMPORT
SIG · SAMPLERATE
S
samplerate
datapythonv0.2.4
Install
3.9s avg
Import
10ms
Disk
89MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.9s · import 0.002s · 87MB
89MB installed
● package 89MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

samplerate
import samplerate

This example demonstrates both the Simple API for single-call resampling and the Full API for chunk-based processing, using a synthesized sine wave. It also includes an assertion to show that both APIs yield the same result for a complete signal.

import numpy as np import samplerate # Synthesize data fs = 1000.0 t = np.arange(fs * 2) / fs input_data = np.sin(2 * np.pi * 5 * t).astype(np.float32) # Simple API ratio = 1.5 converter = 'sinc_best' output_data_simple = samplerate.resample(input_data, ratio, converter) print(f"Original shape: {input_data.shape}, Resampled shape (Simple API): {output_data_simple.shape}") # Full API resampler = samplerate.Resampler(converter, channels=1) output_data_full = resampler.process(input_data, ratio, end_of_input=True) print(f"Resampled shape (Full API): {output_data_full.shape}") assert np.allclose(output_data_simple, output_data_full)
Debug
Known issues
gotchaWhen installing on Linux, the underlying `libsamplerate` C library may need to be installed separately (e.g., `libsamplerate0` on Debian/Ubuntu, `libsamplerate` on Arch Linux). Binary wheels for macOS and Windows include `libsamplerate` statically built.
fix
Ensure `libsamplerate` is installed via your system's package manager on Linux: `sudo apt-get install libsamplerate0` (Debian/Ubuntu) or `sudo pacman -S libsamplerate` (Arch).
affects: All versions
gotchaThe `input_data` must be of `float32` dtype and C-contiguous for optimal performance and correct interaction with the underlying C library.
fix
Convert your input NumPy array to `np.float32` using `array.astype(np.float32)` and ensure it's C-contiguous.
affects: All versions
gotchaThere is an older, distinct package named `scikits.samplerate` which also provides audio resampling. While the `resample` function signature is compatible, `scikits.samplerate` only implements the Simple API and uses Cython, whereas `samplerate` (this package) uses `pybind11` and exposes all three libsamplerate APIs.
fix
Ensure you are installing `samplerate` (the package described here) and not `scikits.samplerate` if you intend to use the Full or Callback APIs or benefit from the `pybind11` implementation.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'samplerate'
The 'samplerate' library has not been installed in the current Python environment.
fix
Install the library using pip: `pip install samplerate`
fatal error: samplerate.h: No such file or directory
The C library `libsamplerate` development headers and libraries are not installed or discoverable on the system, which are required to compile the `samplerate` Python wrapper.
fix
Install the `libsamplerate` development package for your operating system (e.g., `sudo apt-get install libsamplerate0-dev` on Debian/Ubuntu, `brew install libsamplerate` on macOS, `yum install libsamplerate-devel` on Fedora/RHEL).
ValueError: input data must be a numpy array of type float32 or float64
The `input_data` provided to `samplerate.convert` (or similar functions) is either not a NumPy array or has an unsupported data type (e.g., integer array).
fix
Ensure the input data is a NumPy array and convert it to `float32` or `float64` before passing it to `samplerate` functions (e.g., `input_data.astype(numpy.float32)`).
ValueError: ratio must be positive
The `samplerate_ratio` provided to `samplerate.convert` or `samplerate.resample` was zero or negative, which is an invalid value.
fix
Provide a positive floating-point number for `samplerate_ratio` representing the ratio of the output sample rate to the input sample rate.
ValueError: Unknown converter type 'INVALID_TYPE'
The `converter_type` string provided to `samplerate.convert` (e.g., 'INVALID_TYPE') does not match any of the supported converter algorithms.
fix
Use one of the valid converter type strings, which can be listed by `samplerate.available_converters()`. Common valid types include `'sinc_fastest'`, `'sinc_medium'`, `'sinc_best'`, `'zero_order_hold'`, or `'linear'`.
Upgrade
Version history
0.2.4latest on PyPI · released Mar 22, 2026
Audit
Dependencies
numpyrequiredRequired for array manipulation of audio data.
libsamplerate0optionalRequired on Linux systems; binaries for macOS and Windows are included in the wheels.
Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
1
Resources
samplerate — pip install samplerate · libregistry