gigant commited on
Commit
789df26
1 Parent(s): 8612f54

Upload african_accented_french.py

Browse files
Files changed (1) hide show
  1. african_accented_french.py +106 -0
african_accented_french.py ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # This script for Hugging Face's datasets library was written by Théo Gigant
3
+
4
+
5
+ import csv
6
+ import json
7
+ import os
8
+ from pathlib import Path
9
+ import datasets
10
+
11
+ _CITATION = """\
12
+
13
+ """
14
+
15
+ _DESCRIPTION = """\
16
+ This corpus consists of approximately 22 hours of speech recordings. Transcripts are provided for all the recordings. The corpus can be divided into 3 parts:
17
+
18
+ 1. Yaounde
19
+
20
+ Collected by a team from the U.S. Military Academy's Center for Technology Enhanced Language Learning (CTELL) in 2003 in Yaoundé, Cameroon. It has recordings from 84 speakers, 48 male and 36 female.
21
+
22
+ 2. CA16
23
+
24
+ This part was collected by a RDECOM Science Team who participated in the United Nations exercise Central Accord 16 (CA16) in Libreville, Gabon in June 2016. The Science Team included DARPA's Dr. Boyan Onyshkevich and Dr. Aaron Lawson (SRI International), as well as RDECOM scientists. It has recordings from 125 speakers from Cameroon, Chad, Congo and Gabon.
25
+
26
+ 3. Niger
27
+
28
+ This part was collected from 23 speakers in Niamey, Niger, Oct. 26-30 2015. These speakers were students in a course for officers and sergeants presented by Army trainers assigned to U.S. Army Africa. The data was collected by RDECOM Science & Technology Advisors Major Eddie Strimel and Mr. Bill Bergen.
29
+ """
30
+
31
+ _HOMEPAGE = "http://www.openslr.org/57/"
32
+
33
+ _LICENSE = ""
34
+
35
+ _URLS = {
36
+ "fr": "https://www.openslr.org/resources/57/African_Accented_French.tar.gz",
37
+ }
38
+
39
+ class AfricanAccentedFrench(datasets.GeneratorBasedBuilder):
40
+
41
+ VERSION = datasets.Version("1.0.0")
42
+
43
+ BUILDER_CONFIGS = [
44
+ datasets.BuilderConfig(name="fr", version=VERSION, description=""),
45
+ ]
46
+
47
+ DEFAULT_CONFIG_NAME = "fr"
48
+
49
+ def _info(self):
50
+ features = datasets.Features(
51
+ {
52
+ "sentence": datasets.Value("string"),
53
+ "audio": datasets.features.Audio(sampling_rate=16_000),
54
+ }
55
+ )
56
+ return datasets.DatasetInfo(
57
+ description=_DESCRIPTION,
58
+ features=features,
59
+ homepage=_HOMEPAGE,
60
+ license=_LICENSE,
61
+ citation=_CITATION,
62
+ )
63
+
64
+ def _split_generators(self, dl_manager):
65
+ urls = _URLS[self.config.name]
66
+ data_dir = dl_manager.download_and_extract(urls)
67
+ return [
68
+ datasets.SplitGenerator(
69
+ name=datasets.Split.TRAIN,
70
+ gen_kwargs={
71
+ "datapath": data_dir,
72
+ "split": "train"
73
+ },
74
+ ),
75
+ datasets.SplitGenerator(
76
+ name=datasets.Split.TEST,
77
+ gen_kwargs={
78
+ "datapath": data_dir,
79
+ "split": "test"
80
+ },
81
+ ),
82
+ ]
83
+
84
+ def _generate_examples(self, datapath, split):
85
+ key = 0
86
+ files = {}
87
+ for split_name in ["train"] if split=="train" else ["test", "devtest", "dev"]:
88
+ for speaker in os.listdir(os.path.join(datapath, "African_Accented_French", "transcripts", split_name)):
89
+ for meta in os.listdir(os.path.join(datapath,"African_Accented_French", "transcripts", split_name, speaker)):
90
+ with open(os.path.join(datapath,"African_Accented_French", "transcripts", split_name, speaker, meta), 'r') as transcript:
91
+ for line in transcript.readlines():
92
+ line = line.split(maxsplit=1)
93
+ if "answers" not in line[0]:
94
+ filename = line[0].split("/")[-1]
95
+ if ".tdf" in filename or ".wav" in filename:
96
+ filename = f"{filename[:-4]}.wav"
97
+ else :
98
+ filename = f"{filename}.wav"
99
+ files[filename]= line[1]
100
+ for f in Path(os.path.join(datapath, "African_Accented_French")).rglob("*.wav"):
101
+ if f.name in files.keys():
102
+ yield key, {
103
+ "sentence": files[f.name],
104
+ "audio": f.absolute().as_posix()
105
+ }
106
+ key += 1