Datasets:
Added Loader Script
Browse files- OpenBible_Swahili.py +169 -0
OpenBible_Swahili.py
ADDED
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
import json
|
3 |
+
|
4 |
+
import datasets
|
5 |
+
|
6 |
+
logger = datasets.logging.get_logger(__name__)
|
7 |
+
|
8 |
+
_DESCRIPTION = """Verse-level segmented audio of
|
9 |
+
[Swahili: Biblica® Open Kiswahili Contemporary Version (Neno)](https://open.bible/bibles/swahili-biblica-audio-bible/).
|
10 |
+
Aligned, cleaned, and segmented using [MMS](https://arxiv.org/abs/2305.13516).
|
11 |
+
"""
|
12 |
+
_HOMEPAGE_URL = "https://github.com/bookbot-hive/OpenBible-TTS"
|
13 |
+
_CITATION = ""
|
14 |
+
_DATA_URL = "https://huggingface.co/datasets/bookbot/OpenBible_Swahili/resolve/main/data"
|
15 |
+
_LICENSE = "https://creativecommons.org/licenses/by-sa/4.0/"
|
16 |
+
|
17 |
+
BOOKS = [
|
18 |
+
"GEN",
|
19 |
+
"EXO",
|
20 |
+
"LEV",
|
21 |
+
"NUM",
|
22 |
+
"DEU",
|
23 |
+
"JOS",
|
24 |
+
"JDG",
|
25 |
+
"RUT",
|
26 |
+
"1SA",
|
27 |
+
"2SA",
|
28 |
+
"1KI",
|
29 |
+
"2KI",
|
30 |
+
"1CH",
|
31 |
+
"2CH",
|
32 |
+
"EZR",
|
33 |
+
"NEH",
|
34 |
+
"EST",
|
35 |
+
"JOB",
|
36 |
+
"PSA",
|
37 |
+
"PRO",
|
38 |
+
"ECC",
|
39 |
+
"SNG",
|
40 |
+
"ISA",
|
41 |
+
"JER",
|
42 |
+
"LAM",
|
43 |
+
"EZK",
|
44 |
+
"DAN",
|
45 |
+
"HOS",
|
46 |
+
"JOL",
|
47 |
+
"AMO",
|
48 |
+
"OBA",
|
49 |
+
"JON",
|
50 |
+
"MIC",
|
51 |
+
"NAM",
|
52 |
+
"HAB",
|
53 |
+
"ZEP",
|
54 |
+
"HAG",
|
55 |
+
"ZEC",
|
56 |
+
"MAL",
|
57 |
+
"MAT",
|
58 |
+
"MRK",
|
59 |
+
"LUK",
|
60 |
+
"JHN",
|
61 |
+
"ACT",
|
62 |
+
"ROM",
|
63 |
+
"1CO",
|
64 |
+
"2CO",
|
65 |
+
"GAL",
|
66 |
+
"EPH",
|
67 |
+
"PHP",
|
68 |
+
"COL",
|
69 |
+
"1TH",
|
70 |
+
"2TH",
|
71 |
+
"1TI",
|
72 |
+
"2TI",
|
73 |
+
"TIT",
|
74 |
+
"PHM",
|
75 |
+
"HEB",
|
76 |
+
"JAS",
|
77 |
+
"1PE",
|
78 |
+
"2PE",
|
79 |
+
"1JN",
|
80 |
+
"2JN",
|
81 |
+
"3JN",
|
82 |
+
"JUD",
|
83 |
+
"REV",
|
84 |
+
]
|
85 |
+
|
86 |
+
|
87 |
+
class OpenBibleSwahiliConfig(datasets.BuilderConfig):
|
88 |
+
"""BuilderConfig for OpenBibleSwahili"""
|
89 |
+
|
90 |
+
def __init__(self, name, version):
|
91 |
+
super(OpenBibleSwahiliConfig, self).__init__(
|
92 |
+
name=name,
|
93 |
+
version=version,
|
94 |
+
description=_DESCRIPTION,
|
95 |
+
)
|
96 |
+
|
97 |
+
|
98 |
+
class OpenBible_Swahili(datasets.GeneratorBasedBuilder):
|
99 |
+
DEFAULT_CONFIG_NAME = "default"
|
100 |
+
|
101 |
+
BUILDER_CONFIGS = [
|
102 |
+
OpenBibleSwahiliConfig(
|
103 |
+
name=book,
|
104 |
+
version=datasets.Version("1.1.0"),
|
105 |
+
)
|
106 |
+
for book in BOOKS + ["default"]
|
107 |
+
]
|
108 |
+
|
109 |
+
def _info(self):
|
110 |
+
features = datasets.Features(
|
111 |
+
{
|
112 |
+
"id": datasets.Value("string"),
|
113 |
+
"verse_id": datasets.Value("string"),
|
114 |
+
"audio": datasets.Audio(sampling_rate=44_100),
|
115 |
+
"verse_text": datasets.Value("string"),
|
116 |
+
"transcript": datasets.Value("string"),
|
117 |
+
}
|
118 |
+
)
|
119 |
+
|
120 |
+
return datasets.DatasetInfo(
|
121 |
+
description=_DESCRIPTION,
|
122 |
+
features=features,
|
123 |
+
supervised_keys=None,
|
124 |
+
homepage=_HOMEPAGE_URL,
|
125 |
+
citation=_CITATION,
|
126 |
+
license=_LICENSE,
|
127 |
+
)
|
128 |
+
|
129 |
+
def _split_generators(self, dl_manager):
|
130 |
+
if self.config.name == "default":
|
131 |
+
archive_paths = [dl_manager.download_and_extract(f"{_DATA_URL}/{book}.tar.gz") for book in BOOKS]
|
132 |
+
else:
|
133 |
+
archive_paths = [dl_manager.download_and_extract(f"{_DATA_URL}/{self.config.name}.tar.gz")]
|
134 |
+
|
135 |
+
return [
|
136 |
+
datasets.SplitGenerator(
|
137 |
+
name=datasets.Split.TRAIN,
|
138 |
+
gen_kwargs={
|
139 |
+
"archive_paths": archive_paths,
|
140 |
+
},
|
141 |
+
)
|
142 |
+
]
|
143 |
+
|
144 |
+
def _generate_examples(self, archive_paths):
|
145 |
+
id_ = 0
|
146 |
+
for archive_path in archive_paths:
|
147 |
+
path = Path(archive_path)
|
148 |
+
json_path = list(path.rglob("*.json"))[0]
|
149 |
+
with open(json_path) as f:
|
150 |
+
data = json.load(f)
|
151 |
+
|
152 |
+
for datum in data:
|
153 |
+
book = datum["verseNumber"].split()[0]
|
154 |
+
chapter, verse_number = datum["verseNumber"].split()[1].split(":")
|
155 |
+
book_chapter = f"{book}_{chapter.zfill(3)}"
|
156 |
+
book_chapter_verse = f"{book_chapter}_{verse_number.zfill(3)}"
|
157 |
+
audio_path = (path / book / book_chapter / book_chapter_verse).with_suffix(".wav")
|
158 |
+
transcript_path = audio_path.with_suffix(".txt")
|
159 |
+
with open(transcript_path) as f:
|
160 |
+
transcript = f.read().strip()
|
161 |
+
|
162 |
+
yield id_, {
|
163 |
+
"id": book_chapter_verse,
|
164 |
+
"verse_id": datum["verseNumber"],
|
165 |
+
"audio": str(audio_path),
|
166 |
+
"verse_text": datum["verseText"],
|
167 |
+
"transcript": transcript,
|
168 |
+
}
|
169 |
+
id_ += 1
|