speechbrain.augment.codec module

Codec Augmentation via soundfile

This library provides codec augmentation techniques for enhanced audio data processing. Waveforms are encoded to an in-memory buffer with an audio codec and decoded back, simulating the artefacts introduced by lossy compression.

Authors
  • Mirco Ravanelli 2023

  • Peter Plantinga 2026

Summary

Classes:

CodecAugment

Apply random audio codecs to input waveforms using soundfile.

Reference

class speechbrain.augment.codec.CodecAugment(sample_rate=16000)[source]

Bases: Module

Apply random audio codecs to input waveforms using soundfile.

This class provides an interface for applying codec augmentation techniques to audio data.

Parameters:

sample_rate (int) – The sample rate of the input waveform.

Example

>>> waveform = torch.rand(4, 16000)
>>> augmenter = CodecAugment(16000)
>>> output_waveform = augmenter(waveform)
>>> output_waveform.shape
torch.Size([4, 16000])
apply_codec(waveform, format=None, encoder=None)[source]

Apply the selected audio codec.

Parameters:
  • waveform (torch.Tensor) – Input waveform of shape [batch, time].

  • format (str) – The soundfile format to use (e.g., “WAV”, “MP3”). Default is None.

  • encoder (str) – The soundfile subtype to use for the format (e.g., “ULAW”, “OPUS”). Default is None, letting soundfile pick the default subtype.

Returns:

Coded version of the input waveform of shape [batch, time].

Return type:

torch.Tensor

forward(waveform)[source]

Apply a random audio codec from the available list.

Parameters:

waveform (torch.Tensor) – Input waveform of shape [batch, time].

Returns:

Coded version of the input waveform of shape [batch, time].

Return type:

torch.Tensor