Repository: pytorch/audio

Issue:
tedlium test failing in windows on gpu in CircleCI
tedlium test failing in windows on gpu, see [here](https://app.circleci.com/pipelines/github/pytorch/audio/3455/workflows/dda668b7-25c3-48e9-bccc-d8a2c7fd6338/jobs/100751) from [here](https://app.circleci.com/pipelines/github/pytorch/audio/3455/workflows/dda668b7-25c3-48e9-bccc-d8a2c7fd6338). This may have been obscured by #929.

```
self = <torchaudio_unittest.datasets.tedlium_test.TestTedlium testMethod=test_tedlium_release1>

    def test_tedlium_release1(self):
        release = "release1"
        dataset = tedlium.TEDLIUM(self.root_dir, release=release)
        num_samples = 0
>       for i, (data, sample_rate, transcript, talk_id, speaker_id, identifier) in enumerate(dataset):

torchaudio_unittest\datasets\tedlium_test.py:99: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\env\lib\site-packages\torchaudio-0.7.0a0+3250d3d-py3.8.egg\torchaudio\datasets\tedlium.py:184: in __getitem__
    return self._load_tedlium_item(fileid, line, self._path)
..\env\lib\site-packages\torchaudio-0.7.0a0+3250d3d-py3.8.egg\torchaudio\datasets\tedlium.py:151: in _load_tedlium_item
    waveform, sample_rate = self._load_audio(wave_path + self._ext_audio, start_time=start_time, end_time=end_time)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <torchaudio.datasets.tedlium.TEDLIUM object at 0x000002883EC0CF70>
path = 'C:\\Users\\circleci\\AppData\\Local\\Temp\\tmpzvh9jdr_\\tedlium\\TEDLIUM_release1\\train\\sph\\release1.sph'
start_time = 0, end_time = 32000, sample_rate = 16000

    def _load_audio(self, path: str, start_time: float, end_time: float, sample_rate: int = 16000) -> [Tensor, int]:
        """Default load function used in TEDLIUM dataset, you can overwrite this function to customize functionality
        and load individual sentences from a full ted audio talk file.
    
        Args:
            path (str): Path to audio file
            start_time (int, optional): Time in seconds where the sample sentence stars
            end_time (int, optional): Time in seconds where the sample sentence finishes
    
        Returns:
            [Tensor, int]: Audio tensor representation and sample rate
        """
        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]
E       TypeError: tuple indices must be integers or slices, not tuple

..\env\lib\site-packages\torchaudio-0.7.0a0+3250d3d-py3.8.egg\torchaudio\datasets\tedlium.py:171: TypeError
```

Thoughts?


Discussion:

Resolving patch:
diff --git a/torchaudio/datasets/tedlium.py b/torchaudio/datasets/tedlium.py
--- a/torchaudio/datasets/tedlium.py
+++ b/torchaudio/datasets/tedlium.py
@@ -143,9 +143,14 @@ def _load_audio(self, path: str, start_time: float, end_time: float, sample_rate
         """
         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.


Test patch:
diff --git a/test/torchaudio_unittest/common_utils/backend_utils.py b/test/torchaudio_unittest/common_utils/backend_utils.py
--- a/test/torchaudio_unittest/common_utils/backend_utils.py
+++ b/test/torchaudio_unittest/common_utils/backend_utils.py
@@ -6,11 +6,15 @@
 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:
diff --git a/test/torchaudio_unittest/datasets/tedlium_test.py b/test/torchaudio_unittest/datasets/tedlium_test.py
--- a/test/torchaudio_unittest/datasets/tedlium_test.py
+++ b/test/torchaudio_unittest/datasets/tedlium_test.py
@@ -1,8 +1,11 @@
 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 @@
 ]
 
 
-class TestTedlium(TempDirMixin, TorchaudioTestCase):
-    backend = "default"
-
+class Tedlium(TempDirMixin):
     root_dir = None
     samples = {}
 
@@ -151,3 +152,20 @@ def test_tedlium_release3(self):
         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"