Update ESLO_text_only.py
Browse files- ESLO_text_only.py +3 -56
ESLO_text_only.py
CHANGED
@@ -1,13 +1,10 @@
|
|
1 |
import os
|
2 |
import re
|
3 |
-
from ctypes import Array
|
4 |
from dataclasses import dataclass
|
5 |
from typing import List
|
6 |
import xml.etree.ElementTree as ET
|
7 |
-
import ffmpeg
|
8 |
|
9 |
import datasets
|
10 |
-
import numpy as np
|
11 |
|
12 |
_CITATION = """\
|
13 |
@misc{11403/eslo/v1,
|
@@ -23,8 +20,6 @@ _CITATION = """\
|
|
23 |
_DESCRIPTION = """\
|
24 |
ESLO dataset, each utterance are taken out individually
|
25 |
"""
|
26 |
-
SAMPLING_RATE = 16000
|
27 |
-
AUDIO_FOLDER = "audio"
|
28 |
TEST_TRANSCRIPTS = ['ESLO2_ENT_1052_C.trs', 'ESLO1_ENT_026_C.trs', 'ESLO2_ECOLE_1280_C.trs', 'ESLO1_CONSCMPP_727_C.trs',
|
29 |
'ESLO1_ENT_002_C.trs', 'ESLO1_TEL_338_C.trs', 'ESLO1_ENTCONT_213_C.trs', 'ESLO1_INTPERS_449_C.trs',
|
30 |
'ESLO1_CONSCMPP_740_C.trs', 'ESLO2_ENT_1008_C.trs', 'ESLO2_REPAS_1268_C.trs',
|
@@ -236,10 +231,6 @@ class ESLOConfig(datasets.BuilderConfig):
|
|
236 |
super(ESLOConfig, self).__init__(
|
237 |
version=datasets.Version("2.11.0", ""), name=name, **kwargs
|
238 |
)
|
239 |
-
if "no_overlap" in name:
|
240 |
-
self.overlap = False
|
241 |
-
else:
|
242 |
-
self.overlap = True
|
243 |
if "no_hesitation" in name:
|
244 |
self.hesitation = False
|
245 |
else:
|
@@ -250,14 +241,11 @@ class ESLO(datasets.GeneratorBasedBuilder):
|
|
250 |
"""ESLO dataset."""
|
251 |
|
252 |
BUILDER_CONFIGS = [
|
253 |
-
ESLOConfig(name="no_overlap_no_hesitation", description="ESLO dataset, removed hesitations from samples"
|
254 |
-
" and all samples with overlap"),
|
255 |
ESLOConfig(name="no_hesitation", description="ESLO dataset, removed hesitations from samples"),
|
256 |
-
ESLOConfig(name="no_overlap", description="ESLO dataset, removed all samples with overlap"),
|
257 |
ESLOConfig(name="raw", description="ESLO dataset"),
|
258 |
]
|
259 |
|
260 |
-
DEFAULT_CONFIG_NAME = "
|
261 |
|
262 |
def _info(self):
|
263 |
return datasets.DatasetInfo(
|
@@ -265,7 +253,6 @@ class ESLO(datasets.GeneratorBasedBuilder):
|
|
265 |
features=datasets.Features(
|
266 |
{
|
267 |
"file": datasets.Value("string"),
|
268 |
-
"audio": datasets.features.Audio(sampling_rate=SAMPLING_RATE),
|
269 |
"sentence": datasets.Value("string"),
|
270 |
"speaker": datasets.Value("string"),
|
271 |
"start_timestamp": datasets.Value("float"),
|
@@ -283,26 +270,18 @@ class ESLO(datasets.GeneratorBasedBuilder):
|
|
283 |
transcripts_test = dl_manager.download(
|
284 |
[os.path.join("transcripts_deduplicated_test", transcript) for transcript in
|
285 |
TEST_TRANSCRIPTS])
|
286 |
-
train_filenames = [os.path.splitext(transcript)[0] for transcript in TRAIN_TRANSCRIPTS]
|
287 |
-
test_filenames = [os.path.splitext(transcript)[0] for transcript in TEST_TRANSCRIPTS]
|
288 |
-
audio_train = dl_manager.download(
|
289 |
-
{transcript: f"audio/{transcript[:-2]}.mp4" for transcript in train_filenames})
|
290 |
-
audio_test = dl_manager.download(
|
291 |
-
{transcript: f"audio/{transcript[:-2]}.mp4" for transcript in test_filenames})
|
292 |
|
293 |
splits = [
|
294 |
datasets.SplitGenerator(
|
295 |
name=datasets.Split.TRAIN,
|
296 |
gen_kwargs={
|
297 |
"transcripts": transcripts_train,
|
298 |
-
"audio_files": audio_train
|
299 |
}
|
300 |
),
|
301 |
datasets.SplitGenerator(
|
302 |
name=datasets.Split.TEST,
|
303 |
gen_kwargs={
|
304 |
"transcripts": transcripts_test,
|
305 |
-
"audio_files": audio_test
|
306 |
}
|
307 |
),
|
308 |
|
@@ -355,40 +334,11 @@ class ESLO(datasets.GeneratorBasedBuilder):
|
|
355 |
))
|
356 |
return utts
|
357 |
|
358 |
-
@staticmethod
|
359 |
-
def load_audio(file: str, sr: int = SAMPLING_RATE):
|
360 |
-
"""
|
361 |
-
Open an audio file and read as mono waveform, resampling as necessary
|
362 |
-
Parameters
|
363 |
-
----------
|
364 |
-
file:vThe audio file to read
|
365 |
-
sr: int
|
366 |
-
The sample rate to resample the audio if necessary
|
367 |
-
Returns
|
368 |
-
-------
|
369 |
-
A NumPy array containing the audio waveform, in float32 dtype.
|
370 |
-
"""
|
371 |
-
try:
|
372 |
-
# This launches a subprocess to decode audio while down-mixing and resampling as necessary.
|
373 |
-
# Requires the ffmpeg CLI and `ffmpeg-python` package to be installed.
|
374 |
-
out, _ = (
|
375 |
-
ffmpeg.input(file)
|
376 |
-
.output('-', format='s16le', acodec='pcm_s16le', ac=1, ar=sr)
|
377 |
-
.run(capture_stdout=True, capture_stderr=True)
|
378 |
-
)
|
379 |
-
except ffmpeg.Error as e:
|
380 |
-
raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e
|
381 |
-
return np.frombuffer(out, np.int16).flatten().astype(np.float32) / 32768.0
|
382 |
-
|
383 |
-
@staticmethod
|
384 |
-
def _cut_audio(audio: Array, start_timestamp: float, end_timestamp: float):
|
385 |
-
return audio[int(round(start_timestamp * SAMPLING_RATE)): int(round(end_timestamp * SAMPLING_RATE)) + 1]
|
386 |
|
387 |
-
def _generate_examples(self, transcripts
|
388 |
"""Generate examples from a Multilingual LibriSpeech data dir."""
|
389 |
for path in transcripts:
|
390 |
transcript_name = os.path.splitext(os.path.basename(path))[0]
|
391 |
-
audio = self.load_audio(audio_files[transcript_name])
|
392 |
with open(path, "rb") as file:
|
393 |
for utterance in self.load_one(file):
|
394 |
if not self.config.overlap and utterance.overlap:
|
@@ -399,7 +349,4 @@ class ESLO(datasets.GeneratorBasedBuilder):
|
|
399 |
"start_timestamp": utterance.start_timestamp,
|
400 |
"end_timestamp": utterance.end_timestamp,
|
401 |
"speaker": utterance.speaker,
|
402 |
-
"overlap": utterance.overlap
|
403 |
-
"audio": {"path": transcript_name,
|
404 |
-
"array": self._cut_audio(audio, utterance.start_timestamp, utterance.end_timestamp),
|
405 |
-
"sampling_rate": 16000}}
|
|
|
1 |
import os
|
2 |
import re
|
|
|
3 |
from dataclasses import dataclass
|
4 |
from typing import List
|
5 |
import xml.etree.ElementTree as ET
|
|
|
6 |
|
7 |
import datasets
|
|
|
8 |
|
9 |
_CITATION = """\
|
10 |
@misc{11403/eslo/v1,
|
|
|
20 |
_DESCRIPTION = """\
|
21 |
ESLO dataset, each utterance are taken out individually
|
22 |
"""
|
|
|
|
|
23 |
TEST_TRANSCRIPTS = ['ESLO2_ENT_1052_C.trs', 'ESLO1_ENT_026_C.trs', 'ESLO2_ECOLE_1280_C.trs', 'ESLO1_CONSCMPP_727_C.trs',
|
24 |
'ESLO1_ENT_002_C.trs', 'ESLO1_TEL_338_C.trs', 'ESLO1_ENTCONT_213_C.trs', 'ESLO1_INTPERS_449_C.trs',
|
25 |
'ESLO1_CONSCMPP_740_C.trs', 'ESLO2_ENT_1008_C.trs', 'ESLO2_REPAS_1268_C.trs',
|
|
|
231 |
super(ESLOConfig, self).__init__(
|
232 |
version=datasets.Version("2.11.0", ""), name=name, **kwargs
|
233 |
)
|
|
|
|
|
|
|
|
|
234 |
if "no_hesitation" in name:
|
235 |
self.hesitation = False
|
236 |
else:
|
|
|
241 |
"""ESLO dataset."""
|
242 |
|
243 |
BUILDER_CONFIGS = [
|
|
|
|
|
244 |
ESLOConfig(name="no_hesitation", description="ESLO dataset, removed hesitations from samples"),
|
|
|
245 |
ESLOConfig(name="raw", description="ESLO dataset"),
|
246 |
]
|
247 |
|
248 |
+
DEFAULT_CONFIG_NAME = "raw"
|
249 |
|
250 |
def _info(self):
|
251 |
return datasets.DatasetInfo(
|
|
|
253 |
features=datasets.Features(
|
254 |
{
|
255 |
"file": datasets.Value("string"),
|
|
|
256 |
"sentence": datasets.Value("string"),
|
257 |
"speaker": datasets.Value("string"),
|
258 |
"start_timestamp": datasets.Value("float"),
|
|
|
270 |
transcripts_test = dl_manager.download(
|
271 |
[os.path.join("transcripts_deduplicated_test", transcript) for transcript in
|
272 |
TEST_TRANSCRIPTS])
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
|
274 |
splits = [
|
275 |
datasets.SplitGenerator(
|
276 |
name=datasets.Split.TRAIN,
|
277 |
gen_kwargs={
|
278 |
"transcripts": transcripts_train,
|
|
|
279 |
}
|
280 |
),
|
281 |
datasets.SplitGenerator(
|
282 |
name=datasets.Split.TEST,
|
283 |
gen_kwargs={
|
284 |
"transcripts": transcripts_test,
|
|
|
285 |
}
|
286 |
),
|
287 |
|
|
|
334 |
))
|
335 |
return utts
|
336 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
|
338 |
+
def _generate_examples(self, transcripts):
|
339 |
"""Generate examples from a Multilingual LibriSpeech data dir."""
|
340 |
for path in transcripts:
|
341 |
transcript_name = os.path.splitext(os.path.basename(path))[0]
|
|
|
342 |
with open(path, "rb") as file:
|
343 |
for utterance in self.load_one(file):
|
344 |
if not self.config.overlap and utterance.overlap:
|
|
|
349 |
"start_timestamp": utterance.start_timestamp,
|
350 |
"end_timestamp": utterance.end_timestamp,
|
351 |
"speaker": utterance.speaker,
|
352 |
+
"overlap": utterance.overlap}
|
|
|
|
|
|