torchaudio.functional.add_noise
- torchaudio.functional.add_noise(waveform: Tensor, noise: Tensor, snr: Tensor, lengths: Optional[Tensor] = None) Tensor [source]
Scales and adds noise to waveform per signal-to-noise ratio.
Specifically, for each pair of waveform vector and noise vector , the function computes output as
where
with being the desired signal-to-noise ratio between and , in dB.
Note that this function broadcasts singleton leading dimensions in its inputs in a manner that is consistent with the above formulae and PyTorch’s broadcasting semantics.
- Parameters:
waveform (torch.Tensor) – Input waveform, with shape (…, L).
noise (torch.Tensor) – Noise, with shape (…, L) (same shape as
waveform
).snr (torch.Tensor) – Signal-to-noise ratios in dB, with shape (…,).
lengths (torch.Tensor or None, optional) – Valid lengths of signals in
waveform
andnoise
, with shape (…,) (leading dimensions must match those ofwaveform
). IfNone
, all elements inwaveform
andnoise
are treated as valid. (Default:None
)
- Returns:
Result of scaling and adding
noise
towaveform
, with shape (…, L) (same shape aswaveform
).- Return type:
- Tutorials using
add_noise
: Torchaudio-Squim: Non-intrusive Speech Assessment in TorchAudio
Torchaudio-Squim: Non-intrusive Speech Assessment in TorchAudio