class torchaudio.transforms.TimeMasking(time_mask_param: int, iid_masks: bool = False, p: float = 1.0)[source]

Apply masking to a spectrogram in the time domain.

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

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

  • time_mask_param (int) – maximum possible length of the mask. Indices uniformly sampled from [0, time_mask_param).

  • iid_masks (bool, optional) – whether to apply different masks to each example/channel in the batch. (Default: False) This option is applicable only when the input tensor is 4D.

  • p (float, optional) – maximum proportion of time steps that can be masked. Must be within range [0.0, 1.0]. (Default: 1.0)

>>> spectrogram = torchaudio.transforms.Spectrogram()
>>> masking = torchaudio.transforms.TimeMasking(time_mask_param=80)
>>> original = spectrogram(waveform)
>>> masked = masking(original)
The original spectrogram The spectrogram masked along time axis
Tutorials using TimeMasking:
Audio Feature Augmentation

Audio Feature Augmentation

Audio Feature Augmentation


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources