Skip to main content

Wrapper around the audio-stretch C library to time-stretch WAV files without changing their pitch

Project description

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

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

audiostretchy-1.2.0.tar.gz (1.8 MB view details)

Uploaded Source

Built Distribution

audiostretchy-1.2.0-py3-none-any.whl (82.9 kB view details)

Uploaded Python 3

File details

Details for the file audiostretchy-1.2.0.tar.gz.

File metadata

  • Download URL: audiostretchy-1.2.0.tar.gz
  • Upload date:
  • Size: 1.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for audiostretchy-1.2.0.tar.gz
Algorithm Hash digest
SHA256 5f57c46529c2978aec4d0aa529129c3809aa02e9098409c66656a4403a16bb8b
MD5 cff32eaac4375c426cb2355e5e8b2985
BLAKE2b-256 452d5453c3baa51d74a874835aab3e83404c582bc7f32868ee9cbcfdf487089c

See more details on using hashes here.

File details

Details for the file audiostretchy-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for audiostretchy-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70fb7f402629486984db37980d6bd823bef4ac6943d79c420d4a07724aa6c947
MD5 d1bd1e894244eb026cc3030df7ce5242
BLAKE2b-256 ff87ad404953fb327683626ee709ea66d0f25e960b267a7369e6b78ca1c61ddf

See more details on using hashes here.

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