peoples_speech_v1.0 /
polinaeterna's picture
polinaeterna HF staff
specify paths to all archives
raw history blame
No virus
7.44 kB
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import os
import datasets
from datasets.tasks import AutomaticSpeechRecognition
from import tqdm
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """\
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 = {},
eprinttype = {arXiv},
eprint = {2111.09344},
timestamp = {Mon, 22 Nov 2021 16:44:07 +0100},
biburl = {},
bibsource = {dblp computer science bibliography,}
# You can copy an official 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).
"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"
# relative path to data inside dataset's repo
_DATA_URL = "train/{config}/{config}_{archive_id:06d}.tar"
# relative path to file containing number of audio archives inside dataset's repo
_N_FILES_URL = "train/{config}/n_files.txt"
# relative path to metadata inside dataset's repo
_MANIFEST_URL = "train/{config}.json"
class PeoplesSpeech(datasets.GeneratorBasedBuilder):
"""The People's Speech dataset."""
VERSION = datasets.Version("1.1.0")
# TODO: add "subset" config
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."),
def _info(self):
return datasets.DatasetInfo(
"id": datasets.Value("string"),
"audio": datasets.Audio(sampling_rate=16_000),
"duration_ms": datasets.Value("int32"),
"text": datasets.Value("string"),
supervised_keys=("file", "text"),
license="/".join(_LICENSE), # license must be a string
def _split_generators(self, dl_manager):
n_files_url = _N_FILES_URL.format(
n_files_path = dl_manager.download_and_extract(n_files_url)
with open(n_files_path, encoding="utf-8") as f:
n_files = int(
urls = [_DATA_URL.format(, archive_id=i) for i in range(n_files)]
archive_paths = [ for url in urls]
# In non-streaming mode, we extract the archives to have the data locally:
local_extracted_archive_paths = [dl_manager.extract(path) for path in archive_paths] \
if not dl_manager.is_streaming else [None] * len(archive_paths)
manifest_url = _MANIFEST_URL.format(
manifest_path = dl_manager.download_and_extract(manifest_url)
# To access the audio data from the TAR archives using the download manager,
# we have to use the dl_manager.iter_archive method
# This is because dl_manager.download_and_extract
# doesn't work to stream TAR archives in streaming mode.
# (we have to stream the files of a TAR archive one by one)
# The iter_archive method returns an iterable of (path_within_archive, file_obj) for every
# file in a TAR archive.
return [
"local_extracted_archive_paths": local_extracted_archive_paths,
# use iter_archive here to access the files in the TAR archives:
"archives": [dl_manager.iter_archive(path) for path in archive_paths],
"manifest_path": manifest_path,
def _generate_examples(self, local_extracted_archive_paths, 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
for local_extracted_archive_path, archive in zip(local_extracted_archive_paths, archives):
# Here we iterate over all the files within the TAR archive:
for audio_filename, audio_file in archive:
# if an audio file exists locally (i.e. in default, non-streaming mode) set the full path to it
# joining path to directory that the archive was extracted to and audio filename.
path = os.path.join(local_extracted_archive_path, audio_filename) if local_extracted_archive_path \
else audio_filename
yield audio_filename, {
"id": audio_filename,
"audio": {"path": path, "bytes":},
"text": meta[audio_filename]["text"],
"duration_ms": meta[audio_filename]["duration_ms"]