Datasets:
Update dataset loading script
Browse files- jeli-asr.py +19 -10
jeli-asr.py
CHANGED
|
@@ -15,7 +15,6 @@ limitations under the License.
|
|
| 15 |
"""
|
| 16 |
# jeli_asr.py
|
| 17 |
import csv
|
| 18 |
-
import os
|
| 19 |
|
| 20 |
import datasets
|
| 21 |
from datasets import Split, SplitGenerator
|
|
@@ -123,10 +122,12 @@ class JeliASR(datasets.GeneratorBasedBuilder):
|
|
| 123 |
Read metadata.csv row-by-row, filter by subset (based on config) & split,
|
| 124 |
then download each audio file from the Hub and yield its local path.
|
| 125 |
"""
|
|
|
|
|
|
|
|
|
|
| 126 |
with open(metadata_path, "r", encoding="utf-8") as f:
|
| 127 |
reader = csv.DictReader(f)
|
| 128 |
-
idx
|
| 129 |
-
for row in reader:
|
| 130 |
file_path = row["file_name"] # e.g. "bam-asr-oza/train/.../audio.wav"
|
| 131 |
|
| 132 |
# 1) Filter by config
|
|
@@ -144,15 +145,23 @@ class JeliASR(datasets.GeneratorBasedBuilder):
|
|
| 144 |
|
| 145 |
# Build the raw URL for the audio
|
| 146 |
audio_url = f"{_BASE_URL}/{file_path}"
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
# Download it. dl_manager returns the local path in the cache.
|
| 150 |
-
local_audio_path = dl_manager.download(audio_url)
|
| 151 |
|
| 152 |
-
|
| 153 |
-
|
| 154 |
"duration": float(row["duration"]),
|
| 155 |
"bam": row["bam"],
|
| 156 |
"french": row["french"],
|
| 157 |
}
|
| 158 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
"""
|
| 16 |
# jeli_asr.py
|
| 17 |
import csv
|
|
|
|
| 18 |
|
| 19 |
import datasets
|
| 20 |
from datasets import Split, SplitGenerator
|
|
|
|
| 122 |
Read metadata.csv row-by-row, filter by subset (based on config) & split,
|
| 123 |
then download each audio file from the Hub and yield its local path.
|
| 124 |
"""
|
| 125 |
+
audios_to_download = []
|
| 126 |
+
metadata_dict = {}
|
| 127 |
+
|
| 128 |
with open(metadata_path, "r", encoding="utf-8") as f:
|
| 129 |
reader = csv.DictReader(f)
|
| 130 |
+
for idx, row in enumerate(reader):
|
|
|
|
| 131 |
file_path = row["file_name"] # e.g. "bam-asr-oza/train/.../audio.wav"
|
| 132 |
|
| 133 |
# 1) Filter by config
|
|
|
|
| 145 |
|
| 146 |
# Build the raw URL for the audio
|
| 147 |
audio_url = f"{_BASE_URL}/{file_path}"
|
| 148 |
+
audios_to_download.append(audio_url)
|
|
|
|
|
|
|
|
|
|
| 149 |
|
| 150 |
+
# Store metadata in dictionary
|
| 151 |
+
metadata_dict[audio_url] = {
|
| 152 |
"duration": float(row["duration"]),
|
| 153 |
"bam": row["bam"],
|
| 154 |
"french": row["french"],
|
| 155 |
}
|
| 156 |
+
|
| 157 |
+
# Download the audios. dl_manager returns the local paths in the cache.
|
| 158 |
+
local_audio_paths = dl_manager.download(audios_to_download)
|
| 159 |
+
for idx, audio_url in enumerate(audios_to_download):
|
| 160 |
+
local_audio_path = local_audio_paths[idx]
|
| 161 |
+
# Yield the example
|
| 162 |
+
yield idx, {
|
| 163 |
+
"audio": local_audio_path, # local path for datasets.Audio
|
| 164 |
+
"duration": metadata_dict[audio_url]["duration"],
|
| 165 |
+
"bam": metadata_dict[audio_url]["bam"],
|
| 166 |
+
"french": metadata_dict[audio_url]["french"],
|
| 167 |
+
}
|