Datasets:
Upload dataset.py
Browse files- dataset.py +30 -0
dataset.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datasets
|
| 2 |
+
|
| 3 |
+
class MyAudioDataset(datasets.GeneratorBasedBuilder):
|
| 4 |
+
def _info(self):
|
| 5 |
+
return datasets.DatasetInfo(
|
| 6 |
+
features=datasets.Features({
|
| 7 |
+
"audio": datasets.Audio(sampling_rate=44100),
|
| 8 |
+
"tgt_text": datasets.Value("string"),
|
| 9 |
+
}),
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
def _split_generators(self, dl_manager):
|
| 13 |
+
data_path = dl_manager.download_and_extract("data.csv")
|
| 14 |
+
return [
|
| 15 |
+
datasets.SplitGenerator(
|
| 16 |
+
name=datasets.Split.TRAIN,
|
| 17 |
+
gen_kwargs={"filepath": data_path},
|
| 18 |
+
),
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
def _generate_examples(self, filepath):
|
| 22 |
+
import csv
|
| 23 |
+
with open(filepath, encoding="utf-8") as f:
|
| 24 |
+
reader = csv.DictReader(f)
|
| 25 |
+
for idx, row in enumerate(reader):
|
| 26 |
+
yield idx, {
|
| 27 |
+
"audio": row["audio"],
|
| 28 |
+
"tgt_text": row["tgt_text"],
|
| 29 |
+
}
|
| 30 |
+
|