exordium.audio.wavlm

WavLM speech encoding model wrapper.

Attributes

WAVLM_SAMPLE_RATE

Required audio sample rate for all WavLM variants (16 000 Hz).

Classes

WavlmWrapper

Wrapper for WavLM audio feature extraction via HuggingFace Transformers.

Module Contents

exordium.audio.wavlm.WAVLM_SAMPLE_RATE = 16000

Required audio sample rate for all WavLM variants (16 000 Hz).

class exordium.audio.wavlm.WavlmWrapper(device_id: int = -1, model_name: str = 'base+', pretrained: bool = True)[source]

Bases: exordium.audio.base.AudioModelWrapper

Wrapper for WavLM audio feature extraction via HuggingFace Transformers.

Extracts layer-wise hidden states using Microsoft’s WavLM model. Supports base, base+, and large model variants.

Parameters:
  • device_id – GPU device ID. Use -1 for CPU.

  • model_name – Model variant — "base", "base+", or "large". Defaults to "base+".

Raises:

ValueError – If model_name is not one of the supported variants.

Initialize with device setup.

Parameters:

device_id – GPU device ID. Use -1 for CPU.

__call__(waveform: numpy.ndarray | torch.Tensor) → list[torch.Tensor][source]

Extract hidden-state features from a waveform.

Parameters:

waveform – Audio signal of shape (T,) or (B, T) at WAVLM_SAMPLE_RATE Hz.

Returns:

List of hidden-state tensors, one per transformer layer, each of shape (B, T', hidden_size).

Raises:

ValueError – If waveform has an invalid shape (not 1D or 2D).

audio_to_feature(audio: pathlib.Path | str | numpy.ndarray | torch.Tensor, **_kwargs) → list[numpy.ndarray]

Extract WavLM features from a single audio path or waveform.

Parameters:
  • audio – Audio file path, numpy array, or torch tensor. If a path is given, audio is loaded and resampled to 16 kHz.

  • **kwargs – Passed to load_or_create() (output_path, overwrite).

Returns:

List of layer features as numpy arrays, each of shape (T, hidden_size).

batch_audio_to_features(audios: list[pathlib.Path | str | numpy.ndarray | torch.Tensor], **_kwargs) → list[list[numpy.ndarray]][source]

Extract WavLM features from multiple audio inputs in one forward pass.

Variable-length inputs are zero-padded to the longest waveform. Output frames that correspond to padding are trimmed.

Parameters:

audios – List of audio file paths, numpy arrays, or torch tensors.

Returns:

List of per-file features. Each element is a list of layer numpy arrays, each of shape (T_i, hidden_size).

inference(waveform: numpy.ndarray | torch.Tensor) → list[torch.Tensor][source]

Extract features in inference mode.

Parameters:

waveform – Audio signal of shape (T,) or (B, T).

Returns:

List of hidden-state tensors, each of shape (B, T', hidden_size).

Raises:

ValueError – If waveform has an invalid shape.