PYTHON-SAMPLERATE(1)

πŸ“¦ version 0.2.4, in ubuntu stonking

✨ NAME ✨

okay bestie, welcome to python-samplerate β€” like, the manual page for it, PYTHON-SAMPLERATE(1), and yes it's exactly as iconic as it sounds πŸ’…

This is python-samplerate β€” python-samplerate Documentation πŸŽ€

Badge corner, because of course we have badges: python-samplerate β€” python-samplerate Documentation, with the pypi badges pointing at https://pypi.python.org/pypi/samplerate and one of them shout-out-ing Documentation Status, plus a docs badge at http://python-samplerate.readthedocs.io/en/latest/?badge=latest ✨

So what even is this? It's a wrapper around Erik de Castro Lopo's libsamplerate (http://www.mega-nerd.com/libsamplerate/) β€” aka Secret Rabbit Code 🐰 β€” and it does high-quality sample rate conversion. No cap.

It implements all three of the APIs that live at http://www.mega-nerd.com/libsamplerate/api.html inside libsamplerate (http://www.mega-nerd.com/libsamplerate/):

  • Simple API β€” for resampling a big ol' chunk of data with a single library call. one and done, we love her 🫢
  • Full API β€” for getting the resampled signal out of successive chunks of data. it's giving "streaming, but make it chic"
  • Callback API β€” same energy as Full API, except the input samples get handed to you by a callback function πŸŽ€

And the tea: the libsamplerate (http://www.mega-nerd.com/libsamplerate/) library is statically built together with the python bindings using pybind11 (https://github.com/pybind/pybind11/) πŸ”₯


🌸 INSTALLATION 🌸

literally one line, bestie:

$ pip install samplerate

Binary wheels of libsamplerate (http://www.mega-nerd.com/libsamplerate/) are available for:

  • macOS (x86_64, arm64)
  • Linux (x86_64, aarch64)
  • Windows (x86_64)

Building from source on other platforms requires a C++14 or later compiler. yeah. a whole compiler. it's giving "bring your own toolchain" 😭


πŸ’– USAGE πŸ’–

here's the vibe, copy-paste ready:

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/play_modulation.py` for an example.

so like, ratio = 1.5, converter is 'sinc_best' (or 'sinc_fastest', or one of the others β€” the ... is doing so much heavy lifting there 🫠), and both APIs genuinely land on the same answer thanks to that assert np.allclose(...). main character energy from a test assertion, honestly.

For the full rundown, go look at samplerate.resample, samplerate.Resampler, and samplerate.CallbackResampler in the API documentation. details live there πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹

  • scikits.samplerate (https://pypi.python.org/pypi/scikits.samplerate) β€” this one only implements the Simple API and uses Cython (http://cython.org/) for extern calls. fun fact: the resample function of scikits.samplerate and this package share the same function signature for compatiblity (yes, that spelling, we keep it πŸ’…). so if you're migrating, the signature is a handshake, not a goodbye 🫢
  • resampy (https://github.com/bmcfee/resampy) β€” sample rate conversion in Python + Cython. another icon in the resampling cinematic universe ⭐

πŸ‘‘ LICENSE πŸ‘‘

This project is licensed under the MIT license (https://opensource.org/licenses/MIT) πŸŽ€

And plot twist for the history girlies: as of version 0.1.9, libsamplerate (http://www.mega-nerd.com/libsamplerate/) is licensed under the 2-clause BSD license (https://opensource.org/licenses/BSD-2-Clause) ✨

ngl bestie, license lore is real lore. version 0.1.9 is the divider line. remember it.

✨ API DOCUMENTATION ✨


🌸 samplerate module documentation

samplerate β€” Python bindings for libsamplerate based on CFFI and NumPy. that's the whole vibe bestie, that's what we're working with πŸ’–

πŸ’« Simple API

  • samplerate.resample() β€” See samplerate.converters.resample().

πŸ’« Full API

  • class samplerate.Resampler β€” See samplerate.converters.Resampler().

πŸ’« Callback API

  • class samplerate.CallbackResampler β€” See samplerate.converters.CallbackResampler().

πŸ’« Exceptions

  • class samplerate.ResamplingError β€” See samplerate.converters.CallbackResampler().

πŸ¦‹ samplerate.converters -- Sample rate converters

πŸ‘‘ Converter types

class samplerate.converters.ConverterType

Enum of samplerate converter types. like, a little menu of converter options, slay.

Pass any of the members, or their string or value representation, as converter_type in the resamplers. so flexible, we love options πŸ’…

Members:

  • sinc_best
  • sinc_medium
  • sinc_fastest
  • zero_order_hold
  • linear

and here's the receipts, literally:

  • linear = <ConverterType.linear: 4>
  • ConverterType.name -> str
  • sinc_best = <ConverterType.sinc_best: 0>
  • sinc_fastest = <ConverterType.sinc_fastest: 2>
  • sinc_medium = <ConverterType.sinc_medium: 1>
  • property value
  • zero_order_hold = <ConverterType.zero_order_hold: 3>

🌈 Sample rate converters

Simple

samplerate.converters.resample(input: Annotated[numpy.typing.ArrayLike, numpy.float32], ratio: SupportsFloat, converter_type: object = 'sinc_best', verbose: bool = False) -> numpy.typing.NDArray[numpy.float32]

samplerate.converters.resample(input: Annotated[numpy.typing.ArrayLike, numpy.float32], ratio: SupportsFloat, converter_type: object = 'sinc_best', verbose: bool = False) -> numpy.typing.NDArray[numpy.float32]

Resample the signal in input_data at once. one and done, no chunking, just send it πŸš€

Parameters

  • input_data (ndarray) β€” Input data. Input data with one or more channels is represented as a 2D array of shape (num_frames, num_channels). A single channel can be provided as a 1D array of num_frames length. For use with libsamplerate, input_data is converted to 32-bit float and C (row-major) memory order.
  • ratio (float) β€” Conversion ratio = output sample rate / input sample rate.
  • converter_type (ConverterType, str, or int) β€” Sample rate converter (default: sinc_best).
  • verbose (bool) β€” If True, print additional information about the conversion.

Returns

  • output_data β€” Resampled input data.

Return type

  • ndarray
Note: If samples are to be processed in chunks, Resampler and CallbackResampler will provide better results and allow for variable conversion ratios. so if you're feeding it piece by piece? switch classes, bestie 🫢

Full API

class samplerate.converters.Resampler

Resampler.

Parameters

  • converter_type (ConverterType, str, or int) β€” Sample rate converter (default: sinc_best).
  • num_channels (int) β€” Number of channels.

property channels β€” Number of channels.

clone(self: samplerate.converters.Resampler) -> samplerate.converters.Resampler

Creates a copy of the resampler object with the same internal state. a whole twin, same state, iconic πŸ‘―

property converter_type β€” Converter type.

process(self: samplerate.converters.Resampler, input: Annotated[numpy.typing.ArrayLike, numpy.float32], ratio: SupportsFloat, end_of_input: bool = False) -> numpy.typing.NDArray[numpy.float32]

Resample the signal in input_data.

Parameters

  • input_data (ndarray) β€” Input data. Input data with one or more channels is represented as a 2D array of shape (num_frames, num_channels). A single channel can be provided as a 1D array of num_frames length. For use with libsamplerate, input_data is converted to 32-bit float and C (row-major) memory order.
  • ratio (float) β€” Conversion ratio = output sample rate / input sample rate.
  • end_of_input (int) β€” Set to True if no more data is available, or to False otherwise.
  • verbose (bool) β€” If True, print additional information about the conversion.

Returns

  • output_data β€” Resampled input data.

Return type

  • ndarray

reset(self: samplerate.converters.Resampler) -> None

Reset internal state. clean slate, we're starting over ✨

set_ratio(self: samplerate.converters.Resampler, arg0: SupportsFloat) -> None

Set a new conversion ratio immediately. no waiting, right now, periodt.


Callback API

class samplerate.converters.CallbackResampler

CallbackResampler.

Parameters

  • callback (function) β€” Function that returns new frames on each call, or None otherwise. Input data with one or more channels is represented as a 2D array of shape (num_frames, num_channels). A single channel can be provided as a 1D array of num_frames length. For use with libsamplerate, input_data is converted to 32-bit float and C (row-major) memory order.
  • ratio (float) β€” Conversion ratio = output sample rate / input sample rate.
  • converter_type (ConverterType, str, or int) β€” Sample rate converter.
  • channels (int) β€” Number of channels.

property channels β€” Number of channels.

clone(self: samplerate.converters.CallbackResampler) -> samplerate.converters.CallbackResampler

Create a copy of the resampler object.

property converter_type β€” Converter type.

property ratio β€” Conversion ratio = output sample rate / input sample rate.

read(self: samplerate.converters.CallbackResampler, num_frames: SupportsInt) -> numpy.typing.NDArray[numpy.float32]

Read a number of frames from the resampler.

Parameters

  • num_frames (int) β€” Number of frames to read.

Returns

  • output_data β€” Resampled frames as a (num_output_frames, num_channels) or (num_output_frames,) array. Note that this may return fewer frames than requested, for example when no more input is available. don't panic if it comes up short, that's just the vibe when the input runs dry 😭

Return type

  • ndarray

reset(self: samplerate.converters.CallbackResampler) -> None

Reset state.

set_starting_ratio(self: samplerate.converters.CallbackResampler, arg0: SupportsFloat) -> None

Set the starting conversion ratio for the next read call.


πŸ’œ samplerate.exceptions -- Sample rate exceptions

class samplerate.exceptions.ResamplingError


πŸ“œ CHANGE LOG

🌟 Change Log

0.1.0

  • Initial release.

πŸŽ€ INDICES AND TABLES

  • Index
  • Module Index
  • Search Page

🌷 Author

Tino Wagner

2017, Tino Wagner


okay so that's the whole page bestie, you made it to the end and honestly? iconic πŸ’… this was from version 0.2.4, and the page is dated Aug 16, 2026 (the source line calls itself PYTHON-SAMPLERATE(1), iykyk). go resample something gorgeous πŸ¦‹βœ¨

πŸ“¦ where this page comes from