|
"""Huggingface Dataset version of Banc Trawsgrifiadau Bangor""" |
|
|
|
|
|
import os |
|
import datasets |
|
|
|
|
|
|
|
_CITATION = """\ |
|
} |
|
""" |
|
_DESCRIPTION = """Huggingface Dataset version of Banc Trawsgrifiadau Bangor""" |
|
_HOMEPAGE = "https://git.techiaith.bangor.ac.uk/data-porth-technolegau-iaith/banc-trawsgrifiadau-bangor" |
|
_LICENSE = "Creative Commons Zero v1.0 Universal" |
|
_URL = "https://huggingface.co/datasets/prvInSpace/banc-trawsgrifiadau-bangor/resolve/main" |
|
|
|
|
|
|
|
|
|
class BancTrawsgrifiadauBangor(datasets.GeneratorBasedBuilder): |
|
"""Huggingface Dataset version of Banc Trawsgrifiadau Bangor""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"audio_filename": datasets.Value("string"), |
|
"audio_filesize": datasets.Value("string"), |
|
"transcript": datasets.Value("string"), |
|
"duration": datasets.Value("int64"), |
|
"audio": datasets.features.Audio(sampling_rate=16_000) |
|
|
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
|
|
features=features, |
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
|
|
data_dir = dl_manager.download_and_extract( |
|
f"{_URL}/clips.zip") |
|
|
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name="clips", |
|
|
|
gen_kwargs={ |
|
"filepath": dl_manager.download(f"{_URL}/clips.tsv"), |
|
"path_to_clips": os.path.join(data_dir, "clips") |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": dl_manager.download(f"{_URL}/train.tsv"), |
|
"path_to_clips": os.path.join(data_dir, "clips") |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": dl_manager.download(f"{_URL}/test.tsv"), |
|
"path_to_clips": os.path.join(data_dir, "clips") |
|
}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath, path_to_clips): |
|
print(path_to_clips) |
|
import csv |
|
|
|
|
|
with open(filepath, encoding="utf-8") as f: |
|
reader = csv.DictReader(f, delimiter="\t") |
|
for row in reader: |
|
path = f'{path_to_clips}/{row["audio_filename"]}' |
|
|
|
|
|
with open(path, "rb") as file: |
|
row['audio'] = { |
|
'path': path, 'bytes': file.read() |
|
} |
|
yield path, row |
|
|