#16249·Speech

MagpieTTS raw-audio padding adds a spurious silent frame to exact-multiple-length audio

Author: udsy19Created Sep 13, 2026Updated Sep 15, 2026
Labelscommunity-requestwaiting-on-maintainers

Describe the bug

MagpieTTSDataset.__getitem__ and MagpieTTSLhotseDataset's equivalent raw-audio branch pad loaded audio up to a multiple of codec_model_samples_per_frame with:

python
audio = torch.nn.functional.pad(
    audio,
    (0, self.codec_model_samples_per_frame - (audio.shape[0] % self.codec_model_samples_per_frame)),
    value=0,
)

When audio.shape[0] is already an exact multiple of codec_model_samples_per_frame, the modulo is 0 and the pad amount becomes codec_model_samples_per_frame itself instead of 0 — a full spurious silent frame is appended to the training target audio.

This branch is the fallback whenever a manifest entry has no pre-computed target_audio_codes_path (or load_cached_codes_if_available is False), which is a real, documented path for raw-audio MagpieTTS training, not a corner case.

Steps/Code to reproduce bug

python
import torch

codec_model_samples_per_frame = 256
audio = torch.zeros(codec_model_samples_per_frame * 5)  # already an exact multiple

padded = torch.nn.functional.pad(
    audio,
    (0, codec_model_samples_per_frame - (audio.shape[0] % codec_model_samples_per_frame)),
    value=0,
)
print(padded.shape[0])  # 1536, expected 1280 (no padding needed)

Expected behavior

Audio whose length already divides codec_model_samples_per_frame evenly should not be padded at all (audio_len unchanged), matching the sibling guard in nemo/collections/tts/data/dataset.py's _pad_wav_to_multiple, which explicitly checks if wav.shape[0] % self.pad_multiple != 0 before padding.

Environment overview

  • Environment location: Bare-metal
  • Method of NeMo install: from source (main branch)

Environment details

  • OS version: Ubuntu 24.04
  • PyTorch version: 2.13.0+cpu
  • Python version: 3.12.3

Additional context

Both occurrences share the identical formula:

  • nemo/collections/tts/data/text_to_speech_dataset.py (MagpieTTSDataset.__getitem__)
  • nemo/collections/tts/data/text_to_speech_dataset_lhotse.py (MagpieTTSLhotseDataset)

Introduced in 19367c9c25 (#15031, "Update MagpieTTS model with latest changes"); not exercised by any existing test.