|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" AfriSpeech-200 Dataset""" |
|
|
|
|
|
|
|
|
|
|
|
import csv |
|
import os |
|
|
|
import datasets |
|
from datasets.utils.py_utils import size_str |
|
from tqdm import tqdm |
|
|
|
|
|
_CITATION = """ TBD """ |
|
|
|
_DESCRIPTION = """\ |
|
AFRISPEECH-200 is a 200hr Pan-African speech corpus for clinical and general domain English accented ASR; |
|
a dataset with 120 African accents from 13 countries and 2,463 unique African speakers. |
|
Our goal is to raise awareness for and advance Pan-African English ASR research, |
|
especially for the clinical domain. |
|
""" |
|
|
|
_ALL_CONFIGS = [ |
|
'yoruba', 'igbo', 'swahili', 'ijaw', 'xhosa', 'twi', 'luhya', |
|
'igala', 'urhobo', 'hausa', 'kiswahili', 'zulu', 'isizulu', |
|
'venda and xitsonga', 'borana', 'afrikaans', 'setswana', 'idoma', |
|
'izon', 'chichewa', 'ebira', 'tshivenda', 'isixhosa', |
|
'kinyarwanda', 'tswana', 'luganda', 'luo', 'venda', 'dholuo', |
|
'akan (fante)', 'sepedi', 'kikuyu', 'isindebele', |
|
'luganda and kiswahili', 'akan', 'sotho', 'south african english', |
|
'sesotho', 'swahili ,luganda ,arabic', 'shona', 'damara', |
|
'southern sotho', 'luo, swahili', 'ateso', 'meru', 'siswati', |
|
'portuguese', 'esan', 'nasarawa eggon', 'ibibio', 'isoko', |
|
'pidgin', 'alago', 'nembe', 'ngas', 'kagoma', 'ikwere', 'fulani', |
|
'bette', 'efik', 'edo', 'hausa/fulani', 'bekwarra', 'epie', |
|
'afemai', 'benin', 'nupe', 'tiv', 'okrika', 'etsako', 'ogoni', |
|
'kubi', 'gbagyi', 'brass', 'oklo', 'ekene', 'ika', 'berom', 'jaba', |
|
'itsekiri', 'ukwuani', 'yala mbembe', 'afo', 'english', 'ebiobo', |
|
'igbo and yoruba', 'okirika', 'kalabari', 'ijaw(nembe)', 'anaang', |
|
'eggon', 'bini', 'yoruba, hausa', 'ekpeye', 'bajju', 'kanuri', |
|
'delta', 'khana', 'ogbia', 'mada', 'mwaghavul', 'angas', 'ikulu', |
|
'eleme', 'igarra', 'etche', 'agatu', 'bassa', 'jukun', 'urobo', |
|
'ibani', 'obolo', 'idah', 'eket', 'nyandang', 'estako', 'ishan', |
|
'bassa-nge/nupe', 'bagi', 'gerawa' |
|
] |
|
|
|
_HOMEPAGE = "https://github.com/intron-innovation/AfriSpeech-Dataset-Paper" |
|
|
|
_LICENSE = "http://creativecommons.org/licenses/by-nc-sa/4.0/" |
|
|
|
|
|
|
|
_AUDIO_URL = "audio/{split}/{split}_{shard_idx}.tar.gz" |
|
|
|
_TRANSCRIPT_URL = "transcripts/{split}.csv" |
|
|
|
_SHARDS = { |
|
'train': 35, |
|
'dev': 2, |
|
'test': 4 |
|
} |
|
|
|
class AfriSpeechConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for afrispeech""" |
|
|
|
def __init__( |
|
self, name, description, homepage, data_url |
|
): |
|
super(AfriSpeechConfig, self).__init__( |
|
name=self.name, |
|
version=datasets.Version("1.0.0", ""), |
|
description=self.description, |
|
) |
|
self.name = name |
|
self.description = description |
|
self.homepage = homepage |
|
self.data_url = data_url |
|
|
|
|
|
def _build_config(name): |
|
return AfriSpeechConfig( |
|
name=name, |
|
description=_DESCRIPTION, |
|
homepage=_HOMEPAGE, |
|
data_url=_AUDIO_URL, |
|
) |
|
|
|
class AfriSpeech(datasets.GeneratorBasedBuilder): |
|
DEFAULT_WRITER_BATCH_SIZE = 1000 |
|
VERSION = datasets.Version("1.0.0") |
|
BUILDER_CONFIGS = [_build_config(name) for name in _ALL_CONFIGS + ["all"]] |
|
|
|
def _info(self): |
|
description = _DESCRIPTION |
|
features = datasets.Features( |
|
{ |
|
"speaker_id": datasets.Value("string"), |
|
"path": datasets.Value("string"), |
|
"audio": datasets.features.Audio(sampling_rate=44_100), |
|
"transcript": datasets.Value("string"), |
|
"age_group": datasets.Value("string"), |
|
"gender": datasets.Value("string"), |
|
"accent": datasets.Value("string"), |
|
"domain": datasets.Value("string"), |
|
"country": datasets.Value("string"), |
|
"duration": datasets.Value("float"), |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
description=description, |
|
features=features, |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
version=self.VERSION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
langs = ( |
|
_ALL_CONFIGS |
|
if self.config.name == "all" |
|
else [self.config.name] |
|
) |
|
|
|
n_shards = _SHARDS |
|
|
|
audio_urls = {} |
|
splits = ("train", "dev") |
|
for split in splits: |
|
audio_urls[split] = [ |
|
_AUDIO_URL.format(split=split, shard_idx=i) for i in range(n_shards[split]) |
|
] |
|
archive_paths = dl_manager.download(audio_urls) |
|
local_extracted_archive_paths = dl_manager.extract(archive_paths) if not dl_manager.is_streaming else {} |
|
|
|
meta_urls = {split: _TRANSCRIPT_URL.format(split=split) for split in splits} |
|
meta_paths = dl_manager.download_and_extract(meta_urls) |
|
|
|
split_generators = [] |
|
split_names = { |
|
"train": datasets.Split.TRAIN, |
|
"dev": datasets.Split.VALIDATION, |
|
|
|
} |
|
for split in splits: |
|
split_generators.append( |
|
datasets.SplitGenerator( |
|
name=split_names.get(split, split), |
|
gen_kwargs={ |
|
"local_extracted_archive_paths": local_extracted_archive_paths.get(split), |
|
"archives": [dl_manager.iter_archive(path) for path in archive_paths.get(split)], |
|
"meta_path": meta_paths[split], |
|
}, |
|
), |
|
) |
|
|
|
return split_generators |
|
|
|
def _generate_examples(self, local_extracted_archive_paths, archives, meta_path): |
|
"""Yields examples as (key, example) tuples.""" |
|
|
|
|
|
|
|
|
|
data_fields = [key for key in self._info().features.keys() if key not in ["audio", "path"]] |
|
metadata = {} |
|
print("config:", self.config.name) |
|
with open(meta_path, "r", encoding="utf-8") as f: |
|
reader = csv.DictReader(f) |
|
for row in tqdm(reader, desc="Reading metadata..."): |
|
if (row['accent'] == self.config.name) or (self.config.name == 'all'): |
|
row["speaker_id"] = row["user_ids"] |
|
audio_id = "/".join(row["audio_paths"].split("/")[-2:]) |
|
|
|
metadata[audio_id] = {field: row.get(field, "") for field in data_fields} |
|
|
|
for i, audio_archive in enumerate(archives): |
|
for filename, file in tqdm(audio_archive, desc=f"Searching and Extracting audios for config {self.config.name}..."): |
|
|
|
filename = "/".join(filename.split("/")[-2:]) |
|
if filename in metadata: |
|
result = dict(metadata[filename]) |
|
|
|
path = os.path.join(local_extracted_archive_paths[i], filename) if local_extracted_archive_paths else filename |
|
result["audio"] = {"path": path, "bytes": file.read()} |
|
|
|
result["path"] = path if local_extracted_archive_paths else filename |
|
|
|
yield path, result |
|
|