Shortcuts

torchaudio.functional.apply_codec

torchaudio.functional.apply_codec(waveform: Tensor, sample_rate: int, format: str, channels_first: bool = True, compression: Optional[float] = None, encoding: Optional[str] = None, bits_per_sample: Optional[int] = None) Tensor[source]

Apply codecs as a form of augmentation.

This feature supports the following devices: CPU
Parameters:
  • waveform (Tensor) – Audio data. Must be 2 dimensional. See also `channels_first`.

  • sample_rate (int) – Sample rate of the audio waveform.

  • format (str) – File format.

  • channels_first (bool, optional) – When True, both the input and output Tensor have dimension (channel, time). Otherwise, they have dimension (time, channel).

  • compression (float or None, optional) – Used for formats other than WAV. For more details see torchaudio.backend.sox_io_backend.save().

  • encoding (str or None, optional) – Changes the encoding for the supported formats. For more details see torchaudio.backend.sox_io_backend.save().

  • bits_per_sample (int or None, optional) – Changes the bit depth for the supported formats. For more details see torchaudio.backend.sox_io_backend.save().

Returns:

Resulting Tensor. If channels_first=True, it has (channel, time) else (time, channel).

Return type:

Tensor

Tutorials using apply_codec:
Audio Data Augmentation

Audio Data Augmentation

Audio Data Augmentation

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