Skip to content

Commit

Permalink
Do not use IO functions in batch consistency test (#1521)
Browse files Browse the repository at this point in the history
  • Loading branch information
jachymuv authored May 22, 2021
1 parent ae9560d commit c4a1702
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions test/torchaudio_unittest/transforms/batch_consistency_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def test_batch_compute_deltas(self):
self.assertEqual(computed, expected)

def test_batch_mulaw(self):
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath) # (2, 278756), 44100
waveform = common_utils.get_whitenoise(sample_rate=8000, duration=1, n_channels=2)

# Single then transform then batch
waveform_encoded = torchaudio.transforms.MuLawEncoding()(waveform)
Expand All @@ -99,8 +98,7 @@ def test_batch_mulaw(self):
self.assertEqual(computed, expected)

def test_batch_spectrogram(self):
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath) # (2, 278756), 44100
waveform = common_utils.get_whitenoise(sample_rate=8000, duration=1, n_channels=2)

# Single then transform then batch
expected = torchaudio.transforms.Spectrogram()(waveform).repeat(3, 1, 1, 1)
Expand All @@ -110,8 +108,7 @@ def test_batch_spectrogram(self):
self.assertEqual(computed, expected)

def test_batch_melspectrogram(self):
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath) # (2, 278756), 44100
waveform = common_utils.get_whitenoise(sample_rate=8000, duration=1, n_channels=2)

# Single then transform then batch
expected = torchaudio.transforms.MelSpectrogram()(waveform).repeat(3, 1, 1, 1)
Expand All @@ -121,8 +118,7 @@ def test_batch_melspectrogram(self):
self.assertEqual(computed, expected)

def test_batch_mfcc(self):
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath)
waveform = common_utils.get_whitenoise(sample_rate=8000, duration=1, n_channels=2)

# Single then transform then batch
expected = torchaudio.transforms.MFCC()(waveform).repeat(3, 1, 1, 1)
Expand Down Expand Up @@ -160,8 +156,7 @@ def test_batch_TimeStretch(self, test_pseudo_complex):
self.assertEqual(computed, expected, atol=1e-5, rtol=1e-5)

def test_batch_Fade(self):
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath) # (2, 278756), 44100
waveform = common_utils.get_whitenoise(sample_rate=8000, duration=1, n_channels=2)
fade_in_len = 3000
fade_out_len = 3000

Expand All @@ -173,8 +168,7 @@ def test_batch_Fade(self):
self.assertEqual(computed, expected)

def test_batch_Vol(self):
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath) # (2, 278756), 44100
waveform = common_utils.get_whitenoise(sample_rate=8000, duration=1, n_channels=2)

# Single then transform then batch
expected = torchaudio.transforms.Vol(gain=1.1)(waveform).repeat(3, 1, 1)
Expand Down

0 comments on commit c4a1702

Please sign in to comment.