File size: 7,863 Bytes
90e5b44
 
 
 
43d362e
90e5b44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409619f
 
90e5b44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409619f
 
 
90e5b44
 
 
409619f
 
90e5b44
 
 
43d362e
 
 
409619f
0d05549
 
43d362e
0737faa
 
 
 
43d362e
 
409619f
53fb254
0d05549
409619f
 
 
 
0d05549
409619f
0d05549
 
 
c5a5c2a
0d05549
 
 
6a4563c
 
43d362e
0d05549
 
43d362e
409619f
43d362e
90e5b44
 
7f218dd
 
90e5b44
 
 
 
 
 
 
 
 
 
 
 
 
43d362e
409619f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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_and_extract({"train": _DL_URL.format(name=self.config.name)})
        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
        # visitedPaths = set()
        visitedAudios = {}
        visitedJsons = {}
        for path, f in archive_path:
            #print(f"key: {key}")
            #print(f"path: {path}")
            #print(f"visitedAudios: {visitedAudios}")
            #print(f"visitedJsons: {visitedJsons}")
            if path.endswith(".flac") or path.endswith(".json"):
                path_split = path.split("/")
                suffix = path[-5:]  # .flac or .json
                id = path.replace(suffix, "")
                if id not in visitedAudios or id not in visitedJsons:
                    # path_flac = id + ".flac"
                    # path_json = id + ".json"
                    # print(f"actual path: {path}")
                    # print(f"created path: {path_json}")
                    if suffix == ".json":
                        # with open(path_json) as json_file:
                        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,
            }
"""