torchaudio.prototype.functional¶
add_noise¶
- torchaudio.prototype.functional.add_noise(waveform: Tensor, noise: Tensor, lengths: Tensor, snr: Tensor) Tensor[source]¶
Scales and adds noise to waveform per signal-to-noise ratio.
Specifically, for each pair of waveform vector \(x \in \mathbb{R}^L\) and noise vector \(n \in \mathbb{R}^L\), the function computes output \(y\) as
\[y = x + a n \, \text{,} \]where
\[a = \sqrt{ \frac{ ||x||_{2}^{2} }{ ||n||_{2}^{2} } \cdot 10^{-\frac{\text{SNR}}{10}} } \, \text{,} \]with \(\text{SNR}\) being the desired signal-to-noise ratio between \(x\) and \(n\), 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).lengths (torch.Tensor) – Valid lengths of signals in
waveformandnoise, with shape (…,) (leading dimensions must match those ofwaveform).snr (torch.Tensor) – Signal-to-noise ratios in dB, with shape (…,).
- Returns:
Result of scaling and adding
noisetowaveform, with shape (…, L) (same shape aswaveform).- Return type:
convolve¶
- torchaudio.prototype.functional.convolve(x: Tensor, y: Tensor) Tensor[source]¶
Convolves inputs along their last dimension using the direct method. Note that, in contrast to
torch.nn.functional.conv1d(), which actually applies the valid cross-correlation operator, this function applies the true convolution operator.- Parameters:
x (torch.Tensor) – First convolution operand, with shape (…, N).
y (torch.Tensor) – Second convolution operand, with shape (…, M) (leading dimensions must match those of
x).
- Returns:
Result of convolving
xandy, with shape (…, N + M - 1), where the leading dimensions match those ofx.- Return type:
fftconvolve¶
- torchaudio.prototype.functional.fftconvolve(x: Tensor, y: Tensor) Tensor[source]¶
Convolves inputs along their last dimension using FFT. For inputs with large last dimensions, this function is generally much faster than
convolve(). Note that, in contrast totorch.nn.functional.conv1d(), which actually applies the valid cross-correlation operator, this function applies the true convolution operator. Also note that this function can only output float tensors (int tensor inputs will be cast to float).- Parameters:
x (torch.Tensor) – First convolution operand, with shape (…, N).
y (torch.Tensor) – Second convolution operand, with shape (…, M) (leading dimensions must match those of
x).
- Returns:
Result of convolving
xandy, with shape (…, N + M - 1), where the leading dimensions match those ofx.- Return type: