|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import json |
|
|
|
import datasets |
|
from datasets.tasks import AutomaticSpeechRecognition |
|
from tqdm.auto import tqdm |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@article{DBLP:journals/corr/abs-2111-09344, |
|
author = {Daniel Galvez and |
|
Greg Diamos and |
|
Juan Ciro and |
|
Juan Felipe Ceron and |
|
Keith Achorn and |
|
Anjali Gopi and |
|
David Kanter and |
|
Maximilian Lam and |
|
Mark Mazumder and |
|
Vijay Janapa Reddi}, |
|
title = {The People's Speech: A Large-Scale Diverse English Speech Recognition |
|
Dataset for Commercial Usage}, |
|
journal = {CoRR}, |
|
volume = {abs/2111.09344}, |
|
year = {2021}, |
|
url = {https://arxiv.org/abs/2111.09344}, |
|
eprinttype = {arXiv}, |
|
eprint = {2111.09344}, |
|
timestamp = {Mon, 22 Nov 2021 16:44:07 +0100}, |
|
biburl = {https://dblp.org/rec/journals/corr/abs-2111-09344.bib}, |
|
bibsource = {dblp computer science bibliography, https://dblp.org} |
|
} |
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
The People's Speech is a free-to-download 30,000-hour and growing supervised |
|
conversational English speech recognition dataset licensed for academic and |
|
commercial usage under CC-BY-SA (with a CC-BY subset). |
|
""" |
|
|
|
_HOMEPAGE = "https://mlcommons.org/en/peoples-speech/" |
|
|
|
_LICENSE = [ |
|
"cc-by-2.0", "cc-by-2.5", "cc-by-3.0", "cc-by-4.0", "cc-by-sa-2.5", |
|
"cc-by-sa-3.0", "cc-by-sa-4.0" |
|
] |
|
|
|
|
|
|
|
|
|
_URLS = { |
|
"clean-cc-by": { |
|
"audio_tar": "", |
|
"manifest": "", |
|
}, |
|
"dirty-cc-by": { |
|
"audio_tar": "", |
|
"manifest": "", |
|
}, |
|
"clean-cc-by-sa": { |
|
"audio_tar": "", |
|
"manifest": "", |
|
}, |
|
"dirty-cc-by-sa": { |
|
"audio_tar": "", |
|
"manifest": "", |
|
}, |
|
"microset": { |
|
"audio_tar": "", |
|
"manifest": "", |
|
}, |
|
} |
|
|
|
|
|
|
|
|
|
_DATA_URL = "{config}/{config}_00000{archive_id}.tar" |
|
|
|
|
|
_MANIFEST_URL = "{config}.json" |
|
|
|
|
|
class PeoplesSpeech(datasets.GeneratorBasedBuilder): |
|
"""The People's Speech dataset.""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="clean", version=VERSION, description="Clean, CC-BY licensed subset."), |
|
datasets.BuilderConfig(name="dirty", version=VERSION, description="Dirty, CC-BY licensed subset."), |
|
datasets.BuilderConfig(name="clean_sa", version=VERSION, description="Clean, CC-BY-SA licensed subset."), |
|
datasets.BuilderConfig(name="dirty_sa", version=VERSION, description="Dirty, CC-BY-SA licensed subset."), |
|
] |
|
DEFAULT_CONFIG_NAME = "clean" |
|
DEFAULT_WRITER_BATCH_SIZE = 1 |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"audio": datasets.Audio(sampling_rate=16_000), |
|
"duration_ms": datasets.Value("int32"), |
|
"text": datasets.Value("string"), |
|
} |
|
), |
|
task_templates=[AutomaticSpeechRecognition()], |
|
supervised_keys=("file", "text"), |
|
homepage=_HOMEPAGE, |
|
license="/".join(_LICENSE), |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
|
|
urls = [_DATA_URL.format(config=self.config.name, archive_id=i) for i in range(5)] |
|
archives = [dl_manager.iter_archive(dl_manager.download(url)) for url in urls] |
|
|
|
manifest_url = _MANIFEST_URL.format(config=self.config.name) |
|
manifest_path = dl_manager.download_and_extract(manifest_url) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"archives": archives, |
|
"manifest_path": manifest_path |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, archives, manifest_path): |
|
meta = dict() |
|
with open(manifest_path, "r", encoding="utf-8") as f: |
|
for line in tqdm(f, desc="reading metadata file"): |
|
sample_meta = json.loads(line) |
|
_id = sample_meta["audio_document_id"] |
|
texts = sample_meta["training_data"]["label"] |
|
audio_filenames = sample_meta["training_data"]["name"] |
|
durations = sample_meta["training_data"]["duration_ms"] |
|
for audio_filename, text, duration in zip(audio_filenames, texts, durations): |
|
meta[audio_filename] = { |
|
"audio_document_id": _id, |
|
"text": text, |
|
"duration_ms": duration |
|
} |
|
|
|
print("generating examples") |
|
for archive in archives: |
|
|
|
|
|
for audio_filename, audio_file in archive: |
|
yield audio_filename, { |
|
"id": audio_filename, |
|
"audio": {"path": audio_filename, "bytes": audio_file.read()}, |
|
"text": meta[audio_filename]["text"], |
|
"duration_ms": meta[audio_filename]["duration_ms"] |
|
} |
|
|