def assert_amb(self, dtype, sample_rate, num_channels, normalize, duration): """`sox_io_backend.load` can load amb format. This test takes the same strategy as mp3 to compare the result """ path = self.get_temp_path('1.original.amb') ref_path = self.get_temp_path('2.reference.wav') # 1. Generate amb with sox sox_utils.gen_audio_file(path, sample_rate, num_channels, encoding=sox_utils.get_encoding(dtype), bit_depth=sox_utils.get_bit_depth(dtype), duration=duration) # 2. Convert to wav with sox sox_utils.convert_audio_file(path, ref_path) # 3. Load amb with torchaudio data, sr = sox_io_backend.load(path, normalize=normalize) # 4. Load wav with scipy data_ref = load_wav(ref_path, normalize=normalize)[0] # 5. Compare assert sr == sample_rate self.assertEqual(data, data_ref, atol=4e-05, rtol=1.3e-06)
def test_amb(self, dtype, sample_rate, num_channels, normalize): """`sox_io_backend.load` can load amb format correctly.""" bit_depth = sox_utils.get_bit_depth(dtype) encoding = sox_utils.get_encoding(dtype) self.assert_format("amb", sample_rate, num_channels, bit_depth=bit_depth, duration=1, encoding=encoding, normalize=normalize)
def _gen_file(self, ext, dtype, sample_rate, num_channels, num_frames): path = self.get_temp_path(f'test.{ext}') bit_depth = sox_utils.get_bit_depth(dtype) duration = num_frames / sample_rate sox_utils.gen_audio_file( path, sample_rate, num_channels=num_channels, encoding=sox_utils.get_encoding(dtype), bit_depth=bit_depth, duration=duration) return path
def _gen_file(self, ext, dtype, sample_rate, num_channels, num_frames, *, comments=None): path = self.get_temp_path(f'test.{ext}') bit_depth = sox_utils.get_bit_depth(dtype) duration = num_frames / sample_rate comment_file = self._gen_comment_file(comments) if comments else None sox_utils.gen_audio_file( path, sample_rate, num_channels=num_channels, encoding=sox_utils.get_encoding(dtype), bit_depth=bit_depth, duration=duration, comment_file=comment_file, ) return path