bjelkenhed
commited on
Commit
•
78b142c
1
Parent(s):
b43e032
speaker_id, sex and accent
Browse files- babelbox_voice.py +42 -8
babelbox_voice.py
CHANGED
@@ -69,7 +69,10 @@ class BabelboxVoice(datasets.GeneratorBasedBuilder):
|
|
69 |
{
|
70 |
"path": datasets.Value("string"),
|
71 |
"audio": datasets.features.Audio(sampling_rate=16_000),
|
72 |
-
"sentence": datasets.Value("string")
|
|
|
|
|
|
|
73 |
}
|
74 |
)
|
75 |
else:
|
@@ -77,7 +80,10 @@ class BabelboxVoice(datasets.GeneratorBasedBuilder):
|
|
77 |
{
|
78 |
"path": datasets.Value("string"),
|
79 |
"audio": datasets.features.Audio(sampling_rate=16_000),
|
80 |
-
"sentence": datasets.Value("string")
|
|
|
|
|
|
|
81 |
}
|
82 |
)
|
83 |
|
@@ -94,14 +100,28 @@ class BabelboxVoice(datasets.GeneratorBasedBuilder):
|
|
94 |
metadata_path = dl_manager.download(metadata_url)
|
95 |
local_extracted_metadata_path = dl_manager.extract(metadata_path) if not dl_manager.is_streaming else None
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
metadata_archive = dl_manager.iter_archive(metadata_path)
|
98 |
metadata = {}
|
99 |
for path, file in metadata_archive:
|
100 |
reader = csv.DictReader(codecs.iterdecode(file, 'utf-8'))
|
101 |
for row in tqdm(reader, desc="Reading metadata..."):
|
102 |
filename = row['filename_channel_1']
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
return metadata
|
107 |
|
@@ -128,14 +148,28 @@ class BabelboxVoice(datasets.GeneratorBasedBuilder):
|
|
128 |
def _generate_examples(self, local_extracted_archive_paths, archives, metadata):
|
129 |
|
130 |
sampling_rate = 16000
|
|
|
|
|
|
|
|
|
131 |
|
132 |
for i, audio_archive in enumerate(archives):
|
133 |
for path, file in audio_archive:
|
134 |
if local_extracted_archive_paths == False:
|
135 |
path = os.path.join(local_extracted_archive_paths[i], path)
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
yield path, result
|
141 |
|
|
|
69 |
{
|
70 |
"path": datasets.Value("string"),
|
71 |
"audio": datasets.features.Audio(sampling_rate=16_000),
|
72 |
+
"sentence": datasets.Value("string"),
|
73 |
+
"speaker_id": datasets.Value("string"),
|
74 |
+
"sex": datasets.Value("string"),
|
75 |
+
"accent": datasets.Value("string"),
|
76 |
}
|
77 |
)
|
78 |
else:
|
|
|
80 |
{
|
81 |
"path": datasets.Value("string"),
|
82 |
"audio": datasets.features.Audio(sampling_rate=16_000),
|
83 |
+
"sentence": datasets.Value("string"),
|
84 |
+
"speaker_id": datasets.Value("string"),
|
85 |
+
"sex": datasets.Value("string"),
|
86 |
+
"accent": datasets.Value("string"),
|
87 |
}
|
88 |
)
|
89 |
|
|
|
100 |
metadata_path = dl_manager.download(metadata_url)
|
101 |
local_extracted_metadata_path = dl_manager.extract(metadata_path) if not dl_manager.is_streaming else None
|
102 |
|
103 |
+
|
104 |
+
def clean_sentence(sentence):
|
105 |
+
return (sentence
|
106 |
+
.replace("\\Komma", "",)
|
107 |
+
.replace("\\Punkt", "")
|
108 |
+
.replace("\\Utropstecken", "")
|
109 |
+
.replace("\\Frågetecken", ""))
|
110 |
+
|
111 |
metadata_archive = dl_manager.iter_archive(metadata_path)
|
112 |
metadata = {}
|
113 |
for path, file in metadata_archive:
|
114 |
reader = csv.DictReader(codecs.iterdecode(file, 'utf-8'))
|
115 |
for row in tqdm(reader, desc="Reading metadata..."):
|
116 |
filename = row['filename_channel_1']
|
117 |
+
metadata_item = {
|
118 |
+
'sentence': clean_sentence(row['text']),
|
119 |
+
'speaker_id': row['Speaker_ID'],
|
120 |
+
'sex': row['Sex'],
|
121 |
+
'accent': row['Region_of_Youth']
|
122 |
+
}
|
123 |
+
|
124 |
+
metadata[filename] = metadata_item
|
125 |
|
126 |
return metadata
|
127 |
|
|
|
148 |
def _generate_examples(self, local_extracted_archive_paths, archives, metadata):
|
149 |
|
150 |
sampling_rate = 16000
|
151 |
+
|
152 |
+
def filter_sentence(sentence):
|
153 |
+
if "... tyst under denna inspelning ..." in sentence: return False
|
154 |
+
return True
|
155 |
|
156 |
for i, audio_archive in enumerate(archives):
|
157 |
for path, file in audio_archive:
|
158 |
if local_extracted_archive_paths == False:
|
159 |
path = os.path.join(local_extracted_archive_paths[i], path)
|
160 |
+
|
161 |
+
metadata_item = metadata[path]
|
162 |
+
|
163 |
+
if filter_sentence(metadata_item['sentence']) == False: continue
|
164 |
+
|
165 |
+
result = {
|
166 |
+
'path' : path,
|
167 |
+
'audio' : {"path": path, "bytes": file.read() },
|
168 |
+
'sentence' : metadata_item['sentence'],
|
169 |
+
'speaker_id' : metadata_item['speaker_id'],
|
170 |
+
'sex' : metadata_item['sex'],
|
171 |
+
'accent' : metadata_item['accent']
|
172 |
+
}
|
173 |
+
|
174 |
yield path, result
|
175 |
|