{"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":"python","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,"search_vec":"'0.2.4':60 'activ':64 'also':20 'api':43,48,50,53 'array':38 'audio':4,34,70 'avail':44 'callback':52 'castro':16 'code':25 'convers':7,32 'current':57 'data':35 'de':15 'develop':65 'erik':14 'full':49 'high':2,28 'high-qual':1,27 'implement':40 'known':21 'librari':55 'libsampler':19,46 'lopo':17 'maintain':62 'numpi':37,73 'process':75 'provid':26 'python':11 'qualiti':3,29 'rabbit':24 'rate':6,31 'regular':68 'releas':69 'resampl':71 'sampl':5,30 'sampler':8 'secret':23 'signal':74 'simpl':47 'sound':72 'status':66 'three':42 'version':59 'wrapper':12","created_at":"2026-04-15T18:46:25.967741+00:00","updated_at":"2026-04-16T21:20:53.579426+00:00","problems":[{"fix":"Install the library using pip: `pip install samplerate`","cause":"The 'samplerate' library has not been installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'samplerate'"},{"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).","cause":"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.","error":"fatal error: samplerate.h: No such file or directory"},{"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)`).","cause":"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).","error":"ValueError: input data must be a numpy array of type float32 or float64"},{"fix":"Provide a positive floating-point number for `samplerate_ratio` representing the ratio of the output sample rate to the input sample rate.","cause":"The `samplerate_ratio` provided to `samplerate.convert` or `samplerate.resample` was zero or negative, which is an invalid value.","error":"ValueError: ratio must be positive"},{"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'`.","cause":"The `converter_type` string provided to `samplerate.convert` (e.g., 'INVALID_TYPE') does not match any of the supported converter algorithms.","error":"ValueError: Unknown converter type 'INVALID_TYPE'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.2.4","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/samplerate/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}