diff --git a/torchaudio/functional.py b/torchaudio/functional.py index e748416df8d..b17afe1e50a 100644 --- a/torchaudio/functional.py +++ b/torchaudio/functional.py @@ -104,6 +104,12 @@ def spectrogram( if normalized: spec_f /= window.pow(2.).sum().sqrt() if power is not None: + if power == 1.0: + return spec_f.abs() + if power == 2.0: + if spec_f.is_cuda: + return torch.view_as_real(spec_f).pow(power).sum(-1) + return spec_f.pow(power) return spec_f.abs().pow(power) return torch.view_as_real(spec_f)