bagasshw commited on
Commit
39e6227
·
verified ·
1 Parent(s): db94524

Upload indo-gs2.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. indo-gs2.py +98 -0
indo-gs2.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import os
3
+ import zipfile
4
+ from typing import List
5
+
6
+ import datasets
7
+
8
+ _DATASETNAME = "id_asr"
9
+
10
+ _DESCRIPTION = """\
11
+ This dataset contains transcribed audio data for Indonesian. The dataset consists of audio files and a CSV file.
12
+ The CSV file contains the audio ID and transcription of the audio in the file.
13
+ """
14
+ _LANGUAGES = ["ind"]
15
+
16
+ _SOURCE_VERSION = "1.0.0"
17
+
18
+ class IdASR(datasets.GeneratorBasedBuilder):
19
+ """Indonesian ASR training dataset."""
20
+
21
+ VERSION = datasets.Version(_SOURCE_VERSION)
22
+
23
+ BUILDER_CONFIGS = [
24
+ datasets.BuilderConfig(
25
+ name="default",
26
+ version=VERSION,
27
+ description="Indonesian ASR dataset",
28
+ )
29
+ ]
30
+
31
+ DEFAULT_CONFIG_NAME = "default"
32
+
33
+ def _info(self) -> datasets.DatasetInfo:
34
+ features = datasets.Features(
35
+ {
36
+ "id": datasets.Value("string"),
37
+ "path": datasets.Value("string"),
38
+ "audio": datasets.Audio(sampling_rate=16_000),
39
+ "sentence": datasets.Value("string"),
40
+ }
41
+ )
42
+ return datasets.DatasetInfo(
43
+ description=_DESCRIPTION,
44
+ features=features
45
+ )
46
+
47
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
48
+ manual_dir = dl_manager.manual_dir
49
+
50
+ return [
51
+ datasets.SplitGenerator(
52
+ name=datasets.Split.TRAIN,
53
+ gen_kwargs={"archive_path": os.path.join(manual_dir, "train.zip")},
54
+ ),
55
+ datasets.SplitGenerator(
56
+ name=datasets.Split.VALIDATION,
57
+ gen_kwargs={"archive_path": os.path.join(manual_dir, "val.zip")},
58
+ ),
59
+ datasets.SplitGenerator(
60
+ name=datasets.Split.TEST,
61
+ gen_kwargs={"archive_path": os.path.join(manual_dir, "test.zip")},
62
+ ),
63
+ ]
64
+
65
+ def _generate_examples(self, archive_path: str):
66
+ extract_dir = archive_path.rstrip(".zip")
67
+
68
+ with zipfile.ZipFile(archive_path, "r") as zip_ref:
69
+ zip_ref.extractall(extract_dir)
70
+
71
+ csv_path = None
72
+ for root, _, files in os.walk(extract_dir):
73
+ for file in files:
74
+ if file.endswith(".csv"):
75
+ csv_path = os.path.join(root, file)
76
+ break
77
+ if csv_path:
78
+ break
79
+
80
+ if not csv_path:
81
+ raise FileNotFoundError("CSV file not found inside the archive.")
82
+
83
+ with open(csv_path, "r", encoding="utf-8") as f:
84
+ reader = csv.DictReader(f)
85
+ for row in reader:
86
+ audio_id = row["id"]
87
+ relative_path = row["path"]
88
+ sentence = row["sentence"]
89
+
90
+ # Construct full path to audio file
91
+ full_audio_path = os.path.join(extract_dir, relative_path)
92
+
93
+ yield audio_id, {
94
+ "id": audio_id,
95
+ "path": full_audio_path,
96
+ "audio": full_audio_path,
97
+ "sentence": sentence,
98
+ }