Shortcuts

TimeStretch

class torchaudio.transforms.TimeStretch(hop_length: Optional[int] = None, n_freq: int = 201, fixed_rate: Optional[float] = None)[source]

Stretch stft in time without modifying pitch for a given rate.

This feature supports the following devices: CPU, CUDA This API supports the following properties: Autograd, TorchScript

Proposed in SpecAugment [Park et al., 2019].

Parameters:
  • hop_length (int or None, optional) – Length of hop between STFT windows. (Default: win_length // 2)

  • n_freq (int, optional) – number of filter banks from stft. (Default: 201)

  • fixed_rate (float or None, optional) – rate to speed up or slow down by. If None is provided, rate must be passed to the forward method. (Default: None)

Example
>>> spectrogram = torchaudio.transforms.Spectrogram()
>>> stretch = torchaudio.transforms.TimeStretch()
>>>
>>> original = spectrogram(waveform)
>>> streched_1_2 = stretch(original, 1.2)
>>> streched_0_9 = stretch(original, 0.9)
Spectrogram streched by 1.2 The original spectrogram Spectrogram streched by 0.9
Tutorials using TimeStretch:
Audio Feature Augmentation

Audio Feature Augmentation

Audio Feature Augmentation
forward(complex_specgrams: Tensor, overriding_rate: Optional[float] = None) Tensor[source]
Parameters:
  • complex_specgrams (Tensor) – A tensor of dimension (…, freq, num_frame) with complex dtype.

  • overriding_rate (float or None, optional) – speed up to apply to this batch. If no rate is passed, use self.fixed_rate. (Default: None)

Returns:

Stretched spectrogram. The resulting tensor is of the same dtype as the input spectrogram, but the number of frames is changed to ceil(num_frame / rate).

Return type:

Tensor

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources