Unverified Commit 4f0acc58 authored by Vincent QB's avatar Vincent QB Committed by GitHub
Browse files

fix tedlium load_audio (#934)

and add test on other backend.
parent 725f8b06
......@@ -6,11 +6,15 @@ import torchaudio
def set_audio_backend(backend):
"""Allow additional backend value, 'default'"""
backends = torchaudio.list_audio_backends()
if backend == 'default':
if backend == 'soundfile-new':
be = 'soundfile'
torchaudio.USE_SOUNDFILE_LEGACY_INTERFACE = False
elif backend == 'default':
if 'sox_io' in backends:
be = 'sox_io'
elif 'soundfile' in backends:
be = 'soundfile'
torchaudio.USE_SOUNDFILE_LEGACY_INTERFACE = True
else:
raise unittest.SkipTest('No default backend available')
else:
......
import os
import platform
import unittest
from torchaudio.datasets import tedlium
from torchaudio_unittest.common_utils import (
TestBaseMixin,
TempDirMixin,
TorchaudioTestCase,
get_whitenoise,
......@@ -30,9 +33,7 @@ PHONEME = [
]
class TestTedlium(TempDirMixin, TorchaudioTestCase):
backend = "default"
class Tedlium(TempDirMixin):
root_dir = None
samples = {}
......@@ -151,3 +152,20 @@ class TestTedlium(TempDirMixin, TorchaudioTestCase):
phoneme_dict = dataset.phoneme_dict
phoenemes = [f"{key} {' '.join(value)}" for key, value in phoneme_dict.items()]
assert phoenemes == PHONEME
class TestTedliumSoundfile(Tedlium, TorchaudioTestCase):
backend = "soundfile"
class TestTedliumSoundfileNew(Tedlium, TorchaudioTestCase):
backend = "soundfile-new"
if platform.system() != "Windows":
class TestTedliumSox(Tedlium, TorchaudioTestCase):
backend = "sox"
class TestTedliumSoxIO(Tedlium, TorchaudioTestCase):
backend = "sox_io"
......@@ -143,9 +143,14 @@ class TEDLIUM(Dataset):
"""
start_time = int(float(start_time) * sample_rate)
end_time = int(float(end_time) * sample_rate)
if torchaudio.get_audio_backend() == "sox_io":
return torchaudio.load(path, frame_offset=start_time, num_frames=end_time - start_time)
return torchaudio.load(path)[:, start_time:end_time]
backend = torchaudio.get_audio_backend()
if backend == "sox" or (backend == "soundfile" and torchaudio.USE_SOUNDFILE_LEGACY_INTERFACE):
kwargs = {"offset": start_time, "num_frames": end_time - start_time}
else:
kwargs = {"frame_offset": start_time, "num_frames": end_time - start_time}
return torchaudio.load(path, **kwargs)
def __getitem__(self, n: int) -> Tuple[Tensor, int, str, int, int, int]:
"""Load the n-th sample from the dataset.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment