Skip to content

fix: clamp shift perturbation for short audio instead of silently skipping#15561

Open
stanley1208 wants to merge 1 commit intoNVIDIA-NeMo:mainfrom
stanley1208:fix/shift-perturbation-clamp-short-audio
Open

fix: clamp shift perturbation for short audio instead of silently skipping#15561
stanley1208 wants to merge 1 commit intoNVIDIA-NeMo:mainfrom
stanley1208:fix/shift-perturbation-clamp-short-audio

Conversation

@stanley1208
Copy link
Copy Markdown
Contributor

What does this PR do?

Fix a bug in ShiftPerturbation.perturb() where audio augmentation was silently skipped when the randomly sampled shift exceeded the audio duration. This caused short audio clips to receive no shift augmentation at all, with no warning to the user.

Before: If abs(shift_ms) / 1000 > data.duration, the method returned immediately — a silent no-op. Users with short utterances or large max_shift_ms had their augmentation silently disabled.

After: The shift is clamped to the audio duration so some shift is always applied. This resolves the TODO at line 442: "do something smarter than just ignore this condition".

Collection: ASR

Changelog

  • Fix ShiftPerturbation.perturb() to clamp shift amount instead of silently skipping augmentation for short audio
  • Remove resolved TODO comment
  • Add 7 unit tests for ShiftPerturbation covering normal operation, short audio clamping, length preservation, and zero-shift edge case

Usage

from nemo.collections.asr.parts.preprocessing.perturb import ShiftPerturbation

# Previously: short audio (5ms) with max_shift=20ms would silently skip augmentation
# Now: shift is clamped to audio duration and applied
perturb = ShiftPerturbation(min_shift_ms=10.0, max_shift_ms=20.0)
perturb.perturb(short_audio_segment)  # now always applies shift

…pping

Signed-off-by: stanley1208 <stanley.mei08@gmail.com>
Made-with: Cursor
@github-actions github-actions bot added the ASR label Mar 29, 2026
@stanley1208
Copy link
Copy Markdown
Contributor Author

@nithinraok @pzelasko Ready for review — fixes a real bug where ShiftPerturbation silently skipped augmentation for short audio clips. Resolves the TODO at perturb.py line 442. Includes 7 unit tests. Thanks!

Copy link
Copy Markdown
Collaborator

@pzelasko pzelasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good to me.

@chtruong814 chtruong814 added the needs-follow-up Issue needs follow-up label Mar 31, 2026
@stanley1208
Copy link
Copy Markdown
Contributor Author

@pzelasko @nithinraok Friendly ping , this was approved but hasn't been merged yet. Is there anything else needed? Happy to address any feedback. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants