Python Stretch is a simple library for pitch shifting and time stretching audio, currently at version 0.3.1. It acts as a wrapper for the Signalsmith Stretch C++ Library, providing high-quality audio manipulation capabilities. The library supports both mono and multichannel audio and integrates seamlessly with NumPy arrays, making it compatible with other audio processing libraries like librosa. It is also utilized as the core method for pitch and time stretching in the popular audiomentations library. The project shows active maintenance with recent PyPI uploads for version 0.3.1 in early 2025.
pip install python-stretchVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load an audio file using `librosa`, initialize the `Signalsmith.Stretch` object, configure pitch shifting and time stretching parameters, and process the audio. It assumes `librosa` and `soundfile` are installed for loading/saving audio.
Prefer `pip install python-stretch` to use pre-built wheels. If building from source is necessary, ensure a C++ compiler (like g++ or clang) and CMake are installed and correctly configured.
Always convert input audio to a NumPy array, and ensure it has the shape (channels, samples), even for mono audio (e.g., `audio[np.newaxis, :]` for a 1D array).
Install `librosa` and `soundfile` separately if you intend to use the quickstart examples or perform typical audio I/O: `pip install librosa soundfile`.
Use `import stretch` instead of `import python_stretch` or `import python-stretch`.
Ensure `python-stretch` is correctly installed by reinstalling with `pip install --no-cache-dir python-stretch`. On Linux, ensure `python3-dev` (or equivalent) is installed; on Windows, ensure Visual C++ Build Tools are available.
Ensure that `channels` and `samplerate` are cast to integers before being passed to the `SignalsmithStretch` constructor, e.g., `stretch.SignalsmithStretch(int(channels), int(samplerate))`.