Datasets:
Tasks:
Audio Classification
Sub-tasks:
keyword-spotting
Languages:
English
Size:
100K<n<1M
ArXiv:
License:
Delete loading script
Browse files- speech_commands.py +0 -229
speech_commands.py
DELETED
|
@@ -1,229 +0,0 @@
|
|
| 1 |
-
# coding=utf-8
|
| 2 |
-
# Copyright 2021 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 3 |
-
#
|
| 4 |
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
-
# you may not use this file except in compliance with the License.
|
| 6 |
-
# You may obtain a copy of the License at
|
| 7 |
-
#
|
| 8 |
-
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
-
#
|
| 10 |
-
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
-
# See the License for the specific language governing permissions and
|
| 14 |
-
# limitations under the License.
|
| 15 |
-
|
| 16 |
-
"""Speech Commands, an audio dataset of spoken words designed to help train and evaluate keyword spotting systems. """
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
import textwrap
|
| 20 |
-
|
| 21 |
-
import datasets
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
_CITATION = """
|
| 25 |
-
@article{speechcommandsv2,
|
| 26 |
-
author = { {Warden}, P.},
|
| 27 |
-
title = "{Speech Commands: A Dataset for Limited-Vocabulary Speech Recognition}",
|
| 28 |
-
journal = {ArXiv e-prints},
|
| 29 |
-
archivePrefix = "arXiv",
|
| 30 |
-
eprint = {1804.03209},
|
| 31 |
-
primaryClass = "cs.CL",
|
| 32 |
-
keywords = {Computer Science - Computation and Language, Computer Science - Human-Computer Interaction},
|
| 33 |
-
year = 2018,
|
| 34 |
-
month = apr,
|
| 35 |
-
url = {https://arxiv.org/abs/1804.03209},
|
| 36 |
-
}
|
| 37 |
-
"""
|
| 38 |
-
|
| 39 |
-
_DESCRIPTION = """
|
| 40 |
-
This is a set of one-second .wav audio files, each containing a single spoken
|
| 41 |
-
English word or background noise. These words are from a small set of commands, and are spoken by a
|
| 42 |
-
variety of different speakers. This data set is designed to help train simple
|
| 43 |
-
machine learning models. This dataset is covered in more detail at
|
| 44 |
-
[https://arxiv.org/abs/1804.03209](https://arxiv.org/abs/1804.03209).
|
| 45 |
-
|
| 46 |
-
Version 0.01 of the data set (configuration `"v0.01"`) was released on August 3rd 2017 and contains
|
| 47 |
-
64,727 audio files.
|
| 48 |
-
|
| 49 |
-
In version 0.01 thirty different words were recoded: "Yes", "No", "Up", "Down", "Left",
|
| 50 |
-
"Right", "On", "Off", "Stop", "Go", "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
|
| 51 |
-
"Bed", "Bird", "Cat", "Dog", "Happy", "House", "Marvin", "Sheila", "Tree", "Wow".
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
In version 0.02 more words were added: "Backward", "Forward", "Follow", "Learn", "Visual".
|
| 55 |
-
|
| 56 |
-
In both versions, ten of them are used as commands by convention: "Yes", "No", "Up", "Down", "Left",
|
| 57 |
-
"Right", "On", "Off", "Stop", "Go". Other words are considered to be auxiliary (in current implementation
|
| 58 |
-
it is marked by `True` value of `"is_unknown"` feature). Their function is to teach a model to distinguish core words
|
| 59 |
-
from unrecognized ones.
|
| 60 |
-
|
| 61 |
-
The `_silence_` class contains a set of longer audio clips that are either recordings or
|
| 62 |
-
a mathematical simulation of noise.
|
| 63 |
-
|
| 64 |
-
"""
|
| 65 |
-
|
| 66 |
-
_LICENSE = "Creative Commons BY 4.0 License"
|
| 67 |
-
|
| 68 |
-
_URL = "https://www.tensorflow.org/datasets/catalog/speech_commands"
|
| 69 |
-
|
| 70 |
-
_DL_URL = "https://s3.amazonaws.com/datasets.huggingface.co/SpeechCommands/{name}/{name}_{split}.tar.gz"
|
| 71 |
-
|
| 72 |
-
WORDS = [
|
| 73 |
-
"yes",
|
| 74 |
-
"no",
|
| 75 |
-
"up",
|
| 76 |
-
"down",
|
| 77 |
-
"left",
|
| 78 |
-
"right",
|
| 79 |
-
"on",
|
| 80 |
-
"off",
|
| 81 |
-
"stop",
|
| 82 |
-
"go",
|
| 83 |
-
]
|
| 84 |
-
|
| 85 |
-
UNKNOWN_WORDS_V1 = [
|
| 86 |
-
"zero",
|
| 87 |
-
"one",
|
| 88 |
-
"two",
|
| 89 |
-
"three",
|
| 90 |
-
"four",
|
| 91 |
-
"five",
|
| 92 |
-
"six",
|
| 93 |
-
"seven",
|
| 94 |
-
"eight",
|
| 95 |
-
"nine",
|
| 96 |
-
"bed",
|
| 97 |
-
"bird",
|
| 98 |
-
"cat",
|
| 99 |
-
"dog",
|
| 100 |
-
"happy",
|
| 101 |
-
"house",
|
| 102 |
-
"marvin",
|
| 103 |
-
"sheila",
|
| 104 |
-
"tree",
|
| 105 |
-
"wow",
|
| 106 |
-
]
|
| 107 |
-
|
| 108 |
-
UNKNOWN_WORDS_V2 = UNKNOWN_WORDS_V1 + [
|
| 109 |
-
"backward",
|
| 110 |
-
"forward",
|
| 111 |
-
"follow",
|
| 112 |
-
"learn",
|
| 113 |
-
"visual",
|
| 114 |
-
]
|
| 115 |
-
|
| 116 |
-
SILENCE = "_silence_" # background noise
|
| 117 |
-
LABELS_V1 = WORDS + UNKNOWN_WORDS_V1 + [SILENCE]
|
| 118 |
-
LABELS_V2 = WORDS + UNKNOWN_WORDS_V2 + [SILENCE]
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
class SpeechCommandsConfig(datasets.BuilderConfig):
|
| 122 |
-
"""BuilderConfig for SpeechCommands."""
|
| 123 |
-
|
| 124 |
-
def __init__(self, labels, **kwargs):
|
| 125 |
-
super(SpeechCommandsConfig, self).__init__(**kwargs)
|
| 126 |
-
self.labels = labels
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
class SpeechCommands(datasets.GeneratorBasedBuilder):
|
| 130 |
-
BUILDER_CONFIGS = [
|
| 131 |
-
SpeechCommandsConfig(
|
| 132 |
-
name="v0.01",
|
| 133 |
-
description=textwrap.dedent(
|
| 134 |
-
"""\
|
| 135 |
-
Version 0.01 of the SpeechCommands dataset. Contains 30 words
|
| 136 |
-
(20 of them are auxiliary) and background noise.
|
| 137 |
-
"""
|
| 138 |
-
),
|
| 139 |
-
labels=LABELS_V1,
|
| 140 |
-
version=datasets.Version("0.1.0"),
|
| 141 |
-
),
|
| 142 |
-
SpeechCommandsConfig(
|
| 143 |
-
name="v0.02",
|
| 144 |
-
description=textwrap.dedent(
|
| 145 |
-
"""\
|
| 146 |
-
Version 0.02 of the SpeechCommands dataset.
|
| 147 |
-
Contains 35 words (25 of them are auxiliary) and background noise.
|
| 148 |
-
"""
|
| 149 |
-
),
|
| 150 |
-
labels=LABELS_V2,
|
| 151 |
-
version=datasets.Version("0.2.0"),
|
| 152 |
-
),
|
| 153 |
-
]
|
| 154 |
-
|
| 155 |
-
def _info(self):
|
| 156 |
-
return datasets.DatasetInfo(
|
| 157 |
-
description=_DESCRIPTION,
|
| 158 |
-
features=datasets.Features(
|
| 159 |
-
{
|
| 160 |
-
"file": datasets.Value("string"),
|
| 161 |
-
"audio": datasets.features.Audio(sampling_rate=16_000),
|
| 162 |
-
"label": datasets.ClassLabel(names=self.config.labels),
|
| 163 |
-
"is_unknown": datasets.Value("bool"),
|
| 164 |
-
"speaker_id": datasets.Value("string"),
|
| 165 |
-
"utterance_id": datasets.Value("int8"),
|
| 166 |
-
}
|
| 167 |
-
),
|
| 168 |
-
homepage=_URL,
|
| 169 |
-
citation=_CITATION,
|
| 170 |
-
license=_LICENSE,
|
| 171 |
-
version=self.config.version,
|
| 172 |
-
)
|
| 173 |
-
|
| 174 |
-
def _split_generators(self, dl_manager):
|
| 175 |
-
|
| 176 |
-
archive_paths = dl_manager.download(
|
| 177 |
-
{
|
| 178 |
-
"train": _DL_URL.format(name=self.config.name, split="train"),
|
| 179 |
-
"validation": _DL_URL.format(name=self.config.name, split="validation"),
|
| 180 |
-
"test": _DL_URL.format(name=self.config.name, split="test"),
|
| 181 |
-
}
|
| 182 |
-
)
|
| 183 |
-
|
| 184 |
-
return [
|
| 185 |
-
datasets.SplitGenerator(
|
| 186 |
-
name=datasets.Split.TRAIN,
|
| 187 |
-
gen_kwargs={
|
| 188 |
-
"archive": dl_manager.iter_archive(archive_paths["train"]),
|
| 189 |
-
},
|
| 190 |
-
),
|
| 191 |
-
datasets.SplitGenerator(
|
| 192 |
-
name=datasets.Split.VALIDATION,
|
| 193 |
-
gen_kwargs={
|
| 194 |
-
"archive": dl_manager.iter_archive(archive_paths["validation"]),
|
| 195 |
-
},
|
| 196 |
-
),
|
| 197 |
-
datasets.SplitGenerator(
|
| 198 |
-
name=datasets.Split.TEST,
|
| 199 |
-
gen_kwargs={
|
| 200 |
-
"archive": dl_manager.iter_archive(archive_paths["test"]),
|
| 201 |
-
},
|
| 202 |
-
),
|
| 203 |
-
]
|
| 204 |
-
|
| 205 |
-
def _generate_examples(self, archive):
|
| 206 |
-
for path, file in archive:
|
| 207 |
-
if not path.endswith(".wav"):
|
| 208 |
-
continue
|
| 209 |
-
|
| 210 |
-
word, audio_filename = path.split("/")
|
| 211 |
-
is_unknown = False
|
| 212 |
-
|
| 213 |
-
if word == SILENCE:
|
| 214 |
-
speaker_id, utterance_id = None, 0
|
| 215 |
-
|
| 216 |
-
else: # word is either in WORDS or unknown
|
| 217 |
-
if word not in WORDS:
|
| 218 |
-
is_unknown = True
|
| 219 |
-
# an audio filename looks like `0bac8a71_nohash_0.wav`
|
| 220 |
-
speaker_id, _, utterance_id = audio_filename.split(".wav")[0].split("_")
|
| 221 |
-
|
| 222 |
-
yield path, {
|
| 223 |
-
"file": path,
|
| 224 |
-
"audio": {"path": path, "bytes": file.read()},
|
| 225 |
-
"label": word,
|
| 226 |
-
"is_unknown": is_unknown,
|
| 227 |
-
"speaker_id": speaker_id,
|
| 228 |
-
"utterance_id": utterance_id,
|
| 229 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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