Datasets:
shadow-wxh
commited on
Commit
•
8aa388d
1
Parent(s):
4287797
Upload 5 files
Browse files- count_n_shards.py +22 -0
- languages.py +1 -0
- n_shards.json +14 -0
- release_stats.py +1 -0
- voice_command_audio_1_0.py +196 -0
count_n_shards.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
import json
|
3 |
+
|
4 |
+
|
5 |
+
splits = ["train", "test"]
|
6 |
+
|
7 |
+
if __name__ == "__main__":
|
8 |
+
n_files = {}
|
9 |
+
lang_dirs = [d for d in Path("audio").iterdir() if d.is_dir()]
|
10 |
+
for lang_dir in lang_dirs:
|
11 |
+
lang = lang_dir.name
|
12 |
+
n_files[lang] = {}
|
13 |
+
for split in splits:
|
14 |
+
split_dir = lang_dir / split
|
15 |
+
if split_dir.exists():
|
16 |
+
n_files_per_split = len(list(split_dir.glob("*.tar")))
|
17 |
+
else:
|
18 |
+
n_files_per_split = 0
|
19 |
+
n_files[lang][split] = n_files_per_split
|
20 |
+
|
21 |
+
with open("n_shards.json", "w") as f:
|
22 |
+
json.dump(dict(sorted(n_files.items(), key=lambda x: x[0])), f, ensure_ascii=False, indent=4)
|
languages.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
LANGUAGES = {'de': 'German', 'en': 'English', 'zh-CN': 'Chinese (China)'}
|
n_shards.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"de": {
|
3 |
+
"train": 1,
|
4 |
+
"test": 1
|
5 |
+
},
|
6 |
+
"en": {
|
7 |
+
"train": 1,
|
8 |
+
"test": 1
|
9 |
+
},
|
10 |
+
"zh-CN": {
|
11 |
+
"train": 1,
|
12 |
+
"test": 1
|
13 |
+
}
|
14 |
+
}
|
release_stats.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
STATS = {'bundleURLTemplate': 'vca-1.0-2024-07-25/vca-1.0-2024-07-25-{locale}.tar.gz', 'date': '2024-07-25', 'name': 'Voice Command Audio 1.0', 'multilingual': True, 'locales': {'de': {'buckets': {'test': 0, 'train': 0}, 'reportedSentences':0, 'duration': 0, 'clips': 0, 'splits': {'accent': {'': 1}, 'age': {'thirties': 1}, 'gender': {'male': 1}}, 'users': 1, 'size': 0, 'checksum': '94a0c7aeb0d18a280380e5a568d21251ed421f093bc164c9f67d8b28dfbecaaf', 'avgDurationSecs': 0, 'validDurationSecs': 0, 'totalHrs': 0, 'validHrs': 0}, 'en': { 'buckets': {'test': 0, 'train': 0}, 'reportedSentences': 0, 'duration': 0,'clips': 0, 'splits': {'accent': {'': 1}, 'age': {'thirties': 1}, 'gender': {'male': 1}}, 'users': 1, 'size': 0, 'checksum': '0efd86ca6b40641b55d1411b7d3b1f1ab8626de4b207504953706df201d198a5', 'avgDurationSecs': 0, 'validDurationSecs': 0, 'totalHrs': 0, 'validHrs': 0}, 'zh-CN': {'buckets': {'test': 0, 'train': 0}, 'reportedSentences': 0, 'duration': 0, 'clips': 0, 'splits': {'accent': {'': 1}, 'age': {'thirties': 1}, 'gender': {'male': 1}}, 'users': 1, 'size': 0, 'checksum': 'd1168d8cf2fd2654fa74056f3b7a0ade9ccb46777efb52d27ccf4d3b3a1841c5', 'avgDurationSecs': 0, 'validDurationSecs': 0, 'totalHrs': 0, 'validHrs': 0}}, 'totalDuration': 0, 'totalValidDurationSecs': 0, 'totalHrs': 0, 'totalValidHrs': 0, 'version': '1.0'}
|
voice_command_audio_1_0.py
ADDED
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2024 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
+
#
|
4 |
+
# Licensed under the MIT License (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 |
+
# https://mit-license.org/
|
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 |
+
""" Voice Command Audio Dataset"""
|
16 |
+
|
17 |
+
|
18 |
+
import csv
|
19 |
+
import os
|
20 |
+
import json
|
21 |
+
|
22 |
+
import datasets
|
23 |
+
from datasets.utils.py_utils import size_str
|
24 |
+
from tqdm import tqdm
|
25 |
+
|
26 |
+
from .languages import LANGUAGES
|
27 |
+
from .release_stats import STATS
|
28 |
+
|
29 |
+
|
30 |
+
_CITATION = """\
|
31 |
+
@inproceedings{none,
|
32 |
+
author = {shaodw_wxh},
|
33 |
+
title = {Voice Command: A General Purpose Speech Reconginition Gaming Interface},
|
34 |
+
booktitle = {},
|
35 |
+
pages = {1-10},
|
36 |
+
year = 2024
|
37 |
+
}
|
38 |
+
"""
|
39 |
+
|
40 |
+
_HOMEPAGE = "https://www.shadow_wxh.org/"
|
41 |
+
|
42 |
+
_LICENSE = "https://mit-license.org/"
|
43 |
+
|
44 |
+
# TODO: change "streaming" to "main" after merge!
|
45 |
+
_BASE_URL = "https://huggingface.co/datasets/shadow-wxh/VoiceCommandAudio/resolve/main/"
|
46 |
+
|
47 |
+
_AUDIO_URL = _BASE_URL + "audio/{lang}/{split}/{lang}_{split}_{shard_idx}.tar"
|
48 |
+
|
49 |
+
_TRANSCRIPT_URL = _BASE_URL + "transcript/{lang}/{split}.tsv"
|
50 |
+
|
51 |
+
_N_SHARDS_URL = _BASE_URL + "n_shards.json"
|
52 |
+
|
53 |
+
|
54 |
+
class CommonVoiceConfig(datasets.BuilderConfig):
|
55 |
+
"""BuilderConfig for Voice Command Audio."""
|
56 |
+
|
57 |
+
def __init__(self, name, version, **kwargs):
|
58 |
+
self.language = kwargs.pop("language", None)
|
59 |
+
self.release_date = kwargs.pop("release_date", None)
|
60 |
+
self.num_clips = kwargs.pop("num_clips", None)
|
61 |
+
self.num_speakers = kwargs.pop("num_speakers", None)
|
62 |
+
self.validated_hr = kwargs.pop("validated_hr", None)
|
63 |
+
self.total_hr = kwargs.pop("total_hr", None)
|
64 |
+
self.size_bytes = kwargs.pop("size_bytes", None)
|
65 |
+
self.size_human = size_str(self.size_bytes)
|
66 |
+
description = (
|
67 |
+
f"Voice Command Audio dataset in {self.language} released on {self.release_date}. "
|
68 |
+
f"The dataset comprises {self.validated_hr} hours of validated transcribed speech data "
|
69 |
+
f"out of {self.total_hr} hours in total from {self.num_speakers} speakers. "
|
70 |
+
f"The dataset contains {self.num_clips} audio clips and has a size of {self.size_human}."
|
71 |
+
)
|
72 |
+
super(CommonVoiceConfig, self).__init__(
|
73 |
+
name=name,
|
74 |
+
version=datasets.Version(version),
|
75 |
+
description=description,
|
76 |
+
**kwargs,
|
77 |
+
)
|
78 |
+
|
79 |
+
|
80 |
+
class CommonVoice(datasets.GeneratorBasedBuilder):
|
81 |
+
DEFAULT_WRITER_BATCH_SIZE = 1000
|
82 |
+
|
83 |
+
BUILDER_CONFIGS = [
|
84 |
+
CommonVoiceConfig(
|
85 |
+
name=lang,
|
86 |
+
version=STATS["version"],
|
87 |
+
language=LANGUAGES[lang],
|
88 |
+
release_date=STATS["date"],
|
89 |
+
num_clips=lang_stats["clips"],
|
90 |
+
num_speakers=lang_stats["users"],
|
91 |
+
validated_hr=float(lang_stats["validHrs"]) if lang_stats["validHrs"] else None,
|
92 |
+
total_hr=float(lang_stats["totalHrs"]) if lang_stats["totalHrs"] else None,
|
93 |
+
size_bytes=int(lang_stats["size"]) if lang_stats["size"] else None,
|
94 |
+
)
|
95 |
+
for lang, lang_stats in STATS["locales"].items()
|
96 |
+
]
|
97 |
+
|
98 |
+
def _info(self):
|
99 |
+
total_languages = len(STATS["locales"])
|
100 |
+
total_valid_hours = STATS["totalValidHrs"]
|
101 |
+
description = (
|
102 |
+
"Voice Command Audio is a dataset to help fine tune Voice Command a geral purpose speech recongnition gaming interface. "
|
103 |
+
f"The dataset currently consists of {total_valid_hours} validated hours of speech "
|
104 |
+
f" in {total_languages} languages, but more voices and languages are always added."
|
105 |
+
)
|
106 |
+
features = datasets.Features(
|
107 |
+
{
|
108 |
+
"client_id": datasets.Value("string"),
|
109 |
+
"path": datasets.Value("string"),
|
110 |
+
"audio": datasets.features.Audio(sampling_rate=16_000),
|
111 |
+
"sentence": datasets.Value("string"),
|
112 |
+
"up_votes": datasets.Value("int64"),
|
113 |
+
"down_votes": datasets.Value("int64"),
|
114 |
+
"age": datasets.Value("string"),
|
115 |
+
"gender": datasets.Value("string"),
|
116 |
+
"accent": datasets.Value("string"),
|
117 |
+
"locale": datasets.Value("string"),
|
118 |
+
"segment": datasets.Value("string"),
|
119 |
+
}
|
120 |
+
)
|
121 |
+
|
122 |
+
return datasets.DatasetInfo(
|
123 |
+
description=description,
|
124 |
+
features=features,
|
125 |
+
supervised_keys=None,
|
126 |
+
homepage=_HOMEPAGE,
|
127 |
+
license=_LICENSE,
|
128 |
+
citation=_CITATION,
|
129 |
+
version=self.config.version,
|
130 |
+
)
|
131 |
+
|
132 |
+
def _split_generators(self, dl_manager):
|
133 |
+
lang = self.config.name
|
134 |
+
n_shards_path = dl_manager.download_and_extract(_N_SHARDS_URL)
|
135 |
+
with open(n_shards_path, encoding="utf-8") as f:
|
136 |
+
n_shards = json.load(f)
|
137 |
+
|
138 |
+
audio_urls = {}
|
139 |
+
splits = ("train", "test")
|
140 |
+
for split in splits:
|
141 |
+
audio_urls[split] = [
|
142 |
+
_AUDIO_URL.format(lang=lang, split=split, shard_idx=i) for i in range(n_shards[lang][split])
|
143 |
+
]
|
144 |
+
archive_paths = dl_manager.download(audio_urls)
|
145 |
+
local_extracted_archive_paths = dl_manager.extract(archive_paths) if not dl_manager.is_streaming else {}
|
146 |
+
|
147 |
+
meta_urls = {split: _TRANSCRIPT_URL.format(lang=lang, split=split) for split in splits}
|
148 |
+
meta_paths = dl_manager.download_and_extract(meta_urls)
|
149 |
+
|
150 |
+
split_generators = []
|
151 |
+
split_names = {
|
152 |
+
"train": datasets.Split.TRAIN,
|
153 |
+
"test": datasets.Split.TEST,
|
154 |
+
}
|
155 |
+
for split in splits:
|
156 |
+
split_generators.append(
|
157 |
+
datasets.SplitGenerator(
|
158 |
+
name=split_names.get(split, split),
|
159 |
+
gen_kwargs={
|
160 |
+
"local_extracted_archive_paths": local_extracted_archive_paths.get(split),
|
161 |
+
"archives": [dl_manager.iter_archive(path) for path in archive_paths.get(split)],
|
162 |
+
"meta_path": meta_paths[split],
|
163 |
+
},
|
164 |
+
),
|
165 |
+
)
|
166 |
+
|
167 |
+
return split_generators
|
168 |
+
|
169 |
+
def _generate_examples(self, local_extracted_archive_paths, archives, meta_path):
|
170 |
+
data_fields = list(self._info().features.keys())
|
171 |
+
metadata = {}
|
172 |
+
with open(meta_path, encoding="utf-8") as f:
|
173 |
+
reader = csv.DictReader(f, delimiter="\t", quoting=csv.QUOTE_NONE)
|
174 |
+
for row in tqdm(reader, desc="Reading metadata..."):
|
175 |
+
if not row["path"].endswith(".wav"):
|
176 |
+
row["path"] += ".wav"
|
177 |
+
# accent -> accents in CV 8.0
|
178 |
+
if "accents" in row:
|
179 |
+
row["accent"] = row["accents"]
|
180 |
+
del row["accents"]
|
181 |
+
# if data is incomplete, fill with empty values
|
182 |
+
for field in data_fields:
|
183 |
+
if field not in row:
|
184 |
+
row[field] = ""
|
185 |
+
metadata[row["path"]] = row
|
186 |
+
|
187 |
+
for i, audio_archive in enumerate(archives):
|
188 |
+
for path, file in audio_archive:
|
189 |
+
_, filename = os.path.split(path)
|
190 |
+
if filename in metadata:
|
191 |
+
result = dict(metadata[filename])
|
192 |
+
# set the audio feature and the path to the extracted file
|
193 |
+
path = os.path.join(local_extracted_archive_paths[i], path) if local_extracted_archive_paths else path
|
194 |
+
result["audio"] = {"path": path, "bytes": file.read()}
|
195 |
+
result["path"] = path
|
196 |
+
yield path, result
|