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 the audio-stretch library by David Bryant, which implements a sophisticated time-stretching algorithm for high-quality results.

Version: 1.1.2

Features

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

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.

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

Installation

Install AudioStretchy using pip:

python3 -m pip install audiostretchy

or

python3 -m pip install git+https://github.com/twardoch/audiostretchy

Usage

CLI

audiostretchy INFILENAME OUTFILENAME <flags>

POSITIONAL ARGUMENTS
    INFILENAME
        The path to the input WAV file.
    OUTFILENAME
        The path to the output WAV file.

FLAGS
    -r, --ratio=RATIO
        Type: float
        Default: 1.0
        The ratio to use for processing. Defaults to 1.0.
    -s, --silence_ratio=SILENCE_RATIO
        Type: float
        Default: 0.0
        The silence ratio to use for processing if different from ratio

Python

from audiostretchy.stretch import process_audio

input_file = "input.wav"
output_file = "output.wav"
stretch_ratio = 1.1

process_audio(input_file, output_file, ratio=stretch_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.

API

The main function to use in AudioStretchy is process_audio in audiostretchy.stretch:

process_audio(
    infilename: Union[str, Path],
    outfilename: Union[str, Path],
    ratio: float = 1.0,
    silence_ratio: float = 0.0,
)
  • infilename: The path to the input audio file (WAV format).
  • outfilename: The path to the output audio file (WAV format).
  • ratio: The stretching ratio. Must be between 0.25 and 4.0. Defaults to 1.0 (no stretching).
  • silence_ratio: The silence ratio to use for processing. Must be between 0.25 and 4.0. Defaults to 0.0 (use the same ratio as ratio).

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.1.2.tar.gz (2.4 MB view details)

Uploaded Source

Built Distribution

audiostretchy-1.1.2-py3-none-any.whl (81.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for audiostretchy-1.1.2.tar.gz
Algorithm Hash digest
SHA256 affe0477f6de9dd365cdb63336a87022c258d61895be1bbd0b60fe3c30f55577
MD5 951b8923f84a7895f23e3993bf4d9519
BLAKE2b-256 df8cf6ce47a2b1594e271a9a5a34c2dafbb45c9ba411a78801d7f6da4653cb5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for audiostretchy-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 767ddb92cb1dcf9b63d84d31682b8f1862f7976f47ad4756121d55064cac2b21
MD5 1e2571d2c11941e5732d70b89b1de6e0
BLAKE2b-256 2ae439899536096a5abe0f8a22b5059f23d7e8ea55c0818469c284867747c81d

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