torchaudio 2.9.1__cp311-cp311-manylinux_2_28_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. torchaudio/__init__.py +204 -0
  2. torchaudio/_extension/__init__.py +61 -0
  3. torchaudio/_extension/utils.py +133 -0
  4. torchaudio/_internal/__init__.py +10 -0
  5. torchaudio/_internal/module_utils.py +171 -0
  6. torchaudio/_torchcodec.py +340 -0
  7. torchaudio/compliance/__init__.py +5 -0
  8. torchaudio/compliance/kaldi.py +813 -0
  9. torchaudio/datasets/__init__.py +47 -0
  10. torchaudio/datasets/cmuarctic.py +157 -0
  11. torchaudio/datasets/cmudict.py +186 -0
  12. torchaudio/datasets/commonvoice.py +86 -0
  13. torchaudio/datasets/dr_vctk.py +121 -0
  14. torchaudio/datasets/fluentcommands.py +108 -0
  15. torchaudio/datasets/gtzan.py +1118 -0
  16. torchaudio/datasets/iemocap.py +147 -0
  17. torchaudio/datasets/librilight_limited.py +111 -0
  18. torchaudio/datasets/librimix.py +133 -0
  19. torchaudio/datasets/librispeech.py +174 -0
  20. torchaudio/datasets/librispeech_biasing.py +189 -0
  21. torchaudio/datasets/libritts.py +168 -0
  22. torchaudio/datasets/ljspeech.py +107 -0
  23. torchaudio/datasets/musdb_hq.py +139 -0
  24. torchaudio/datasets/quesst14.py +136 -0
  25. torchaudio/datasets/snips.py +157 -0
  26. torchaudio/datasets/speechcommands.py +183 -0
  27. torchaudio/datasets/tedlium.py +218 -0
  28. torchaudio/datasets/utils.py +54 -0
  29. torchaudio/datasets/vctk.py +143 -0
  30. torchaudio/datasets/voxceleb1.py +309 -0
  31. torchaudio/datasets/yesno.py +89 -0
  32. torchaudio/functional/__init__.py +130 -0
  33. torchaudio/functional/_alignment.py +128 -0
  34. torchaudio/functional/filtering.py +1685 -0
  35. torchaudio/functional/functional.py +2505 -0
  36. torchaudio/lib/__init__.py +0 -0
  37. torchaudio/lib/_torchaudio.so +0 -0
  38. torchaudio/lib/libtorchaudio.so +0 -0
  39. torchaudio/models/__init__.py +85 -0
  40. torchaudio/models/_hdemucs.py +1008 -0
  41. torchaudio/models/conformer.py +293 -0
  42. torchaudio/models/conv_tasnet.py +330 -0
  43. torchaudio/models/decoder/__init__.py +64 -0
  44. torchaudio/models/decoder/_ctc_decoder.py +568 -0
  45. torchaudio/models/decoder/_cuda_ctc_decoder.py +187 -0
  46. torchaudio/models/deepspeech.py +84 -0
  47. torchaudio/models/emformer.py +884 -0
  48. torchaudio/models/rnnt.py +816 -0
  49. torchaudio/models/rnnt_decoder.py +339 -0
  50. torchaudio/models/squim/__init__.py +11 -0
  51. torchaudio/models/squim/objective.py +326 -0
  52. torchaudio/models/squim/subjective.py +150 -0
  53. torchaudio/models/tacotron2.py +1046 -0
  54. torchaudio/models/wav2letter.py +72 -0
  55. torchaudio/models/wav2vec2/__init__.py +45 -0
  56. torchaudio/models/wav2vec2/components.py +1167 -0
  57. torchaudio/models/wav2vec2/model.py +1579 -0
  58. torchaudio/models/wav2vec2/utils/__init__.py +7 -0
  59. torchaudio/models/wav2vec2/utils/import_fairseq.py +213 -0
  60. torchaudio/models/wav2vec2/utils/import_huggingface.py +134 -0
  61. torchaudio/models/wav2vec2/wavlm_attention.py +214 -0
  62. torchaudio/models/wavernn.py +409 -0
  63. torchaudio/pipelines/__init__.py +102 -0
  64. torchaudio/pipelines/_source_separation_pipeline.py +109 -0
  65. torchaudio/pipelines/_squim_pipeline.py +156 -0
  66. torchaudio/pipelines/_tts/__init__.py +16 -0
  67. torchaudio/pipelines/_tts/impl.py +385 -0
  68. torchaudio/pipelines/_tts/interface.py +255 -0
  69. torchaudio/pipelines/_tts/utils.py +230 -0
  70. torchaudio/pipelines/_wav2vec2/__init__.py +0 -0
  71. torchaudio/pipelines/_wav2vec2/aligner.py +87 -0
  72. torchaudio/pipelines/_wav2vec2/impl.py +1699 -0
  73. torchaudio/pipelines/_wav2vec2/utils.py +346 -0
  74. torchaudio/pipelines/rnnt_pipeline.py +380 -0
  75. torchaudio/transforms/__init__.py +78 -0
  76. torchaudio/transforms/_multi_channel.py +467 -0
  77. torchaudio/transforms/_transforms.py +2138 -0
  78. torchaudio/utils/__init__.py +4 -0
  79. torchaudio/utils/download.py +89 -0
  80. torchaudio/version.py +2 -0
  81. torchaudio-2.9.1.dist-info/METADATA +133 -0
  82. torchaudio-2.9.1.dist-info/RECORD +85 -0
  83. torchaudio-2.9.1.dist-info/WHEEL +5 -0
  84. torchaudio-2.9.1.dist-info/licenses/LICENSE +25 -0
  85. torchaudio-2.9.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,54 @@
