Update multilingual-TEDX-fr.py
Browse files- multilingual-TEDX-fr.py +23 -11
multilingual-TEDX-fr.py
CHANGED
@@ -9,6 +9,13 @@ import ffmpeg
|
|
9 |
import csv
|
10 |
import datasets
|
11 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
_CITATION = """\
|
14 |
@inproceedings{salesky2021mtedx,
|
@@ -201,17 +208,22 @@ class TEDX(datasets.GeneratorBasedBuilder):
|
|
201 |
#import librosa
|
202 |
#with open(file, "rb") as f:
|
203 |
# return librosa.load(f, sr=sr)
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
|
|
|
|
|
|
|
|
|
|
215 |
|
216 |
@staticmethod
|
217 |
def _cut_audio(audio: Array, start_timestamp: float, end_timestamp: float):
|
|
|
9 |
import csv
|
10 |
import datasets
|
11 |
import numpy as np
|
12 |
+
try:
|
13 |
+
import ffmpeg
|
14 |
+
FFMPEG_AVAILABLE = True
|
15 |
+
except ImportError:
|
16 |
+
import librosa
|
17 |
+
FFMPEG_AVAILABLE = False
|
18 |
+
|
19 |
|
20 |
_CITATION = """\
|
21 |
@inproceedings{salesky2021mtedx,
|
|
|
208 |
#import librosa
|
209 |
#with open(file, "rb") as f:
|
210 |
# return librosa.load(f, sr=sr)
|
211 |
+
if FFMPEG_AVAILABLE:
|
212 |
+
try:
|
213 |
+
# This launches a subprocess to decode audio while down-mixing and resampling as necessary.
|
214 |
+
# Requires the ffmpeg CLI and `ffmpeg-python` package to be installed.
|
215 |
+
out, _ = (
|
216 |
+
ffmpeg.input(file)
|
217 |
+
.output('-', format='s16le', acodec='pcm_s16le', ac=1, ar=sr)
|
218 |
+
.run(capture_stdout=True, capture_stderr=True)
|
219 |
+
)
|
220 |
+
except ffmpeg.Error as e:
|
221 |
+
raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e
|
222 |
+
return np.frombuffer(out, np.int16).flatten().astype(np.float32) / 32768.0
|
223 |
+
else:
|
224 |
+
with open(file, "rb") as f:
|
225 |
+
return librosa.load(f, sr=sr)
|
226 |
+
|
227 |
|
228 |
@staticmethod
|
229 |
def _cut_audio(audio: Array, start_timestamp: float, end_timestamp: float):
|