|
from collections import defaultdict |
|
import os |
|
import json |
|
import csv |
|
csv.field_size_limit(100000000) |
|
|
|
import datasets |
|
|
|
_NAME="cv17_es_other_automatically_verified" |
|
_VERSION="1.0.0" |
|
_AUDIO_EXTENSIONS=".mp3" |
|
|
|
_DESCRIPTION = """ |
|
Split called -other- of the Spanish Common Voice v17.0 that was automatically verified |
|
using various ASR system. |
|
""" |
|
|
|
_CITATION = """ |
|
@misc{carlosmena2024cv17autoveri, |
|
title={Spanish Common Voice v17.0 Split Other Automatically Verified}, |
|
author={Mena, Carlos}, |
|
publisher={Barcelona Supercomputing Center} |
|
year={2024}, |
|
url={https://huggingface.co/datasets/projecte-aina/cv17_es_other_automatically_verified}, |
|
} |
|
""" |
|
|
|
_HOMEPAGE = "https://huggingface.co/datasets/projecte-aina/cv17_es_other_automatically_verified" |
|
|
|
_LICENSE = "CC-BY-4.0, See https://creativecommons.org/licenses/by/4.0/" |
|
|
|
_BASE_DATA_DIR = "corpus/" |
|
|
|
_METADATA_OTHER = os.path.join(_BASE_DATA_DIR,"files","other.tsv") |
|
|
|
_TARS_REPO = os.path.join(_BASE_DATA_DIR,"files","tars_repo.paths") |
|
|
|
class CV17EsOtherAutomaticallyVerifiedConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for The Spanish Common Voice v17.0 Split Other Automatically Verified""" |
|
|
|
def __init__(self, name, **kwargs): |
|
name=_NAME |
|
super().__init__(name=name, **kwargs) |
|
|
|
class CV17EsOtherAutomaticallyVerified(datasets.GeneratorBasedBuilder): |
|
"""Spanish Common Voice v17.0 Split Other Automatically Verified""" |
|
|
|
VERSION = datasets.Version(_VERSION) |
|
BUILDER_CONFIGS = [ |
|
CV17EsOtherAutomaticallyVerifiedConfig( |
|
name=_NAME, |
|
version=datasets.Version(_VERSION), |
|
) |
|
] |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"audio": datasets.Audio(sampling_rate=16000), |
|
"client_id": datasets.Value("string"), |
|
"path": datasets.Value("string"), |
|
"sentence_id": datasets.Value("string"), |
|
"sentence": datasets.Value("string"), |
|
"sentence_domain": datasets.Value("string"), |
|
"up_votes": datasets.Value("int32"), |
|
"down_votes": datasets.Value("int32"), |
|
"age": datasets.Value("string"), |
|
"gender": datasets.Value("string"), |
|
"accents": datasets.Value("string"), |
|
"variant": datasets.Value("string"), |
|
"locale": datasets.Value("string"), |
|
"segment": datasets.Value("string"), |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
metadata_other=dl_manager.download_and_extract(_METADATA_OTHER) |
|
|
|
tars_repo=dl_manager.download_and_extract(_TARS_REPO) |
|
|
|
hash_tar_files=defaultdict(dict) |
|
|
|
with open(tars_repo,'r') as f: |
|
hash_tar_files['other']=[path.replace('\n','') for path in f] |
|
|
|
hash_meta_paths={"other":metadata_other} |
|
|
|
audio_paths = dl_manager.download(hash_tar_files) |
|
|
|
splits=["other"] |
|
local_extracted_audio_paths = ( |
|
dl_manager.extract(audio_paths) if not dl_manager.is_streaming else |
|
{ |
|
split:[None] * len(audio_paths[split]) for split in splits |
|
} |
|
) |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name="other", |
|
gen_kwargs={ |
|
"audio_archives":[dl_manager.iter_archive(archive) for archive in audio_paths["other"]], |
|
"local_extracted_archives_paths": local_extracted_audio_paths["other"], |
|
"metadata_paths": hash_meta_paths["other"], |
|
} |
|
), |
|
] |
|
|
|
def _generate_examples(self, audio_archives, local_extracted_archives_paths, metadata_paths): |
|
|
|
features = ["client_id","sentence_id","sentence","sentence_domain","up_votes", |
|
"down_votes","age","gender", "accents","variant","locale","segment"] |
|
|
|
with open(metadata_paths) as f: |
|
metadata = {x["path"]: x for x in csv.DictReader(f, delimiter="\t")} |
|
|
|
for audio_archive, local_extracted_archive_path in zip(audio_archives, local_extracted_archives_paths): |
|
for audio_filename, audio_file in audio_archive: |
|
audio_id =os.path.splitext(os.path.basename(audio_filename))[0] |
|
audio_id=audio_id+_AUDIO_EXTENSIONS |
|
path = os.path.join(local_extracted_archive_path, audio_filename) if local_extracted_archive_path else audio_filename |
|
|
|
try: |
|
yield audio_id, { |
|
"path": audio_id, |
|
**{feature: metadata[audio_id][feature] for feature in features}, |
|
"audio": {"path": path, "bytes": audio_file.read()}, |
|
} |
|
except: |
|
continue |
|
|
|
|