{"id":6867,"library":"samplerate","title":"High-quality Audio Sample Rate Conversion","description":"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.","status":"active","version":"0.2.4","language":"en","source_language":"en","source_url":"https://github.com/tuxu/python-samplerate","tags":["audio","resampling","sound","numpy","signal processing"],"install":[{"cmd":"pip install samplerate","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Required for array manipulation of audio data.","package":"numpy"},{"reason":"Required on Linux systems; binaries for macOS and Windows are included in the wheels.","package":"libsamplerate0","optional":true}],"imports":[{"symbol":"samplerate","correct":"import samplerate"}],"quickstart":{"code":"import numpy as np\nimport samplerate\n\n# Synthesize data\nfs = 1000.0\nt = np.arange(fs * 2) / fs\ninput_data = np.sin(2 * np.pi * 5 * t).astype(np.float32)\n\n# Simple API\nratio = 1.5\nconverter = 'sinc_best'\noutput_data_simple = samplerate.resample(input_data, ratio, converter)\n\nprint(f\"Original shape: {input_data.shape}, Resampled shape (Simple API): {output_data_simple.shape}\")\n\n# Full API\nresampler = samplerate.Resampler(converter, channels=1)\noutput_data_full = resampler.process(input_data, ratio, end_of_input=True)\n\nprint(f\"Resampled shape (Full API): {output_data_full.shape}\")\n\nassert np.allclose(output_data_simple, output_data_full)","lang":"python","description":"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."},"warnings":[{"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).","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Convert your input NumPy array to `np.float32` using `array.astype(np.float32)` and ensure it's C-contiguous.","message":"The `input_data` must be of `float32` dtype and C-contiguous for optimal performance and correct interaction with the underlying C library.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"There 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}