File size: 4,078 Bytes
dca3754
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd48917
dca3754
6a4ecbb
0ee7fb5
dca3754
 
 
 
 
 
7052c88
dca3754
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29c035b
dca3754
 
 
 
 
 
 
7052c88
dca3754
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36e6665
7052c88
dca3754
e66f06c
dca3754
f219a93
7052c88
dca3754
 
 
 
 
f6d2989
dca3754
 
7094add
dca3754
969b9a0
5719d18
b4bb17d
 
 
 
 
dca3754
 
 
9cdc9d1
dca3754
9cdc9d1
 
dca3754
 
 
 
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
# coding=utf-8
# Lint as: python3
"""test set"""


import csv
import os
import json

import datasets
from datasets.utils.py_utils import size_str
from tqdm import tqdm


_CITATION = """\
@inproceedings{panayotov2015librispeech,
  title={Librispeech: an ASR corpus based on public domain audio books},
  author={Panayotov, Vassil and Chen, Guoguo and Povey, Daniel and Khudanpur, Sanjeev},
  booktitle={Acoustics, Speech and Signal Processing (ICASSP), 2015 IEEE International Conference on},
  pages={5206--5210},
  year={2015},
  organization={IEEE}
}
"""

_DESCRIPTION = """\
Lorem ipsum
"""


_BASE_URL = "https://huggingface.co/datasets/j-krzywdziak/test/tree/main"
_DATA_URL = "https://huggingface.co/datasets/j-krzywdziak/test/blob/main/dev.tar"
_PROMPTS_URLS = {"test": "https://huggingface.co/datasets/j-krzywdziak/test/raw/main/dev.tsv"}

logger = datasets.logging.get_logger(__name__)

class TestConfig(datasets.BuilderConfig):
    """Lorem impsum."""

    def __init__(self, name, **kwargs):
        # self.language = kwargs.pop("language", None)
        # self.release_date = kwargs.pop("release_date", None)
        # self.num_clips = kwargs.pop("num_clips", None)
        # self.num_speakers = kwargs.pop("num_speakers", None)
        # self.validated_hr = kwargs.pop("validated_hr", None)
        # self.total_hr = kwargs.pop("total_hr", None)
        # self.size_bytes = kwargs.pop("size_bytes", None)
        # self.size_human = size_str(self.size_bytes)
        description = (
            f"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor "
            f"incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud "
            f"exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure "
            f"dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. "
            f"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
            f"mollit anim id est laborum."
        )
        super(TestConfig, self).__init__(
            name=name,
            description=description,
            **kwargs,
        )

class TestASR(datasets.GeneratorBasedBuilder):
    """Lorem ipsum."""


    BUILDER_CONFIGS = [
        TestConfig(
            name="Test Dataset",
        )
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "audio_id": datasets.Value("string"),
                    "audio": datasets.Audio(sampling_rate=16_000),
                    "ngram": datasets.Value("string")
                }
            ),
            supervised_keys=None,
            homepage=_BASE_URL,
            citation=_CITATION
        )

    def _split_generators(self, dl_manager):
        archive_path = dl_manager.download(_DATA_URL)
        meta_path = dl_manager.download(_PROMPTS_URLS)
        return [datasets.SplitGenerator(
            name=datasets.Split.TEST,
            gen_kwargs={
                "meta_path": meta_path["test"],
                "audio_files": dl_manager.iter_archive(archive_path)
            }
        )]

    def _generate_examples(self, meta_path, audio_files):
        """Lorem ipsum."""
        print(audio_files)
        metadata = {}
        with open(meta_path, encoding="utf-8") as f:
            next(f)
            for row in f:
                print(row)
                r = row.split("\t")
                print(r)
                audio_id = r[0]
                ngram = r[1]
                metadata[audio_id] = {"audio_id": audio_id,
                                      "ngram": ngram}

        id_ = 0
        for path, f in audio_files:
            print(path, f)
            _, audio_name = os.path.split(path)
            print(audio_name)
            print(metadata)
            if audio_name in metadata:
                audio = {"bytes": f.read()}
                yield id_, {**metadata[audio_id], "audio": audio}
                id_ +=1