Usage

Installation

You can install torch-time-stretch from PyPI.

pip install torch-time-stretch

To upgrade an existing installation of torch-time-stretch, use the following command:

pip install --upgrade --no-cache-dir torch-time-stretch

Importing

First, import torch-time-stretch.

# import all functions
from torch_time_stretch import *

# ... or import them manually
from torch_time_stretch import get_fast_stretches, time_stretch

What's included

torch-time-stretch includes the following:

Type Name Description
Function time_stretch Stretch a batch of waveforms by a given amount without altering the pitch.
Function get_fast_stretches Utility function for calculating time-stretches that can be executed quickly.

Methods

time_stretch

Stretch a batch of waveforms by a given amount without altering the pitch.

Arguments

Argument Required Default Value Type Description
input Yes
torch.Tensor [
    shape=(
        batch_size,
        channels,
        samples
    )
]
Input audio clips of shape (batch_size, channels, samples)
stretch Yes float or Fraction Indicates the stretch ratio (usually an element in get_fast_stretches()).
sample_rate Yes int The sample rate of the input audio clips.
n_fft No sample_rate // 64 int Size of FFT. Default sample_rate // 64. Smaller is faster.

Return value

Type Description
torch.Tensor [
    shape=(
        batch_size,
        channels,
        samples
    )
]
The time-stretched batch of audio clips

get_fast_stretches

Search for time-stretch targets that can be computed quickly for a given sample rate.

Argument Required Default Value Type Description
sample_rate Yes int The sample rate of an audio clip.
condition No
lambda x: (
    x >= 0.5 and x <= 2 and x != 1
)
Callable A function to validate fast stretch ratios. Default value limits computed targets to values between 50% and 200% speed

Return value

Type Description
List[Fraction] A list of fast time-stretch target ratios that satisfy the given conditions.

Example

See example.py to see an example of torch-time-stretch in action!