File size: 1,929 Bytes
7a73e7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import glob
import os
from functools import partial

import datasets

LANGS = [
  "he"
]
VERSION = datasets.Version("0.0.1")


class PublicSpeech(datasets.GeneratorBasedBuilder):
    """Public Speech dataset."""

    BUILDER_CONFIGS = [
        datasets.BuilderConfig(name=lang, version=VERSION, description=f"Public Speech {lang} dataset")
        for lang in LANGS
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description="youtube audio of kan digital samples",
            features=datasets.Features(
                {
                    "audio": datasets.Audio(sampling_rate=16000),
                    "sentence": datasets.Value("string"),
                }
            ),
            supervised_keys=("audio", "sentence"),
            homepage="https://huggingface.co/datasets/imvladikon/hebrew_speech_kan",
            citation="TODO",
        )

    def _split_generators(self, dl_manager):
        downloader = partial(
            lambda split: dl_manager.download_and_extract(f"data/{self.config.name}/{split}.tar.gz"),
        )

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={"root_path": downloader("train"), "split": "train"},
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={"root_path": downloader("dev"), "split": "dev"},
            ),
        ]

    def _generate_examples(self, root_path, split):
        split_path = os.path.join(root_path, split)
        for wav in glob.glob(split_path + "/*.wav"):
            uid = os.path.splitext(os.path.basename(wav))[0]
            with open(os.path.join(split_path, f"{uid}.txt"), encoding="utf-8") as fin:
                text = fin.read()
            example = {
                "audio": wav,
                "sentence": text,
            }
            yield uid, example