imvladikon commited on
Commit
7a73e7b
1 Parent(s): babe2f3
Files changed (1) hide show
  1. hebrew_speech_kan.py +61 -0
hebrew_speech_kan.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import glob
2
+ import os
3
+ from functools import partial
4
+
5
+ import datasets
6
+
7
+ LANGS = [
8
+ "he"
9
+ ]
10
+ VERSION = datasets.Version("0.0.1")
11
+
12
+
13
+ class PublicSpeech(datasets.GeneratorBasedBuilder):
14
+ """Public Speech dataset."""
15
+
16
+ BUILDER_CONFIGS = [
17
+ datasets.BuilderConfig(name=lang, version=VERSION, description=f"Public Speech {lang} dataset")
18
+ for lang in LANGS
19
+ ]
20
+
21
+ def _info(self):
22
+ return datasets.DatasetInfo(
23
+ description="youtube audio of kan digital samples",
24
+ features=datasets.Features(
25
+ {
26
+ "audio": datasets.Audio(sampling_rate=16000),
27
+ "sentence": datasets.Value("string"),
28
+ }
29
+ ),
30
+ supervised_keys=("audio", "sentence"),
31
+ homepage="https://huggingface.co/datasets/imvladikon/hebrew_speech_kan",
32
+ citation="TODO",
33
+ )
34
+
35
+ def _split_generators(self, dl_manager):
36
+ downloader = partial(
37
+ lambda split: dl_manager.download_and_extract(f"data/{self.config.name}/{split}.tar.gz"),
38
+ )
39
+
40
+ return [
41
+ datasets.SplitGenerator(
42
+ name=datasets.Split.TRAIN,
43
+ gen_kwargs={"root_path": downloader("train"), "split": "train"},
44
+ ),
45
+ datasets.SplitGenerator(
46
+ name=datasets.Split.VALIDATION,
47
+ gen_kwargs={"root_path": downloader("dev"), "split": "dev"},
48
+ ),
49
+ ]
50
+
51
+ def _generate_examples(self, root_path, split):
52
+ split_path = os.path.join(root_path, split)
53
+ for wav in glob.glob(split_path + "/*.wav"):
54
+ uid = os.path.splitext(os.path.basename(wav))[0]
55
+ with open(os.path.join(split_path, f"{uid}.txt"), encoding="utf-8") as fin:
56
+ text = fin.read()
57
+ example = {
58
+ "audio": wav,
59
+ "sentence": text,
60
+ }
61
+ yield uid, example