carlosdanielhernandezmena commited on
Commit
87d6ef3
·
1 Parent(s): d50d4d6

Adding files to the repo for the first time

Browse files
corpus/files/metadata_train.tsv ADDED
The diff for this file is too large to render. See raw diff
 
corpus/files/tars_train.paths ADDED
@@ -0,0 +1 @@
 
 
1
+ corpus/speech/train.tar.gz
corpus/speech/remover.txt ADDED
File without changes
tele_con_ciencia.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from collections import defaultdict
2
+ import os
3
+ import json
4
+ import csv
5
+
6
+ import datasets
7
+
8
+ _NAME="tele_con_ciencia"
9
+ _VERSION="1.0.0"
10
+
11
+ _DESCRIPTION = """
12
+ TELEconCIENCIA SPANISH CORPUS. Audio and Transcripts in Spanish in a
13
+ CIEMPIESS Corpus style, taken from the radio program Tele con Ciencia
14
+ by CONACYT.
15
+ """
16
+
17
+ _CITATION = """
18
+ @misc{carlosmenaciempiesslight2017,
19
+ title={TELEconCIENCIA SPANISH CORPUS: Audio and Transcripts in Spanish taken from broadcast radio programs.},
20
+ author={Hernandez Mena, Carlos Daniel},
21
+ year={2019},
22
+ url={https://huggingface.co/ciempiess/tele_con_ciencia},
23
+ }
24
+ """
25
+
26
+ _HOMEPAGE = "https://huggingface.co/ciempiess/tele_con_ciencia"
27
+
28
+ _LICENSE = "CC-BY-SA-4.0, See https://creativecommons.org/licenses/by-sa/4.0/"
29
+
30
+ _BASE_DATA_DIR = "corpus/"
31
+ _METADATA_TRAIN = os.path.join(_BASE_DATA_DIR,"files", "metadata_train.tsv")
32
+
33
+ _TARS_TRAIN = os.path.join(_BASE_DATA_DIR,"files", "tars_train.paths")
34
+
35
+ class TeleconCienciaConfig(datasets.BuilderConfig):
36
+ """BuilderConfig for TELEconCIENCIA SPANISH CORPUS"""
37
+
38
+ def __init__(self, name, **kwargs):
39
+ name=_NAME
40
+ super().__init__(name=name, **kwargs)
41
+
42
+ class TeleconCiencia(datasets.GeneratorBasedBuilder):
43
+ """TELEconCIENCIA SPANISH CORPUS"""
44
+
45
+ VERSION = datasets.Version(_VERSION)
46
+ BUILDER_CONFIGS = [
47
+ TeleconCienciaConfig(
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_train=dl_manager.download_and_extract(_METADATA_TRAIN)
75
+
76
+ tars_train=dl_manager.download_and_extract(_TARS_TRAIN)
77
+
78
+ hash_tar_files=defaultdict(dict)
79
+
80
+ with open(tars_train,'r') as f:
81
+ hash_tar_files['train']=[path.replace('\n','') for path in f]
82
+
83
+ hash_meta_paths={"train":metadata_train}
84
+ audio_paths = dl_manager.download(hash_tar_files)
85
+
86
+ splits=["train"]
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.TRAIN,
97
+ gen_kwargs={
98
+ "audio_archives": [dl_manager.iter_archive(archive) for archive in audio_paths["train"]],
99
+ "local_extracted_archives_paths": local_extracted_audio_paths["train"],
100
+ "metadata_paths": hash_meta_paths["train"],
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
+
113
+
114
+ for audio_archive, local_extracted_archive_path in zip(audio_archives, local_extracted_archives_paths):
115
+ for audio_filename, audio_file in audio_archive:
116
+ audio_id =os.path.splitext(os.path.basename(audio_filename))[0]
117
+ path = os.path.join(local_extracted_archive_path, audio_filename) if local_extracted_archive_path else audio_filename
118
+
119
+ yield audio_id, {
120
+ "audio_id": audio_id,
121
+ **{feature: metadata[audio_id][feature] for feature in features},
122
+ "audio": {"path": path, "bytes": audio_file.read()},
123
+ }