# coding=utf-8 # Copyright 2021 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors. # # 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 # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Lint as: python3 """Libri-Light audio dataset.""" import glob import os import json 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_and_extract({"train": _DL_URL.format(name=self.config.name)}) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"archive_path": archive_path["train"]}, ), ] def _generate_examples(self, archive_path): paths = glob.glob(os.path.join(archive_path, self.config.name, "**", "**", "*.flac")) 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, }