Update ESLO.py
Browse files
ESLO.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import os
|
2 |
import re
|
3 |
from ctypes import Array
|
@@ -24,7 +26,7 @@ _DESCRIPTION = """\
|
|
24 |
ESLO dataset, each utterance are taken out individually
|
25 |
"""
|
26 |
SAMPLING_RATE = 16000
|
27 |
-
AUDIO_FOLDER = "audio"
|
28 |
AUDIO_FILES = ['ESLO2_ITI_1073.mp4', 'ESLO1_ENT_117.mp4', 'ESLO1_ENT_103.mp4', 'ESLO2_ITI_1098.mp4',
|
29 |
'ESLO1_ENTCONT_237.mp4', 'ESLO1_ENTCONT_223.mp4', 'ESLO2_RUMEUR_1339.mp4', 'ESLO2_INTPERS_1245.mp4',
|
30 |
'ESLO1_TEL_364.mp4', 'ESLO2_ITI_1107.mp4', 'ESLO1_CONF_503.mp4', 'ESLO1_MAG_631.mp4',
|
@@ -261,8 +263,8 @@ class MultilingualLibrispeech(datasets.GeneratorBasedBuilder):
|
|
261 |
def _split_generators(self, dl_manager):
|
262 |
|
263 |
transcripts = dl_manager.download({
|
264 |
-
"train": "transcripts_deduplicated_train.zip",
|
265 |
-
"test": "transcripts_deduplicated_test.zip",
|
266 |
})
|
267 |
audio_files = dl_manager.download(
|
268 |
{audio_file: os.path.join(AUDIO_FOLDER, audio_file) for audio_file in AUDIO_FILES})
|
@@ -297,7 +299,7 @@ class MultilingualLibrispeech(datasets.GeneratorBasedBuilder):
|
|
297 |
|
298 |
def clean_text(self, text: str) -> str:
|
299 |
def replace_uppercase(match):
|
300 |
-
"""replaces BRUNO spelling
|
301 |
return ' '.join(match.group(1))
|
302 |
|
303 |
text = re.sub(r"\bNPERS\b", "", text)
|
@@ -321,7 +323,7 @@ class MultilingualLibrispeech(datasets.GeneratorBasedBuilder):
|
|
321 |
end_time = float(turn.get('endTime'))
|
322 |
text = re.sub(r"[\r\n\s]+", " ", MultilingualLibrispeech.extract_text(turn).strip())
|
323 |
text = self.clean_text(text)
|
324 |
-
if text:
|
325 |
utts.append(Utterance(
|
326 |
speaker=speaker,
|
327 |
sentence=text,
|
@@ -337,7 +339,7 @@ class MultilingualLibrispeech(datasets.GeneratorBasedBuilder):
|
|
337 |
Open an audio file and read as mono waveform, resampling as necessary
|
338 |
Parameters
|
339 |
----------
|
340 |
-
file:
|
341 |
sr: int
|
342 |
The sample rate to resample the audio if necessary
|
343 |
Returns
|
@@ -361,6 +363,7 @@ class MultilingualLibrispeech(datasets.GeneratorBasedBuilder):
|
|
361 |
return audio[int(round(start_timestamp * SAMPLING_RATE)): int(round(end_timestamp * SAMPLING_RATE)) + 1]
|
362 |
|
363 |
def _generate_examples(self, transcripts_paths, audio_files):
|
|
|
364 |
for path, file in transcripts_paths:
|
365 |
file_name = os.path.splitext(os.path.basename(path))[0][:-2]
|
366 |
audio_path = f"{file_name}.mp4"
|
@@ -368,14 +371,13 @@ class MultilingualLibrispeech(datasets.GeneratorBasedBuilder):
|
|
368 |
for utterance in self.load_one(file):
|
369 |
if not self.config.overlap and utterance.overlap:
|
370 |
continue
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
"sampling_rate": 16000}}
|
|
|
1 |
+
"""Multilingual Librispeech automatic speech recognition dataset."""
|
2 |
+
|
3 |
import os
|
4 |
import re
|
5 |
from ctypes import Array
|
|
|
26 |
ESLO dataset, each utterance are taken out individually
|
27 |
"""
|
28 |
SAMPLING_RATE = 16000
|
29 |
+
AUDIO_FOLDER = "/Users/brunohays/datalab/épellations/Scrapping/ortolang_datasets/eslo/downloads/audio"
|
30 |
AUDIO_FILES = ['ESLO2_ITI_1073.mp4', 'ESLO1_ENT_117.mp4', 'ESLO1_ENT_103.mp4', 'ESLO2_ITI_1098.mp4',
|
31 |
'ESLO1_ENTCONT_237.mp4', 'ESLO1_ENTCONT_223.mp4', 'ESLO2_RUMEUR_1339.mp4', 'ESLO2_INTPERS_1245.mp4',
|
32 |
'ESLO1_TEL_364.mp4', 'ESLO2_ITI_1107.mp4', 'ESLO1_CONF_503.mp4', 'ESLO1_MAG_631.mp4',
|
|
|
263 |
def _split_generators(self, dl_manager):
|
264 |
|
265 |
transcripts = dl_manager.download({
|
266 |
+
"train": "/Users/brunohays/datalab/épellations/Scrapping/ortolang_datasets/eslo/downloads/transcripts_deduplicated_train.zip",
|
267 |
+
"test": "/Users/brunohays/datalab/épellations/Scrapping/ortolang_datasets/eslo/downloads/transcripts_deduplicated_test.zip",
|
268 |
})
|
269 |
audio_files = dl_manager.download(
|
270 |
{audio_file: os.path.join(AUDIO_FOLDER, audio_file) for audio_file in AUDIO_FILES})
|
|
|
299 |
|
300 |
def clean_text(self, text: str) -> str:
|
301 |
def replace_uppercase(match):
|
302 |
+
"""replaces BRUNO spelling by B R U N O"""
|
303 |
return ' '.join(match.group(1))
|
304 |
|
305 |
text = re.sub(r"\bNPERS\b", "", text)
|
|
|
323 |
end_time = float(turn.get('endTime'))
|
324 |
text = re.sub(r"[\r\n\s]+", " ", MultilingualLibrispeech.extract_text(turn).strip())
|
325 |
text = self.clean_text(text)
|
326 |
+
if any(c.isalnum() for c in text):
|
327 |
utts.append(Utterance(
|
328 |
speaker=speaker,
|
329 |
sentence=text,
|
|
|
339 |
Open an audio file and read as mono waveform, resampling as necessary
|
340 |
Parameters
|
341 |
----------
|
342 |
+
file:vThe audio file to read
|
343 |
sr: int
|
344 |
The sample rate to resample the audio if necessary
|
345 |
Returns
|
|
|
363 |
return audio[int(round(start_timestamp * SAMPLING_RATE)): int(round(end_timestamp * SAMPLING_RATE)) + 1]
|
364 |
|
365 |
def _generate_examples(self, transcripts_paths, audio_files):
|
366 |
+
"""Generate examples from a Multilingual LibriSpeech data dir."""
|
367 |
for path, file in transcripts_paths:
|
368 |
file_name = os.path.splitext(os.path.basename(path))[0][:-2]
|
369 |
audio_path = f"{file_name}.mp4"
|
|
|
371 |
for utterance in self.load_one(file):
|
372 |
if not self.config.overlap and utterance.overlap:
|
373 |
continue
|
374 |
+
yield f"{file_name}_{utterance.start_timestamp}-{utterance.end_timestamp}", {
|
375 |
+
"file": file_name,
|
376 |
+
"sentence": utterance.sentence,
|
377 |
+
"start_timestamp": utterance.start_timestamp,
|
378 |
+
"end_timestamp": utterance.end_timestamp,
|
379 |
+
"speaker": utterance.speaker,
|
380 |
+
"overlap": utterance.overlap,
|
381 |
+
"audio": {"path": audio_path,
|
382 |
+
"array": self._cut_audio(audio, utterance.start_timestamp, utterance.end_timestamp),
|
383 |
+
"sampling_rate": 16000}}
|
|