Exemplo n.º 1
0
 def test_InverseSpectrogram(self):
     tensor = common_utils.get_whitenoise(sample_rate=8000)
     spectrogram = common_utils.get_spectrogram(tensor,
                                                n_fft=400,
                                                hop_length=100)
     self._assert_consistency_complex(
         T.InverseSpectrogram(n_fft=400, hop_length=100), spectrogram)
Exemplo n.º 2
0
 def test_InverseSpectrogram_pseudocomplex(self):
     tensor = common_utils.get_whitenoise(sample_rate=8000)
     spectrogram = common_utils.get_spectrogram(tensor,
                                                n_fft=400,
                                                hop_length=100)
     spectrogram = torch.view_as_real(spectrogram)
     self._assert_consistency(
         T.InverseSpectrogram(n_fft=400, hop_length=100), spectrogram)
Exemplo n.º 3
0
 def test_inverse_spectrogram(self):
     # create a realistic input:
     waveform = get_whitenoise(sample_rate=8000,
                               duration=0.05,
                               n_channels=2)
     length = waveform.shape[-1]
     spectrogram = get_spectrogram(waveform, n_fft=400)
     # test
     inv_transform = T.InverseSpectrogram(n_fft=400)
     self.assert_grad(inv_transform, [spectrogram, length])
Exemplo n.º 4
0
    def test_roundtrip_spectrogram(self, **args):
        """Test the spectrogram + inverse spectrogram results in approximate identity."""

        waveform = get_whitenoise(sample_rate=8000,
                                  duration=0.5,
                                  dtype=self.dtype)

        s = T.Spectrogram(**args, power=None)
        inv_s = T.InverseSpectrogram(**args)
        transformed = s.forward(waveform)
        restored = inv_s.forward(transformed, length=waveform.shape[-1])
        self.assertEqual(waveform, restored, atol=1e-6, rtol=1e-6)