|
import glob |
|
import os |
|
|
|
import json |
|
import torchaudio |
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@INPROCEEDINGS{librilight, |
|
author={J. Kahn and M. Rivière and W. Zheng and E. Kharitonov and Q. Xu and P. E. Mazaré and J. Karadayi and V. Liptchinsky and R. Collobert and C. Fuegen and T. Likhomanenko and G. Synnaeve and A. Joulin and A. Mohamed and E. Dupoux}, |
|
booktitle={ICASSP 2020 - 2020 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP)}, |
|
title={Libri-Light: A Benchmark for ASR with Limited or No Supervision}, |
|
year={2020}, |
|
pages={7669-7673}, |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
Libri-light is a large dataset of 60K hours of unlabelled speech from audiobooks in English. |
|
It is a benchmark for the training of automatic speech recognition (ASR) systems with limited or no supervision. |
|
""" |
|
|
|
_HOMEPAGE = "https://ai.facebook.com/tools/libri-light/" |
|
|
|
_LICENSE = """\ |
|
MIT License |
|
Copyright (c) Facebook, Inc. and its affiliates. |
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
|
of this software and associated documentation files (the "Software"), to deal |
|
in the Software without restriction, including without limitation the rights |
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
copies of the Software, and to permit persons to whom the Software is |
|
furnished to do so, subject to the following conditions: |
|
The above copyright notice and this permission notice shall be included in all |
|
copies or substantial portions of the Software. |
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
SOFTWARE. |
|
""" |
|
|
|
_DL_URL = "https://dl.fbaipublicfiles.com/librilight/data/{name}.tar" |
|
|
|
|
|
class LibriLightConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for Libri-Light.""" |
|
|
|
def __init__(self, **kwargs): |
|
super(LibriLightConfig, self).__init__( |
|
version=datasets.Version("2.1.0", ""), **kwargs) |
|
|
|
|
|
class LibriLight(datasets.GeneratorBasedBuilder): |
|
"""Libri-Light dataset.""" |
|
|
|
BUILDER_CONFIGS = [ |
|
LibriLightConfig(name="small", description="577 hours, 35 GB."), |
|
LibriLightConfig(name="medium", description="5193 hours, 321 GB."), |
|
LibriLightConfig(name="large", description="51934 hours, 3.05 TB."), |
|
] |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("string"), |
|
"file": datasets.Value("string"), |
|
"audio": datasets.Audio(sampling_rate=16_000), |
|
"speaker_id": datasets.Value("int64"), |
|
"metadata": { |
|
"speaker": datasets.Value("string"), |
|
"book_meta": { |
|
"id": datasets.Value("string"), |
|
"title": datasets.Value("string"), |
|
"description": datasets.Value("string"), |
|
"url_text_source": datasets.Value("string"), |
|
"language": datasets.Value("string"), |
|
"copyright_year": datasets.Value("string"), |
|
"num_sections": datasets.Value("string"), |
|
"url_rss": datasets.Value("string"), |
|
"url_zip_file": datasets.Value("string"), |
|
"url_project": datasets.Value("string"), |
|
"url_librivox": datasets.Value("string"), |
|
"url_other": datasets.Value("string"), |
|
"totaltimesecs": datasets.Value("int64"), |
|
"authors": datasets.Sequence( |
|
{ |
|
"id": datasets.Value("string"), |
|
"first_name": datasets.Value("string"), |
|
"last_name": datasets.Value("string"), |
|
"dob": datasets.Value("string"), |
|
"dod": datasets.Value("string") |
|
} |
|
), |
|
"genre": datasets.Sequence(datasets.Value("string")), |
|
"Dramatic Readings": datasets.Value("bool"), |
|
"meta_genre": datasets.Value("string"), |
|
}, |
|
"snr": datasets.Value("float32"), |
|
"voice_activity": datasets.Sequence(datasets.Sequence(datasets.Value("float32"))), |
|
} |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
archive_path = dl_manager.download( |
|
_DL_URL.format(name=self.config.name)) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"archive_path": dl_manager.iter_archive(archive_path)}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, archive_path): |
|
"""Generate examples from a LibriLight archive_path.""" |
|
key = 0 |
|
|
|
visitedAudios = {} |
|
visitedJsons = {} |
|
for path, f in archive_path: |
|
|
|
|
|
|
|
|
|
if path.endswith(".flac") or path.endswith(".json"): |
|
path_split = path.split("/") |
|
suffix = path[-5:] |
|
id = path.replace(suffix, "") |
|
if id not in visitedAudios or id not in visitedJsons: |
|
|
|
|
|
|
|
|
|
if suffix == ".json": |
|
|
|
metadata = json.load(f) |
|
visitedJsons[id] = metadata |
|
elif suffix == ".flac": |
|
audioData = f.read() |
|
visitedAudios[id] = audioData |
|
|
|
if id in visitedAudios and id in visitedJsons: |
|
speaker_id = int(path_split[-3]) |
|
yield key, {"id": id, "file": path, "audio": visitedAudios[id], "speaker_id": speaker_id, "metadata": visitedJsons[id]} |
|
key += 1 |
|
del visitedAudios[id] |
|
del visitedJsons[id] |
|
|
|
|
|
""" |
|
def _generate_examples(self, archive_path): |
|
paths = glob.glob(os.path.join(archive_path, "small", "**", "**", "*.flac")) |
|
print(f"archive_path in glob: {archive_path}") |
|
print(f"paths: {paths}") |
|
for key, path in enumerate(paths): |
|
path_split = path.split("/") |
|
id_ = path_split[-1].replace(".flac", "") |
|
speaker_id = int(path_split[-3]) |
|
path_json = path.replace(".flac", ".json") |
|
with open(path_json) as json_file: |
|
metadata = json.load(json_file) |
|
yield key, { |
|
"id": id_, |
|
"file": path, |
|
"audio": path, |
|
"speaker_id": speaker_id, |
|
"metadata": metadata, |
|
} |
|
""" |
|
|