def test_2_load(self): for backend in BACKENDS_MP3: with self.subTest(): with AudioBackendScope(backend): self._test_2_load(self.test_filepath, 278756) for backend in BACKENDS: with self.subTest(): with AudioBackendScope(backend): self._test_2_load(self.test_filepath_wav, 276858)
def test_1_save(self): for backend in BACKENDS_MP3: with self.subTest(): with AudioBackendScope(backend): self._test_1_save(self.test_filepath, False) for backend in BACKENDS: with self.subTest(): with AudioBackendScope(backend): self._test_1_save(self.test_filepath_wav, True)
def _test_3_load_and_save_is_identity_across_backend( self, backend1, backend2): with AudioBackendScope(backend1): input_path = os.path.join(self.test_dirpath, 'assets', 'sinewave.wav') tensor1, sample_rate1 = torchaudio.load(input_path) output_path = os.path.join(self.test_dirpath, 'test.wav') torchaudio.save(output_path, tensor1, sample_rate1) with AudioBackendScope(backend2): tensor2, sample_rate2 = torchaudio.load(output_path) self.assertTrue(tensor1.allclose(tensor2)) self.assertEqual(sample_rate1, sample_rate2) os.unlink(output_path)
E.append_effect_to_chain("vol", [gain, gain_type]) x, sr = E.sox_build_flow_effects() vol = torchaudio.transforms.Vol(gain, gain_type) z = vol(x_orig) # check if effect worked self.assertTrue(x.allclose(z, rtol=1e-4, atol=1e-4)) def test_vad(self): sample_files = [ common_utils.get_asset_path("vad-go-stereo-44100.wav"), common_utils.get_asset_path("vad-go-mono-32000.wav") ] for sample_file in sample_files: E = torchaudio.sox_effects.SoxEffectsChain() E.set_input_file(sample_file) E.append_effect_to_chain("vad") x, _ = E.sox_build_flow_effects() x_orig, sample_rate = torchaudio.load(sample_file) vad = torchaudio.transforms.Vad(sample_rate) y = vad(x_orig) self.assertTrue(x.allclose(y, rtol=1e-4, atol=1e-4)) if __name__ == '__main__': with AudioBackendScope("sox"): unittest.main()
def test_1_save_sine(self): for backend in BACKENDS: with self.subTest(): with AudioBackendScope(backend): self._test_1_save_sine()
def test_5_get_info(self): for backend in BACKENDS: with self.subTest(): with AudioBackendScope(backend): self._test_5_get_info()
def test_4_load_partial(self): for backend in BACKENDS_MP3: with self.subTest(): with AudioBackendScope(backend): self._test_4_load_partial()
def test_3_load_and_save_is_identity(self): for backend in BACKENDS: with self.subTest(): with AudioBackendScope(backend): self._test_3_load_and_save_is_identity()
def test_2_load_nonormalization(self): for backend in BACKENDS_MP3: with self.subTest(): with AudioBackendScope(backend): self._test_2_load_nonormalization(self.test_filepath, 278756)