carlosdanielhernandezmena commited on
Commit
b65e307
1 Parent(s): 280e263

Delete loading script

Browse files
Files changed (1) hide show
  1. masri_dev.py +0 -122
masri_dev.py DELETED
@@ -1,122 +0,0 @@
1
- from collections import defaultdict
2
- import os
3
- import json
4
- import csv
5
-
6
- import datasets
7
-
8
- _NAME="masri_dev"
9
- _VERSION="1.0.0"
10
- _AUDIO_EXTENSIONS=".flac"
11
-
12
- _DESCRIPTION = """
13
- The MASRI-DEV CORPUS was created out of YouTube videos belonging to the channel of the University of Malta. It has a length of 1 hour and it is gender balanced, as it has the same number of male and female speakers.
14
- """
15
-
16
- _CITATION = """
17
- @misc{carlosmenamasridev2020,
18
- title={MASRI-DEV CORPUS: Audio and Transcriptions in Maltese extracted from the YouTube channel of the University of Malta.},
19
- author={Hernandez Mena, Carlos Daniel and Brincat, Ayrton Didier and Gatt, Albert and DeMarco, Andrea and Borg, Claudia and van der Plas, Lonneke and Meza Ruiz, Iván Vladimir},
20
- journal={MASRI Project, Malta},
21
- year={2020},
22
- url={https://www.um.edu.mt/projects/masri/},
23
- }
24
- """
25
-
26
- _HOMEPAGE = "https://www.um.edu.mt/projects/masri/"
27
-
28
- _LICENSE = "CC-BY-4.0. The copyright remains with the original owners of the video. See https://creativecommons.org/licenses/by/4.0/"
29
-
30
- _BASE_DATA_DIR = "corpus/"
31
- _METADATA_DEV = os.path.join(_BASE_DATA_DIR,"files", "metadata_dev.tsv")
32
-
33
- _TARS_DEV = os.path.join(_BASE_DATA_DIR,"files", "tars_dev.paths")
34
-
35
- class MasriDevConfig(datasets.BuilderConfig):
36
- """BuilderConfig for MASRI-DEV Corpus"""
37
-
38
- def __init__(self, name, **kwargs):
39
- name=_NAME
40
- super().__init__(name=name, **kwargs)
41
-
42
- class MasriDev(datasets.GeneratorBasedBuilder):
43
- """MASRI-DEV Corpus"""
44
-
45
- VERSION = datasets.Version(_VERSION)
46
- BUILDER_CONFIGS = [
47
- MasriDevConfig(
48
- name=_NAME,
49
- version=datasets.Version(_VERSION),
50
- )
51
- ]
52
-
53
- def _info(self):
54
- features = datasets.Features(
55
- {
56
- "audio_id": datasets.Value("string"),
57
- "audio": datasets.Audio(sampling_rate=16000),
58
- "speaker_id": datasets.Value("string"),
59
- "gender": datasets.Value("string"),
60
- "duration": datasets.Value("float32"),
61
- "normalized_text": datasets.Value("string"),
62
- }
63
- )
64
- return datasets.DatasetInfo(
65
- description=_DESCRIPTION,
66
- features=features,
67
- homepage=_HOMEPAGE,
68
- license=_LICENSE,
69
- citation=_CITATION,
70
- )
71
-
72
- def _split_generators(self, dl_manager):
73
-
74
- metadata_dev=dl_manager.download_and_extract(_METADATA_DEV)
75
-
76
- tars_dev=dl_manager.download_and_extract(_TARS_DEV)
77
-
78
- hash_tar_files=defaultdict(dict)
79
-
80
- with open(tars_dev,'r') as f:
81
- hash_tar_files['dev']=[path.replace('\n','') for path in f]
82
-
83
- hash_meta_paths={"dev":metadata_dev}
84
- audio_paths = dl_manager.download(hash_tar_files)
85
-
86
- splits=["dev"]
87
- local_extracted_audio_paths = (
88
- dl_manager.extract(audio_paths) if not dl_manager.is_streaming else
89
- {
90
- split:[None] * len(audio_paths[split]) for split in splits
91
- }
92
- )
93
-
94
- return [
95
- datasets.SplitGenerator(
96
- name=datasets.Split.VALIDATION,
97
- gen_kwargs={
98
- "audio_archives": [dl_manager.iter_archive(archive) for archive in audio_paths["dev"]],
99
- "local_extracted_archives_paths": local_extracted_audio_paths["dev"],
100
- "metadata_paths": hash_meta_paths["dev"],
101
- }
102
- ),
103
- ]
104
-
105
- def _generate_examples(self, audio_archives, local_extracted_archives_paths, metadata_paths):
106
-
107
- features = ["speaker_id","gender","duration","normalized_text"]
108
-
109
- with open(metadata_paths) as f:
110
- metadata = {x["audio_id"]: x for x in csv.DictReader(f, delimiter="\t")}
111
-
112
- for audio_archive, local_extracted_archive_path in zip(audio_archives, local_extracted_archives_paths):
113
- for audio_filename, audio_file in audio_archive:
114
- #audio_id = audio_filename.split(os.sep)[-1].split(_AUDIO_EXTENSIONS)[0]
115
- audio_id =os.path.splitext(os.path.basename(audio_filename))[0]
116
- path = os.path.join(local_extracted_archive_path, audio_filename) if local_extracted_archive_path else audio_filename
117
-
118
- yield audio_id, {
119
- "audio_id": audio_id,
120
- **{feature: metadata[audio_id][feature] for feature in features},
121
- "audio": {"path": path, "bytes": audio_file.read()},
122
- }