1
+ import logging
2
+ import os
3
+ import tarfile
4
+ import zipfile
5
+ from typing import Any, List, Optional # noqa: F401
6
+
7
+ import torchaudio
8
+
9
+ _LG = logging.getLogger(__name__)
10
+
11
+
12
+ def _extract_tar(from_path: str, to_path: Optional[str] = None, overwrite: bool = False) -> List[str]:
13
+ if to_path is None:
14
+ to_path = os.path.dirname(from_path)
15
+ with tarfile.open(from_path, "r") as tar:
16
+ files = []
17
+ for file_ in tar: # type: Any
18
+ file_path = os.path.join(to_path, file_.name)
19
+ if file_.isfile():
20
+ files.append(file_path)
21
+ if os.path.exists(file_path):
22
+ _LG.info("%s already extracted.", file_path)
23
+ if not overwrite:
24
+ continue
25
+ tar.extract(file_, to_path)
26
+ return files
27
+
28
+
29
+ def _extract_zip(from_path: str, to_path: Optional[str] = None, overwrite: bool = False) -> List[str]:
30
+ if to_path is None:
31
+ to_path = os.path.dirname(from_path)
32
+
33
+ with zipfile.ZipFile(from_path, "r") as zfile:
34
+ files = zfile.namelist()
35
+ for file_ in files:
36
+ file_path = os.path.join(to_path, file_)
37
+ if os.path.exists(file_path):
38
+ _LG.info("%s already extracted.", file_path)
39
+ if not overwrite:
40
+ continue
41
+ zfile.extract(file_, to_path)
42
+ return files
43
+
44
+
45
+ def _load_waveform(
46
+ root: str,
47
+ filename: str,
48
+ exp_sample_rate: int,
49
+ ):
50
+ path = os.path.join(root, filename)
51
+ waveform, sample_rate = torchaudio.load(path)
52
+ if exp_sample_rate != sample_rate:
53
+ raise ValueError(f"sample rate should be {exp_sample_rate}, but got {sample_rate}")
54
+ return waveform
@@ -0,0 +1,143 @@
1
+ import os
2
+ from typing import Tuple
3
+
4
+ import torchaudio
5
+ from torch import Tensor
6
+ from torch.utils.data import Dataset
7
+ from torchaudio._internal import download_url_to_file
8
+ from torchaudio.datasets.utils import _extract_zip
9
+
10
+ URL = "https://datashare.is.ed.ac.uk/bitstream/handle/10283/3443/VCTK-Corpus-0.92.zip"
11
+ _CHECKSUMS = {
12
+ "https://datashare.is.ed.ac.uk/bitstream/handle/10283/3443/VCTK-Corpus-0.92.zip": "f96258be9fdc2cbff6559541aae7ea4f59df3fcaf5cf963aae5ca647357e359c" # noqa: E501
13
+ }
14
+
15
+
16
+ SampleType = Tuple[Tensor, int, str, str, str]
17
+
18
+
19
+ class VCTK_092(Dataset):
20
+ """*VCTK 0.92* :cite:`yamagishi2019vctk` dataset
21
+
22
+ Args:
23
+ root (str): Root directory where the dataset's top level directory is found.
24
+ mic_id (str, optional): Microphone ID. Either ``"mic1"`` or ``"mic2"``. (default: ``"mic2"``)
25
+ download (bool, optional):
26
+ Whether to download the dataset if it is not found at root path. (default: ``False``).
27
+ url (str, optional): The URL to download the dataset from.
28
+ (default: ``"https://datashare.is.ed.ac.uk/bitstream/handle/10283/3443/VCTK-Corpus-0.92.zip"``)
29
+ audio_ext (str, optional): Custom audio extension if dataset is converted to non-default audio format.
30
+
31
+ Note:
32
+ * All the speeches from speaker ``p315`` will be skipped due to the lack of the corresponding text files.
33
+ * All the speeches from ``p280`` will be skipped for ``mic_id="mic2"`` due to the lack of the audio files.
34
+ * Some of the speeches from speaker ``p362`` will be skipped due to the lack of the audio files.
35
+ * See Also: https://datashare.is.ed.ac.uk/handle/10283/3443
36
+ """
37
+
38
+ def __init__(
39
+ self,
40
+ root: str,
41
+ mic_id: str = "mic2",
42
+ download: bool = False,
43
+ url: str = URL,
44
+ audio_ext=".flac",
45
+ ):
46
+ if mic_id not in ["mic1", "mic2"]:
47
+ raise RuntimeError(f'`mic_id` has to be either "mic1" or "mic2". Found: {mic_id}')
48
+
49
+ archive = os.path.join(root, "VCTK-Corpus-0.92.zip")
50
+
51
+ self._path = os.path.join(root, "VCTK-Corpus-0.92")
52
+ self._txt_dir = os.path.join(self._path, "txt")
53
+ self._audio_dir = os.path.join(self._path, "wav48_silence_trimmed")
54
+ self._mic_id = mic_id
55
+ self._audio_ext = audio_ext
56
+
57
+ if download:
58
+ if not os.path.isdir(self._path):
59
+ if not os.path.isfile(archive):
60
+ checksum = _CHECKSUMS.get(url, None)
61
+ download_url_to_file(url, archive, hash_prefix=checksum)
62
+ _extract_zip(archive, self._path)
63
+
64
+ if not os.path.isdir(self._path):
65
+ raise RuntimeError("Dataset not found. Please use `download=True` to download it.")
66
+
67
+ # Extracting speaker IDs from the folder structure
68
+ self._speaker_ids = sorted(os.listdir(self._txt_dir))
69
+ self._sample_ids = []
70
+
71
+ """
72
+ Due to some insufficient data complexity in the 0.92 version of this dataset,
73
+ we start traversing the audio folder structure in accordance with the text folder.
74
+ As some of the audio files are missing of either ``mic_1`` or ``mic_2`` but the
75
+ text is present for the same, we first check for the existence of the audio file
76
+ before adding it to the ``sample_ids`` list.
77
+
78
+ Once the ``audio_ids`` are loaded into memory we can quickly access the list for
79
+ different parameters required by the user.
80
+ """
81
+ for speaker_id in self._speaker_ids:
82
+ if speaker_id == "p280" and mic_id == "mic2":
83
+ continue
84
+ utterance_dir = os.path.join(self._txt_dir, speaker_id)
85
+ for utterance_file in sorted(f for f in os.listdir(utterance_dir) if f.endswith(".txt")):
86
+ utterance_id = os.path.splitext(utterance_file)[0]
87
+ audio_path_mic = os.path.join(
88
+ self._audio_dir,
89
+ speaker_id,
90
+ f"{utterance_id}_{mic_id}{self._audio_ext}",
91
+ )
92
+ if speaker_id == "p362" and not os.path.isfile(audio_path_mic):
93
+ continue
94
+ self._sample_ids.append(utterance_id.split("_"))
95
+
96
+ def _load_text(self, file_path) -> str:
97
+ with open(file_path) as file_path:
98
+ return file_path.readlines()[0]
99
+
100
+ def _load_audio(self, file_path) -> Tuple[Tensor, int]:
101
+ return torchaudio.load(file_path)
102
+
103
+ def _load_sample(self, speaker_id: str, utterance_id: str, mic_id: str) -> SampleType:
104
+ transcript_path = os.path.join(self._txt_dir, speaker_id, f"{speaker_id}_{utterance_id}.txt")
105
+ audio_path = os.path.join(
106
+ self._audio_dir,
107
+ speaker_id,
108
+ f"{speaker_id}_{utterance_id}_{mic_id}{self._audio_ext}",
109
+ )
110
+
111
+ # Reading text
112
+ transcript = self._load_text(transcript_path)
113
+
114
+ # Reading FLAC
115
+ waveform, sample_rate = self._load_audio(audio_path)
116
+
117
+ return (waveform, sample_rate, transcript, speaker_id, utterance_id)
118
+
119
+ def __getitem__(self, n: int) -> SampleType:
120
+ """Load the n-th sample from the dataset.
121
+
122
+ Args:
123
+ n (int): The index of the sample to be loaded
124
+
125
+ Returns:
126
+ Tuple of the following items;
127
+
128
+ Tensor:
129
+ Waveform
130
+ int:
131
+ Sample rate
132
+ str:
133
+ Transcript
134
+ str:
135
+ Speaker ID
136
+ std:
137
+ Utterance ID
138
+ """
139
+ speaker_id, utterance_id = self._sample_ids[n]
140
+ return self._load_sample(speaker_id, utterance_id, self._mic_id)
141
+
142
+ def __len__(self) -> int:
143
+ return len(self._sample_ids)
@@ -0,0 +1,309 @@
1
+ import os
2
+ from pathlib import Path
3
+ from typing import List, Tuple, Union
4
+
5
+ from torch import Tensor
6
+ from torch.utils.data import Dataset
7
+ from torchaudio._internal import download_url_to_file
8
+ from torchaudio.datasets.utils import _extract_zip, _load_waveform
9
+
10
+
11
+ SAMPLE_RATE = 16000
12
+ _ARCHIVE_CONFIGS = {
13
+ "dev": {
14
+ "archive_name": "vox1_dev_wav.zip",
15
+ "urls": [
16
+ "https://thor.robots.ox.ac.uk/~vgg/data/voxceleb/vox1a/vox1_dev_wav_partaa",
17
+ "https://thor.robots.ox.ac.uk/~vgg/data/voxceleb/vox1a/vox1_dev_wav_partab",
18
+ "https://thor.robots.ox.ac.uk/~vgg/data/voxceleb/vox1a/vox1_dev_wav_partac",
19
+ "https://thor.robots.ox.ac.uk/~vgg/data/voxceleb/vox1a/vox1_dev_wav_partad",
20
+ ],
21
+ "checksums": [
22
+ "21ec6ca843659ebc2fdbe04b530baa4f191ad4b0971912672d92c158f32226a0",
23
+ "311d21e0c8cbf33573a4fce6c80e5a279d80736274b381c394319fc557159a04",
24
+ "92b64465f2b2a3dc0e4196ae8dd6828cbe9ddd1f089419a11e4cbfe2e1750df0",
25
+ "00e6190c770b27f27d2a3dd26ee15596b17066b715ac111906861a7d09a211a5",
26
+ ],
27
+ },
28
+ "test": {
29
+ "archive_name": "vox1_test_wav.zip",
30
+ "url": "https://thor.robots.ox.ac.uk/~vgg/data/voxceleb/vox1a/vox1_test_wav.zip",
31
+ "checksum": "8de57f347fe22b2c24526e9f444f689ecf5096fc2a92018cf420ff6b5b15eaea",
32
+ },
33
+ }
34
+ _IDEN_SPLIT_URL = "https://www.robots.ox.ac.uk/~vgg/data/voxceleb/meta/iden_split.txt"
35
+ _VERI_TEST_URL = "https://www.robots.ox.ac.uk/~vgg/data/voxceleb/meta/veri_test.txt"
36
+
37
+
38
+ def _download_extract_wavs(root: str):
39
+ for archive in ["dev", "test"]:
40
+ archive_name = _ARCHIVE_CONFIGS[archive]["archive_name"]
41
+ archive_path = os.path.join(root, archive_name)
42
+ # The zip file of dev data is splited to 4 chunks.
43
+ # Download and combine them into one file before extraction.
44
+ if archive == "dev":
45
+ urls = _ARCHIVE_CONFIGS[archive]["urls"]
46
+ checksums = _ARCHIVE_CONFIGS[archive]["checksums"]
47
+ with open(archive_path, "wb") as f:
48
+ for url, checksum in zip(urls, checksums):
49
+ file_path = os.path.join(root, os.path.basename(url))
50
+ download_url_to_file(url, file_path, hash_prefix=checksum)
51
+ with open(file_path, "rb") as f_split:
52
+ f.write(f_split.read())
53
+ else:
54
+ url = _ARCHIVE_CONFIGS[archive]["url"]
55
+ checksum = _ARCHIVE_CONFIGS[archive]["checksum"]
56
+ download_url_to_file(url, archive_path, hash_prefix=checksum)
57
+ _extract_zip(archive_path)
58
+
59
+
60
+ def _get_flist(root: str, file_path: str, subset: str) -> List[str]:
61
+ f_list = []
62
+ if subset == "train":
63
+ index = 1
64
+ elif subset == "dev":
65
+ index = 2
66
+ else:
67
+ index = 3
68
+ with open(file_path, "r") as f:
69
+ for line in f:
70
+ id, path = line.split()
71
+ if int(id) == index:
72
+ f_list.append(path)
73
+ return sorted(f_list)
74
+
75
+
76
+ def _get_paired_flist(root: str, veri_test_path: str):
77
+ f_list = []
78
+ with open(veri_test_path, "r") as f:
79
+ for line in f:
80
+ label, path1, path2 = line.split()
81
+ f_list.append((label, path1, path2))
82
+ return f_list
83
+
84
+
85
+ def _get_file_id(file_path: str, _ext_audio: str):
86
+ speaker_id, youtube_id, utterance_id = file_path.split("/")[-3:]
87
+ utterance_id = utterance_id.replace(_ext_audio, "")
88
+ file_id = "-".join([speaker_id, youtube_id, utterance_id])
89
+ return file_id
90
+
91
+
92
+ class VoxCeleb1(Dataset):
93
+ """*VoxCeleb1* :cite:`nagrani2017voxceleb` dataset.
94
+
95
+ Args:
96
+ root (str or Path): Path to the directory where the dataset is found or downloaded.
97
+ download (bool, optional):
98
+ Whether to download the dataset if it is not found at root path. (Default: ``False``).
99
+ """
100
+
101
+ _ext_audio = ".wav"
102
+
103
+ def __init__(self, root: Union[str, Path], download: bool = False) -> None:
104
+ # Get string representation of 'root' in case Path object is passed
105
+ root = os.fspath(root)
106
+ self._path = os.path.join(root, "wav")
107
+ if not os.path.isdir(self._path):
108
+ if not download:
109
+ raise RuntimeError(
110
+ f"Dataset not found at {self._path}. Please set `download=True` to download the dataset."
111
+ )
112
+ _download_extract_wavs(root)
113
+
114
+ def get_metadata(self, n: int):
115
+ raise NotImplementedError
116
+
117
+ def __getitem__(self, n: int):
118
+ raise NotImplementedError
119
+
120
+ def __len__(self) -> int:
121
+ raise NotImplementedError
122
+
123
+
124
+ class VoxCeleb1Identification(VoxCeleb1):
125
+ """*VoxCeleb1* :cite:`nagrani2017voxceleb` dataset for speaker identification task.
126
+
127
+ Each data sample contains the waveform, sample rate, speaker id, and the file id.
128
+
129
+ Args:
130
+ root (str or Path): Path to the directory where the dataset is found or downloaded.
131
+ subset (str, optional): Subset of the dataset to use. Options: ["train", "dev", "test"]. (Default: ``"train"``)
132
+ meta_url (str, optional): The url of meta file that contains the list of subset labels and file paths.
133
+ The format of each row is ``subset file_path". For example: ``1 id10006/nLEBBc9oIFs/00003.wav``.
134
+ ``1``, ``2``, ``3`` mean ``train``, ``dev``, and ``test`` subest, respectively.
135
+ (Default: ``"https://www.robots.ox.ac.uk/~vgg/data/voxceleb/meta/iden_split.txt"``)
136
+ download (bool, optional):
137
+ Whether to download the dataset if it is not found at root path. (Default: ``False``).
138
+
139
+ Note:
140
+ The file structure of `VoxCeleb1Identification` dataset is as follows:
141
+
142
+ └─ root/
143
+
144
+ └─ wav/
145
+
146
+ └─ speaker_id folders
147
+
148
+ Users who pre-downloaded the ``"vox1_dev_wav.zip"`` and ``"vox1_test_wav.zip"`` files need to move
149
+ the extracted files into the same ``root`` directory.
150
+ """
151
+
152
+ def __init__(
153
+ self, root: Union[str, Path], subset: str = "train", meta_url: str = _IDEN_SPLIT_URL, download: bool = False
154
+ ) -> None:
155
+ super().__init__(root, download)
156
+ if subset not in ["train", "dev", "test"]:
157
+ raise ValueError("`subset` must be one of ['train', 'dev', 'test']")
158
+ # download the iden_split.txt to get the train, dev, test lists.
159
+ meta_list_path = os.path.join(root, os.path.basename(meta_url))
160
+ if not os.path.exists(meta_list_path):
161
+ download_url_to_file(meta_url, meta_list_path)
162
+ self._flist = _get_flist(self._path, meta_list_path, subset)
163
+
164
+ def get_metadata(self, n: int) -> Tuple[str, int, int, str]:
165
+ """Get metadata for the n-th sample from the dataset. Returns filepath instead of waveform,
166
+ but otherwise returns the same fields as :py:func:`__getitem__`.
167
+
168
+ Args:
169
+ n (int): The index of the sample
170
+
171
+ Returns:
172
+ Tuple of the following items;
173
+
174
+ str:
175
+ Path to audio
176
+ int:
177
+ Sample rate
178
+ int:
179
+ Speaker ID
180
+ str:
181
+ File ID
182
+ """
183
+ file_path = self._flist[n]
184
+ file_id = _get_file_id(file_path, self._ext_audio)
185
+ speaker_id = file_id.split("-")[0]
186
+ speaker_id = int(speaker_id[3:])
187
+ return file_path, SAMPLE_RATE, speaker_id, file_id
188
+
189
+ def __getitem__(self, n: int) -> Tuple[Tensor, int, int, str]:
190
+ """Load the n-th sample from the dataset.
191
+
192
+ Args:
193
+ n (int): The index of the sample to be loaded
194
+
195
+ Returns:
196
+ Tuple of the following items;
197
+
198
+ Tensor:
199
+ Waveform
200
+ int:
201
+ Sample rate
202
+ int:
203
+ Speaker ID
204
+ str:
205
+ File ID
206
+ """
207
+ metadata = self.get_metadata(n)
208
+ waveform = _load_waveform(self._path, metadata[0], metadata[1])
209
+ return (waveform,) + metadata[1:]
210
+
211
+ def __len__(self) -> int:
212
+ return len(self._flist)
213
+
214
+
215
+ class VoxCeleb1Verification(VoxCeleb1):
216
+ """*VoxCeleb1* :cite:`nagrani2017voxceleb` dataset for speaker verification task.
217
+
218
+ Each data sample contains a pair of waveforms, sample rate, the label indicating if they are
219
+ from the same speaker, and the file ids.
220
+
221
+ Args:
222
+ root (str or Path): Path to the directory where the dataset is found or downloaded.
223
+ meta_url (str, optional): The url of meta file that contains a list of utterance pairs
224
+ and the corresponding labels. The format of each row is ``label file_path1 file_path2".
225
+ For example: ``1 id10270/x6uYqmx31kE/00001.wav id10270/8jEAjG6SegY/00008.wav``.
226
+ ``1`` means the two utterances are from the same speaker, ``0`` means not.
227
+ (Default: ``"https://www.robots.ox.ac.uk/~vgg/data/voxceleb/meta/veri_test.txt"``)
228
+ download (bool, optional):
229
+ Whether to download the dataset if it is not found at root path. (Default: ``False``).
230
+
231
+ Note:
232
+ The file structure of `VoxCeleb1Verification` dataset is as follows:
233
+
234
+ └─ root/
235
+
236
+ └─ wav/
237
+
238
+ └─ speaker_id folders
239
+
240
+ Users who pre-downloaded the ``"vox1_dev_wav.zip"`` and ``"vox1_test_wav.zip"`` files need to move
241
+ the extracted files into the same ``root`` directory.
242
+ """
243
+
244
+ def __init__(self, root: Union[str, Path], meta_url: str = _VERI_TEST_URL, download: bool = False) -> None:
245
+ super().__init__(root, download)
246
+ # download the veri_test.txt to get the list of training pairs and labels.
247
+ meta_list_path = os.path.join(root, os.path.basename(meta_url))
248
+ if not os.path.exists(meta_list_path):
249
+ download_url_to_file(meta_url, meta_list_path)
250
+ self._flist = _get_paired_flist(self._path, meta_list_path)
251
+
252
+ def get_metadata(self, n: int) -> Tuple[str, str, int, int, str, str]:
253
+ """Get metadata for the n-th sample from the dataset. Returns filepaths instead of waveforms,
254
+ but otherwise returns the same fields as :py:func:`__getitem__`.
255
+
256
+ Args:
257
+ n (int): The index of the sample
258
+
259
+ Returns:
260
+ Tuple of the following items;
261
+
262
+ str:
263
+ Path to audio file of speaker 1
264
+ str:
265
+ Path to audio file of speaker 2
266
+ int:
267
+ Sample rate
268
+ int:
269
+ Label
270
+ str:
271
+ File ID of speaker 1
272
+ str:
273
+ File ID of speaker 2
274
+ """
275
+ label, file_path_spk1, file_path_spk2 = self._flist[n]
276
+ label = int(label)
277
+ file_id_spk1 = _get_file_id(file_path_spk1, self._ext_audio)
278
+ file_id_spk2 = _get_file_id(file_path_spk2, self._ext_audio)
279
+ return file_path_spk1, file_path_spk2, SAMPLE_RATE, label, file_id_spk1, file_id_spk2
280
+
281
+ def __getitem__(self, n: int) -> Tuple[Tensor, Tensor, int, int, str, str]:
282
+ """Load the n-th sample from the dataset.
283
+
284
+ Args:
285
+ n (int): The index of the sample to be loaded.
286
+
287
+ Returns:
288
+ Tuple of the following items;
289
+
290
+ Tensor:
291
+ Waveform of speaker 1
292
+ Tensor:
293
+ Waveform of speaker 2
294
+ int:
295
+ Sample rate
296
+ int:
297
+ Label
298
+ str:
299
+ File ID of speaker 1
300
+ str:
301
+ File ID of speaker 2
302
+ """
303
+ metadata = self.get_metadata(n)
304
+ waveform_spk1 = _load_waveform(self._path, metadata[0], metadata[2])
305
+ waveform_spk2 = _load_waveform(self._path, metadata[1], metadata[2])
306
+ return (waveform_spk1, waveform_spk2) + metadata[2:]
307
+
308
+ def __len__(self) -> int:
309
+ return len(self._flist)
@@ -0,0 +1,89 @@
1
+ import os
2
+ from pathlib import Path
3
+ from typing import List, Tuple, Union
4
+
5
+ import torchaudio
6
+ from torch import Tensor
7
+ from torch.utils.data import Dataset
8
+ from torchaudio._internal import download_url_to_file
9
+ from torchaudio.datasets.utils import _extract_tar
10
+
11
+
12
+ _RELEASE_CONFIGS = {
13
+ "release1": {
14
+ "folder_in_archive": "waves_yesno",
15
+ "url": "http://www.openslr.org/resources/1/waves_yesno.tar.gz",
16
+ "checksum": "c3f49e0cca421f96b75b41640749167b52118f232498667ca7a5f9416aef8e73",
17
+ }
18
+ }
19
+
20
+
21
+ class YESNO(Dataset):
22
+ """*YesNo* :cite:`YesNo` dataset.
23
+
24
+ Args:
25
+ root (str or Path): Path to the directory where the dataset is found or downloaded.
26
+ url (str, optional): The URL to download the dataset from.
27
+ (default: ``"http://www.openslr.org/resources/1/waves_yesno.tar.gz"``)
28
+ folder_in_archive (str, optional):
29
+ The top-level directory of the dataset. (default: ``"waves_yesno"``)
30
+ download (bool, optional):
31
+ Whether to download the dataset if it is not found at root path. (default: ``False``).
32
+ """
33
+
34
+ def __init__(
35
+ self,
36
+ root: Union[str, Path],
37
+ url: str = _RELEASE_CONFIGS["release1"]["url"],
38
+ folder_in_archive: str = _RELEASE_CONFIGS["release1"]["folder_in_archive"],
39
+ download: bool = False,
40
+ ) -> None:
41
+
42
+ self._parse_filesystem(root, url, folder_in_archive, download)
43
+
44
+ def _parse_filesystem(self, root: str, url: str, folder_in_archive: str, download: bool) -> None:
45
+ root = Path(root)
46
+ archive = os.path.basename(url)
47
+ archive = root / archive
48
+
49
+ self._path = root / folder_in_archive
50
+ if download:
51
+ if not os.path.isdir(self._path):
52
+ if not os.path.isfile(archive):
53
+ checksum = _RELEASE_CONFIGS["release1"]["checksum"]
54
+ download_url_to_file(url, archive, hash_prefix=checksum)
55
+ _extract_tar(archive)
56
+
57
+ if not os.path.isdir(self._path):
58
+ raise RuntimeError("Dataset not found. Please use `download=True` to download it.")
59
+
60
+ self._walker = sorted(str(p.stem) for p in Path(self._path).glob("*.wav"))
61
+
62
+ def _load_item(self, fileid: str, path: str):
63
+ labels = [int(c) for c in fileid.split("_")]
64
+ file_audio = os.path.join(path, fileid + ".wav")
65
+ waveform, sample_rate = torchaudio.load(file_audio)
66
+ return waveform, sample_rate, labels
67
+
68
+ def __getitem__(self, n: int) -> Tuple[Tensor, int, List[int]]:
69
+ """Load the n-th sample from the dataset.
70
+
71
+ Args:
72
+ n (int): The index of the sample to be loaded
73
+
74
+ Returns:
75
+ Tuple of the following items;
76
+
77
+ Tensor:
78
+ Waveform
79
+ int:
80
+ Sample rate
81
+ List[int]:
82
+ labels
83
+ """
84
+ fileid = self._walker[n]
85
+ item = self._load_item(fileid, self._path)
86
+ return item
87
+
88
+ def __len__(self) -> int:
89
+ return len(self._walker)