Datasets:
Gabriel Baziramwabo
commited on
Commit
·
dd50273
1
Parent(s):
96bdb20
Add dataset loading script using transcripts.txt
Browse files- my_kinyarwanda_dataset.py +35 -0
my_kinyarwanda_dataset.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import datasets
|
3 |
+
|
4 |
+
_DESCRIPTION = "A Kinyarwanda speech dataset of 102 spoken words with corresponding audio files and text labels."
|
5 |
+
_HOMEPAGE = "https://huggingface.co/datasets/benax-rw/my_kinyarwanda_dataset"
|
6 |
+
_CITATION = ""
|
7 |
+
|
8 |
+
class MyKinyarwandaDataset(datasets.GeneratorBasedBuilder):
|
9 |
+
def _info(self):
|
10 |
+
return datasets.DatasetInfo(
|
11 |
+
description=_DESCRIPTION,
|
12 |
+
features=datasets.Features({
|
13 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
14 |
+
"text": datasets.Value("string"),
|
15 |
+
}),
|
16 |
+
supervised_keys=None,
|
17 |
+
homepage=_HOMEPAGE,
|
18 |
+
citation=_CITATION,
|
19 |
+
)
|
20 |
+
|
21 |
+
def _split_generators(self, dl_manager):
|
22 |
+
return [
|
23 |
+
datasets.SplitGenerator(
|
24 |
+
name=datasets.Split.TRAIN,
|
25 |
+
gen_kwargs={"audio_dir": os.path.join(self.config.data_dir, "audio"),
|
26 |
+
"transcript_file": os.path.join(self.config.data_dir, "transcripts.txt")},
|
27 |
+
)
|
28 |
+
]
|
29 |
+
|
30 |
+
def _generate_examples(self, audio_dir, transcript_file):
|
31 |
+
with open(transcript_file, "r", encoding="utf-8") as f:
|
32 |
+
for idx, line in enumerate(f):
|
33 |
+
fname, text = line.strip().split("\t")
|
34 |
+
audio_path = os.path.join(audio_dir, fname)
|
35 |
+
yield idx, {"audio": audio_path, "text": text}
|