Skip to main content

Simple wrapper for librubberband

Project description


rubberband is a simple Python3 wrapper around the well-known librubberband sound stretching / pitch-shifting library. Unlike existing Python wrappers (e.g. pyrubberband) this is a true native extension.

The initial release provides a single function that will stretch a mono audio stream my multiplying its duration by a provided factor. Future versions may include pitch shifting, and more complex processing based on data maps.


The module is available only for MacOS and Linux. The code may compile on Windows, but it has not been tested. Dependencies are:

Assuming these dependencies are met, then installation is simplicity itself:

pip3 install rubberband

The install script does check for the required libraries, and will complain vociferously if they cannot be located. Information on obtaining them is available from the links above.


rubberband.stretch (inarray, rate , ratio , crispness = 5 , formants = False )


input audio is assumed to be encoded as single-dimensional NUMPY arrays of type float32. librubberband assumes that input data is normalised to the range [-1,1]; rubberband.stretch automatically applies normalisation if it is required
the frame rate of the input audio stream (so bit rate divided by sample size)
the ration of output length to input length (in seconds / number of samples)
integer 0 - 6, default 5: measure of performance - see the rubberband-cli documentation for more details
Boolean, default False : whether or not to preserve formants - see the rubberband-cli documentation for more details
Return value
a one-dimensional NUMPY array of type float32 containing the stretched audio data


import rubberband
from sound import wavfile

nFrames = None
rate = None
bitrate = None
stream = None

with wavfile("infile.wav",rw='r') as wav:
    stream =


print(f'Ratio is {ratio}')


with wavfile("outfilet.wav",rw='w',rate=rate) as f:

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for rubberband, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size rubberband-0.2.0-cp37-cp37m-macosx_10_9_x86_64.whl (19.1 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size rubberband-0.2.0.tar.gz (93.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page