Repository: pytorch/audio

Issue:
torch.stft calls need to be updated to set the return_complex kwarg
torch.stft (https://pytorch.org/docs/master/generated/torch.stft.html?highlight=stft#torch.stft) has deprecated not setting the return_complex kwarg, and we want to make passing return_complex required before the PyTorch 1.8 release. To avoid torchaudio breaking with PyTorch nightlies or PyTorch 1.8 it needs to update its torch.stft calls to pass the return_complex argument. 


Discussion:

Resolving patch:
diff --git a/torchaudio/functional/functional.py b/torchaudio/functional/functional.py
--- a/torchaudio/functional/functional.py
+++ b/torchaudio/functional/functional.py
@@ -70,8 +70,19 @@ def spectrogram(
     waveform = waveform.reshape(-1, shape[-1])
 
     # default values are consistent with librosa.core.spectrum._spectrogram
-    spec_f = torch.stft(
-        waveform, n_fft, hop_length, win_length, window, True, "reflect", False, True
+    spec_f = torch.view_as_real(
+        torch.stft(
+            input=waveform,
+            n_fft=n_fft,
+            hop_length=hop_length,
+            win_length=win_length,
+            window=window,
+            center=True,
+            pad_mode="reflect",
+            normalized=False,
+            onesided=True,
+            return_complex=True,
+        )
     )
 
     # unpack batch
@@ -174,8 +185,20 @@ def griffinlim(
                               length=length).float()
 
         # Rebuild the spectrogram
-        rebuilt = torch.stft(inverse, n_fft, hop_length, win_length, window,
-                             True, 'reflect', False, True)
+        rebuilt = torch.view_as_real(
+            torch.stft(
+                input=inverse,
+                n_fft=n_fft,
+                hop_length=hop_length,
+                win_length=win_length,
+                window=window,
+                center=True,
+                pad_mode='reflect',
+                normalized=False,
+                onesided=True,
+                return_complex=True,
+            )
+        )
 
         # Update our phase estimates
         angles = rebuilt


Test patch:
diff --git a/test/torchaudio_unittest/batch_consistency_test.py b/test/torchaudio_unittest/batch_consistency_test.py
--- a/test/torchaudio_unittest/batch_consistency_test.py
+++ b/test/torchaudio_unittest/batch_consistency_test.py
@@ -227,19 +227,22 @@ def test_batch_TimeStretch(self):
         test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
         waveform, _ = torchaudio.load(test_filepath)  # (2, 278756), 44100
 
-        kwargs = {
-            'n_fft': 2048,
-            'hop_length': 512,
-            'win_length': 2048,
-            'window': torch.hann_window(2048),
-            'center': True,
-            'pad_mode': 'reflect',
-            'normalized': True,
-            'onesided': True,
-        }
         rate = 2
 
-        complex_specgrams = torch.stft(waveform, **kwargs)
+        complex_specgrams = torch.view_as_real(
+            torch.stft(
+                input=waveform,
+                n_fft=2048,
+                hop_length=512,
+                win_length=2048,
+                window=torch.hann_window(2048),
+                center=True,
+                pad_mode='reflect',
+                normalized=True,
+                onesided=True,
+                return_complex=True,
+            )
+        )
 
         # Single then transform then batch
         expected = torchaudio.transforms.TimeStretch(