Skip to main content

AudioStretchy

AudioStretchy is a Python library that allows you to time-stretch audio signals without changing their pitch. It is a wrapper around David Bryant’s audio-stretch library by David Bryant, which implements a sophisticated time-stretching algorithm for high-quality results.

Version: 1.2.0

Features

  • Time stretching of audio files without changing their pitch
  • Supports WAV files, and optionally MP3 files
  • Adjustable stretching ratio from 0.25 to 4.0
  • Cross-platform: Windows, macOS, and Linux
  • Optional resampling

The following explanation is adapted from the original audio-stretch C library:

Time-domain harmonic scaling (TDHS) is a method for time-scale modification of speech (or other audio signals), allowing the apparent rate of speech articulation to be changed without affecting the pitch-contour and the time-evolution of the formant structure. TDHS differs from other time-scale modification algorithms in that time-scaling operations are performed in the time domain (not the frequency domain).

This project is a Python wrapper around a a TDHS library to utilize it with standard WAV files.

There are two effects possible with TDHS and the audio-stretch demo. The first is the more obvious mentioned above of changing the duration (or speed) of a speech (or other audio) sample without modifying its pitch. The other effect is similar, but after applying the duration change we change the sampling rate in a complimentary manner to restore the original duration and timing, which then results in the pitch being altered.

So when a ratio is supplied to the audio-stretch program, the default operation is for the total duration of the audio file to be scaled by exactly that ratio (0.5X to 2.0X), with the pitches remaining constant. If the option to scale the sample-rate proportionally is specified (-s) then the total duration and timing of the audio file will be preserved, but the pitches will be scaled by the specified ratio instead. This is useful for creating a "helium voice" effect and lots of other fun stuff.

Note that unless ratios of exactly 0.5 or 2.0 are used with the -s option, non-standard sampling rates will probably result. Many programs will still properly play these files, and audio editing programs will likely import them correctly (by resampling), but it is possible that some applications will barf on them. They can also be resampled to a standard rate using audio-resampler by David Bryant.

Note: The Python package does not expose all command-line options of the original library.

Installation

Simple installation

To be able to stretch and resample WAV and MP3 files, install AudioStretchy using pip like so:

pip install audiostretchy[all]

Efficient installation

To only be able to stretch WAV files, install AudioStretchy without dependencies like so:

pip install audiostretchy

Development installation

To install the development version, use:

python3 -m pip install git+https://github.com/twardoch/audiostretchy#egg=audiostretchy[all]

Usage

CLI

audiostretchy INPUT_WAV OUTPUT_WAV <flags>

POSITIONAL ARGUMENTS
    INPUT_WAV
    OUTPUT_WAV

FLAGS
    -r, --ratio=RATIO
        Default: 1.0
    -g, --gap_ratio=GAP_RATIO
        Default: 0.0
    -u, --upper_freq=UPPER_FREQ
        Default: 333
    -l, --lower_freq=LOWER_FREQ
        Default: 55
    -b, --buffer_ms=BUFFER_MS
        Default: 25
    -t, --threshold_gap_db=THRESHOLD_GAP_DB
        Default: -40
    -d, --dual_force=DUAL_FORCE
        Default: False
    -f, --fast_detection=FAST_DETECTION
        Default: False
    -n, --normal_detection=NORMAL_DETECTION
        Default: False
    -s, --sample_rate=SAMPLE_RATE
        Default: 0

Python

from audiostretchy.stretch import stretch_audio

stretch_audio("input.wav", "output.wav", ratio=ratio)

In this example, the input.wav file will be time-stretched by a factor of 1.1, meaning it will be 10% longer, and the result will be saved in the output.wav file.

For advanced usage, you can use the AudioStretch class (docs to be provided).

License

Release files for audiostretchy 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for audiostretchy 1.2.0
File Size Uploaded
audiostretchy-1.2.0.tar.gz 1.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for audiostretchy 1.2.0
File Interpreter ABI Platform
audiostretchy-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.9 MB

Release files / audiostretchy-1.2.0.tar.gz

Download URL audiostretchy-1.2.0.tar.gz
Size 1.8 MB
Tags Source
SHA-256 checksum
How to use checksums
5f57c46529c2978aec4d0aa529129c3809aa02e9098409c66656a4403a16bb8b
BLAKE2b-256 checksum
How to use checksums
452d5453c3baa51d74a874835aab3e83404c582bc7f32868ee9cbcfdf487089c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / audiostretchy-1.2.0-py3-none-any.whl

Download URL audiostretchy-1.2.0-py3-none-any.whl
Size 82.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70fb7f402629486984db37980d6bd823bef4ac6943d79c420d4a07724aa6c947
BLAKE2b-256 checksum
How to use checksums
ff87ad404953fb327683626ee709ea66d0f25e960b267a7369e6b78ca1c61ddf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release history Release notifications | RSS feed

1.3.5

2 release files

1.3.4

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

This release

1.2.0 This release

2 release files

1.1.2

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

1 release file

1.0.5

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page