Shortcuts

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.

This feature supports the following devices: CPU, CUDA This API supports the following properties: Autograd, TorchScript
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 waveform and noise, with shape (…,) (leading dimensions must match those of waveform).

  • snr (torch.Tensor) – Signal-to-noise ratios in dB, with shape (…,).

Returns:

Result of scaling and adding noise to waveform, with shape (…, L) (same shape as waveform).

Return type:

torch.Tensor

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.

This feature supports the following devices: CPU, CUDA This API supports the following properties: Autograd, TorchScript
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 x and y, with shape (…, N + M - 1), where the leading dimensions match those of x.

Return type:

torch.Tensor

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 to torch.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).

This feature supports the following devices: CPU, CUDA This API supports the following properties: Autograd, TorchScript
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 x and y, with shape (…, N + M - 1), where the leading dimensions match those of x.

Return type:

torch.Tensor

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources