# coding=utf-8 # Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ MASC Dataset""" # This script has been adopted from this dataset: "mozilla-foundation/common_voice_11_0" import csv import os import json import datasets from datasets.utils.py_utils import size_str from tqdm import tqdm _CITATION = """\ @INPROCEEDINGS{10022652, author={Al-Fetyani, Mohammad and Al-Barham, Muhammad and Abandah, Gheith and Alsharkawi, Adham and Dawas, Maha}, booktitle={2022 IEEE Spoken Language Technology Workshop (SLT)}, title={MASC: Massive Arabic Speech Corpus}, year={2023}, volume={}, number={}, pages={1006-1013}, doi={10.1109/SLT54892.2023.10022652}} } """ # TODO: Add description of the dataset here # You can copy an official description _DESCRIPTION = """\ MASC is a dataset that contains 1,000 hours of speech sampled at 16 kHz and crawled from over 700 YouTube channels. The dataset is multi-regional, multi-genre, and multi-dialect intended to advance the research and development of Arabic speech technology with a special emphasis on Arabic speech recognition. """ _HOMEPAGE = "https://ieee-dataport.org/open-access/masc-massive-arabic-speech-corpus" _LICENSE = "https://creativecommons.org/licenses/by/4.0/" _BASE_URL = "https://huggingface.co/datasets/pain/MASC/resolve/main/" _AUDIO_URL1 = _BASE_URL + "audio/{split}/{split}_{shard_idx}.tar.gz" _AUDIO_URL2 = _BASE_URL + "audio/{split}/{split}_{shard_idx}.tar.xz" _TRANSCRIPT_URL = _BASE_URL + "transcript/{split}/{split}.csv" class MASC(datasets.GeneratorBasedBuilder): VERSION = datasets.Version("1.0.0") def _info(self): features = datasets.Features( { "video_id": datasets.Value("string"), "start": datasets.Value("float64"), "end": datasets.Value("float64"), "duration": datasets.Value("float64"), "text": datasets.Value("string"), "type": datasets.Value("string"), "file_path": datasets.Value("string"), "audio": datasets.features.Audio(sampling_rate=16_000), } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, supervised_keys=None, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, version=self.config.version, ) def _split_generators(self, dl_manager): n_shards = {"train": 8,"dev": 1, "test": 1} audio_urls = {} splits = ("train", "dev", "test") for split in splits: audio_urls[split] = [ _AUDIO_URL2.format(split=split, shard_idx="{:02d}".format(i+1)) if split=="train" else _AUDIO_URL1.format(split=split, shard_idx="{:02d}".format(i+1)) 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(meta_urls) split_generators = [] split_names = { "train": datasets.Split.TRAIN, "dev": datasets.Split.VALIDATION, "test": datasets.Split.TEST, } 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): data_fields = list(self._info().features.keys()) metadata = {} with open(meta_path, encoding="utf-8") as f: reader = csv.DictReader(f, delimiter=",", quoting=csv.QUOTE_NONE) for row in reader: if not row["file_path"].endswith(".wav"): row["file_path"] += ".wav" for field in data_fields: if field not in row: row[field] = "" metadata[row["file_path"]] = row for i, audio_archive in enumerate(archives): for filename, file in audio_archive: _, filename = os.path.split(filename) if filename in metadata: result = dict(metadata[filename]) # set the audio feature and the path to the extracted file path = os.path.join(local_extracted_archive_paths[i], filename) if local_extracted_archive_paths else filename try: result["audio"] = {"path": path, "bytes": file.read()} except ReadError as e: # Handle the ReadError print("An error occurred while reading the data:", str(e)) continiue # set path to None if the audio file doesn't exist locally (i.e. in streaming mode) result["file_path"] = path if local_extracted_archive_paths else filename yield path, result