How to use the torchaudio.functional function in torchaudio

To help you get started, we’ve selected a few torchaudio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pytorch / audio / torchaudio / transforms.py View on Github external
def forward(self, waveform):
        r"""
        Args:
            waveform (torch.Tensor): Tensor of audio of dimension (channel, time)

        Returns:
            torch.Tensor: Dimension (channel, freq, time), where channel
            is unchanged, freq is ``n_fft // 2 + 1`` where ``n_fft`` is the number of
            Fourier bins, and time is the number of window hops (n_frame).
        """
        return F.spectrogram(waveform, self.pad, self.window, self.n_fft, self.hop_length,
                             self.win_length, self.power, self.normalized)
github pytorch / audio / test / test_functional.py View on Github external
def test_istft_requires_non_empty(self):
        self.assertRaises(AssertionError, torchaudio.functional.istft, torch.zeros((3, 0, 2)), 2)
        self.assertRaises(AssertionError, torchaudio.functional.istft, torch.zeros((0, 3, 2)), 2)
github pytorch / audio / test / test_jit.py View on Github external
def jit_method(sig, pad, window, n_fft, hop, ws, power, normalize):
            # type: (Tensor, int, Tensor, int, int, int, int, bool) -> Tensor
            return F.spectrogram(sig, pad, window, n_fft, hop, ws, power, normalize)
github pytorch / audio / test / test_functional.py View on Github external
kwargs_ok = {
            'n_fft': 4,
            'win_length': 4,
            'window': torch.ones(4),
        }

        kwargs_not_ok = {
            'n_fft': 4,
            'win_length': 4,
            'window': torch.zeros(4),
        }

        # A window of ones meets NOLA but a window of zeros does not. This should
        # throw an error.
        torchaudio.functional.istft(stft, **kwargs_ok)
        self.assertRaises(AssertionError, torchaudio.functional.istft, stft, **kwargs_not_ok)
github pytorch / audio / torchaudio / augmentations.py View on Github external
def forward(self, specgram, mask_value=0.):
        # type: (Tensor, float) -> Tensor
        r"""
        Args:
            specgram (torch.Tensor): Tensor of dimension (*, channel, freq, time)

        Returns:
            torch.Tensor: Masked spectrogram of dimensions (*, channel, freq, time)
        """

        # if iid_masks flag marked and specgram has a batch dimension
        if self.iid_masks and specgram.dim() == 4:
            return F.mask_along_axis_iid(specgram, self.mask_param, mask_value, self.axis + 1)
        else:
            shape = specgram.size()
            specgram = specgram.reshape([-1] + list(shape[-2:]))
            specgram = F.mask_along_axis(specgram, self.mask_param, mask_value, self.axis)

            return specgram.reshape(shape[:-2] + specgram.shape[-2:])
github pytorch / audio / torchaudio / transforms.py View on Github external
(Tensor): Stretched complex spectrogram of dimension (..., freq, ceil(time/rate), complex=2)
        """
        assert complex_specgrams.size(-1) == 2, "complex_specgrams should be a complex tensor, shape (..., complex=2)"

        if overriding_rate is None:
            rate = self.fixed_rate
            if rate is None:
                raise ValueError("If no fixed_rate is specified"
                                 ", must pass a valid rate to the forward method.")
        else:
            rate = overriding_rate

        if rate == 1.0:
            return complex_specgrams

        return F.phase_vocoder(complex_specgrams, rate, self.phase_advance)
github AppleHolic / pytorch_sound / pytorch_sound / models / transforms.py View on Github external
def __init__(self, n_mfcc: int, mel_size: int, norm: str = 'ortho'):
        super().__init__()
        self.n_mfcc = n_mfcc
        dct_mat = audio_func.create_dct(n_mfcc, mel_size, norm)
        self.register_buffer('dct_mat', dct_mat.transpose(0, 1))
github pytorch / audio / torchaudio / transforms.py View on Github external
def forward(self, x_mu):
        r"""
        Args:
            x_mu (torch.Tensor): A mu-law encoded signal which needs to be decoded

        Returns:
            torch.Tensor: The signal decoded
        """
        return F.mu_law_decoding(x_mu, self.quantization_channels)