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 are available for macOS (x86_64, arm64), Linux (x86_64, aarch64), and Windows (x86_64). Building from source on other platforms requires a C++14 or later compiler.
importnumpyasnpimportsamplerate# Synthesize datafs=1000.t=np.arange(fs*2) /fsinput_data=np.sin(2*np.pi*5*t)
# Simple APIratio=1.5converter='sinc_best'# or 'sinc_fastest', ...output_data_simple=samplerate.resample(input_data, ratio, converter)
# Full APIresampler=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.assertnp.allclose(output_data_simple, output_data_full)
# See `samplerate.CallbackResampler` for the Callback API, or# `examples/play_modulation.py` for an example.See samplerate.resample, samplerate.Resampler, and
samplerate.CallbackResampler in the API documentation for details.
- 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.