Skip to content

Commit

Permalink
Add test for frames
Browse files Browse the repository at this point in the history
  • Loading branch information
mthrok committed Jan 4, 2021
1 parent 22aadef commit 13023be
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/torchaudio_unittest/sox_io_backend/load_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,25 @@ def test_requests(self, ext, compression):

assert sr == sample_rate
self.assertEqual(expected, found)

@parameterized.expand(list(itertools.product(
[0, 1, 10, 100, 1000],
[-1, 1, 10, 100, 1000],
)), name_func=name_func)
def test_frame(self, frame_offset, num_frames):
"""num_frames and frame_offset correctly specify the region of data"""
sample_rate = 8000
audio_file = f'test.wav'
audio_path = self.get_temp_path(audio_file)

original = get_wav_data('float32', num_channels=2)
save_wav(audio_path, original, sample_rate)
frame_end = None if num_frames == -1 else frame_offset + num_frames
expected = original[:, frame_offset:frame_end]

url = self.get_url(audio_file)
with requests.get(url, stream=True) as resp:
found, sr = sox_io_backend.load(resp.raw, frame_offset, num_frames)

assert sr == sample_rate
self.assertEqual(expected, found)

0 comments on commit 13023be

Please sign in to comment.