Skip to main content

Monolithic python wrapper for libsamplerate based on pybind11 and NumPy

Project description Documentation Status

This is a wrapper around Erik de Castro Lopo’s libsamplerate (aka Secret Rabbit Code) for high-quality sample rate conversion.

It implements all three APIs available in libsamplerate:

  • Simple API: for resampling a large chunk of data with a single library call

  • Full API: for obtaining the resampled signal from successive chunks of data

  • Callback API: like Full API, but input samples are provided by a callback function

The libsamplerate library is statically built together with the python bindings using pybind11.


$ pip install samplerate

Binary wheels of libsamplerate for macOS and Windows (64 bit) are available. For other systems, a C++ 14 or above compiler is required to build the package.


import numpy as np
import samplerate

# Synthesize data
fs = 1000.
t = np.arange(fs * 2) / fs
input_data = np.sin(2 * np.pi * 5 * t)

# Simple API
ratio = 1.5
converter = 'sinc_best'  # or 'sinc_fastest', ...
output_data_simple = samplerate.resample(input_data, ratio, converter)

# Full API
resampler = samplerate.Resampler(converter, channels=1)
output_data_full = resampler.process(input_data, ratio, end_of_input=True)

# The result is the same for both APIs.
assert np.allclose(output_data_simple, output_data_full)

# See `samplerate.CallbackResampler` for the Callback API, or
# `examples/` for an example.

See samplerate.resample, samplerate.Resampler, and samplerate.CallbackResampler in the API documentation for details.

See also

  • scikits.samplerate implements only the Simple API and uses Cython for extern calls. The resample function of scikits.samplerate and this package share the same function signature for compatiblity.

  • resampy: sample rate conversion in Python + Cython.


This project is licensed under the MIT license.

As of version 0.1.9, libsamplerate is licensed under the 2-clause BSD license.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

samplerate-0.2.1.tar.gz (21.5 kB view hashes)

Uploaded Source

Built Distributions

samplerate-0.2.1-cp312-cp312-win_amd64.whl (1.4 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

samplerate-0.2.1-cp312-cp312-macosx_12_0_universal2.whl (2.9 MB view hashes)

Uploaded CPython 3.12 macOS 12.0+ universal2 (ARM64, x86-64)

samplerate-0.2.1-cp311-cp311-win_amd64.whl (1.4 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

samplerate-0.2.1-cp311-cp311-macosx_12_0_universal2.whl (2.9 MB view hashes)

Uploaded CPython 3.11 macOS 12.0+ universal2 (ARM64, x86-64)

samplerate-0.2.1-cp310-cp310-win_amd64.whl (1.4 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

samplerate-0.2.1-cp310-cp310-macosx_12_0_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.10 macOS 12.0+ x86-64

samplerate-0.2.1-cp39-cp39-win_amd64.whl (1.4 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

samplerate-0.2.1-cp39-cp39-macosx_12_0_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.9 macOS 12.0+ x86-64

samplerate-0.2.1-cp38-cp38-win_amd64.whl (1.4 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

samplerate-0.2.1-cp38-cp38-macosx_12_0_x86_64.whl (1.4 MB view hashes)

Uploaded CPython 3.8 macOS 12.0+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page