From 265bc5ca97fbd6618af22c0c8d3915340847fe4c Mon Sep 17 00:00:00 2001 From: Zhenyu Tang Date: Thu, 12 Dec 2024 21:32:48 -0800 Subject: [PATCH] Fix incorrect audio trimming with negative index Differential Revision: D67155973 Pull Request resolved: https://github.com/pytorch/audio/pull/3860 --- src/torchaudio/functional/filtering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/torchaudio/functional/filtering.py b/src/torchaudio/functional/filtering.py index 97ff6040dc..1628d82c33 100644 --- a/src/torchaudio/functional/filtering.py +++ b/src/torchaudio/functional/filtering.py @@ -1665,6 +1665,6 @@ def vad( if not has_triggered: return waveform[..., :0].view(shape[:-1] + torch.Size([0])) - res = waveform[:, pos - samplesLen_ns + flushedLen_ns :] + res = waveform[:, max(pos - samplesLen_ns + flushedLen_ns, 0) :] # unpack batch return res.view(shape[:-1] + res.shape[-1:])