Skip to main content

Python bindings for the RubberBand library

Project description

pylibrb

tests PyPI version

pylibrb (py-lib-rubberband) is a simple Python extension exposing Rubber Band Library using nanobind bindings.

Since this is not a wrapper around a command-line tool (like pyrubberband), both offline and real-time modes are available.

Currently this extenstion exposes only a single class: RubberBandStretcher, which implements all the functionalities of the underlying C++ class. The interface is nearly identical to the original library, with a few changes to make it a bit more Pythonic by:

  • using snake_case for functions, variables and properties, and SNAKE_CASE for constants
  • not using (magic) numbers to represent the state
    • use is_done() to see if all the data has been processed and returned from the stretcher, instead of available() == -1
    • use stretcher.formant_scale = pylibrb.AUTO_FORMANT_SCALE instead of stretcher.formant_scale = 0

Throughout the library, audio is accepted and returned in the form of NumPy ndarrays.

Example

from pylibrb import RubberBandStretcher, Option, create_audio_array

# create a stretcher
stretcher = RubberBandStretcher(sample_rate=16000,
                                channels=1,
                                options=Option.PROCESS_REALTIME | Option.ENGINE_FINER,
                                initial_time_ratio=0.5)
stretcher.set_max_process_size(1024)

# provide the audio to the stretcher, until some output is available
audio_in = create_audio_array(channels_num=1, samples_num=1024)
while not stretcher.available():
  audio_in[:] = 0  # get the next batch of samples, here we just use silence
  stretcher.process(audio_in)

# retrieve the available samples
audio_out = stretcher.retrieve_available()

For more instructions, read the docstings of the RubberBandStretcher class and the Option enum, or see the documentation of Rubber Band Library.

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

pylibrb-0.1.2.tar.gz (33.3 kB view hashes)

Uploaded Source

Built Distributions

pylibrb-0.1.2-cp312-abi3-win_amd64.whl (2.0 MB view hashes)

Uploaded CPython 3.12+ Windows x86-64

pylibrb-0.1.2-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.12+ manylinux: glibc 2.17+ x86-64

pylibrb-0.1.2-cp312-abi3-macosx_11_0_arm64.whl (1.6 MB view hashes)

Uploaded CPython 3.12+ macOS 11.0+ ARM64

pylibrb-0.1.2-cp312-abi3-macosx_10_14_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.12+ macOS 10.14+ x86-64

pylibrb-0.1.2-cp311-cp311-win_amd64.whl (2.0 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

pylibrb-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pylibrb-0.1.2-cp311-cp311-macosx_11_0_arm64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pylibrb-0.1.2-cp311-cp311-macosx_10_14_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 macOS 10.14+ x86-64

pylibrb-0.1.2-cp310-cp310-win_amd64.whl (2.0 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

pylibrb-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pylibrb-0.1.2-cp310-cp310-macosx_11_0_arm64.whl (1.6 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pylibrb-0.1.2-cp310-cp310-macosx_10_14_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.10 macOS 10.14+ x86-64

pylibrb-0.1.2-cp39-cp39-win_amd64.whl (2.0 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

pylibrb-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pylibrb-0.1.2-cp39-cp39-macosx_11_0_arm64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pylibrb-0.1.2-cp39-cp39-macosx_10_14_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 macOS 10.14+ x86-64

pylibrb-0.1.2-cp38-cp38-win_amd64.whl (2.0 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

pylibrb-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pylibrb-0.1.2-cp38-cp38-macosx_11_0_arm64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

pylibrb-0.1.2-cp38-cp38-macosx_10_14_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 macOS 10.14+ 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