Skip to content

Commit

Permalink
Set individual backends
Browse files Browse the repository at this point in the history
  • Loading branch information
mthrok committed Jun 12, 2020
1 parent d9b240a commit 8519dc6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/test_batch_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def test_griffinlim(self):
)

def test_detect_pitch_frequency(self):
common_utils.set_audio_backend('default')
filenames = [
'steam-train-whistle-daniel_simon.wav', # 2ch 44100Hz
# Files from https://www.mediacollege.com/audio/tone/download/
Expand Down Expand Up @@ -79,6 +80,7 @@ def test_overdrive(self):
self.assert_batch_consistencies(F.overdrive, waveform, gain=45, colour=30)

def test_phaser(self):
common_utils.set_audio_backend('default')
filepath = common_utils.get_asset_path("whitenoise.wav")
waveform, sample_rate = torchaudio.load(filepath)
self.assert_batch_consistencies(F.phaser, waveform, sample_rate)
Expand All @@ -97,6 +99,7 @@ def test_sliding_window_cmn(self):
self.assert_batch_consistencies(F.sliding_window_cmn, waveform, center=False, norm_vars=False)

def test_vad(self):
common_utils.set_audio_backend('default')
filepath = common_utils.get_asset_path("vad-go-mono-32000.wav")
waveform, sample_rate = torchaudio.load(filepath)
self.assert_batch_consistencies(F.vad, waveform, sample_rate=sample_rate)
Expand Down Expand Up @@ -168,6 +171,7 @@ def test_batch_compute_deltas(self):
self.assertEqual(computed, expected)

def test_batch_mulaw(self):
common_utils.set_audio_backend('default')
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath) # (2, 278756), 44100

Expand All @@ -193,6 +197,7 @@ def test_batch_mulaw(self):
self.assertEqual(computed, expected)

def test_batch_spectrogram(self):
common_utils.set_audio_backend('default')
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath) # (2, 278756), 44100

Expand All @@ -204,6 +209,7 @@ def test_batch_spectrogram(self):
self.assertEqual(computed, expected)

def test_batch_melspectrogram(self):
common_utils.set_audio_backend('default')
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath) # (2, 278756), 44100

Expand All @@ -215,6 +221,7 @@ def test_batch_melspectrogram(self):
self.assertEqual(computed, expected)

def test_batch_mfcc(self):
common_utils.set_audio_backend('default')
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath)

Expand All @@ -226,6 +233,7 @@ def test_batch_mfcc(self):
self.assertEqual(computed, expected, atol=1e-4, rtol=1e-5)

def test_batch_TimeStretch(self):
common_utils.set_audio_backend('default')
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath) # (2, 278756), 44100

Expand Down Expand Up @@ -260,6 +268,7 @@ def test_batch_TimeStretch(self):
self.assertEqual(computed, expected, atol=1e-5, rtol=1e-5)

def test_batch_Fade(self):
common_utils.set_audio_backend('default')
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath) # (2, 278756), 44100
fade_in_len = 3000
Expand All @@ -273,6 +282,7 @@ def test_batch_Fade(self):
self.assertEqual(computed, expected)

def test_batch_Vol(self):
common_utils.set_audio_backend('default')
test_filepath = common_utils.get_asset_path('steam-train-whistle-daniel_simon.wav')
waveform, _ = torchaudio.load(test_filepath) # (2, 278756), 44100

Expand Down
3 changes: 3 additions & 0 deletions test/test_librosa_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def _load_audio_asset(*asset_paths, **kwargs):
class TestTransforms(common_utils.TorchaudioTestCase):
"""Test suite for functions in `transforms` module."""
def assert_compatibilities(self, n_fft, hop_length, power, n_mels, n_mfcc, sample_rate):
common_utils.set_audio_backend('default')
sound, sample_rate = _load_audio_asset('sinewave.wav')
sound_librosa = sound.cpu().numpy().squeeze() # (64000)

Expand Down Expand Up @@ -275,6 +276,7 @@ def test_MelScale(self):
hop_length = n_fft // 4

# Prepare spectrogram input. We use torchaudio to compute one.
common_utils.set_audio_backend('default')
sound, sample_rate = _load_audio_asset('whitenoise_1min.mp3')
sound = sound.mean(dim=0, keepdim=True)
spec_ta = F.spectrogram(
Expand All @@ -297,6 +299,7 @@ def test_InverseMelScale(self):
hop_length = n_fft // 4

# Prepare mel spectrogram input. We use torchaudio to compute one.
common_utils.set_audio_backend('default')
sound, sample_rate = _load_audio_asset(
'steam-train-whistle-daniel_simon.wav', offset=2**10, num_frames=2**14)
sound = sound.mean(dim=0, keepdim=True)
Expand Down

0 comments on commit 8519dc6

Please sign in to comment.