Datasets:
LIUM
/

sanchit-gandhi commited on
Commit
55cde07
·
1 Parent(s): 2fc08d0

fix sampling rate bug

Browse files
Files changed (1) hide show
  1. tedlium.py +5 -6
tedlium.py CHANGED
@@ -287,7 +287,7 @@ class TedLium(datasets.GeneratorBasedBuilder):
287
  speaker_file = fn
288
  audio_file = os.path.join(split_dir, speaker_file + ".sph")
289
  segment, sampling_rate = sf.read(audio_file, dtype=np.int16)
290
- samples = _extract_audio_segment(segment, int(channel), float(start), float(end))
291
  key = "-".join([speaker, start, end, label])
292
  example = {
293
  "audio": {"path": audio_file, "array": samples, "sampling_rate": sampling_rate},
@@ -368,13 +368,12 @@ def _maybe_trim_suffix(transcript):
368
  return transcript
369
 
370
 
371
- def _extract_audio_segment(segment, channel, start_sec, end_sec):
372
  """Extracts segment of audio samples (as an ndarray) from the given segment."""
373
  # The dataset only contains mono audio.
374
- assert channel == 1
375
- start_ms = int(start_sec * 1000)
376
- end_ms = int(end_sec * 1000)
377
- samples = segment[start_ms:end_ms]
378
  return samples
379
 
380
 
 
287
  speaker_file = fn
288
  audio_file = os.path.join(split_dir, speaker_file + ".sph")
289
  segment, sampling_rate = sf.read(audio_file, dtype=np.int16)
290
+ samples = _extract_audio_segment(segment, sampling_rate, float(start), float(end))
291
  key = "-".join([speaker, start, end, label])
292
  example = {
293
  "audio": {"path": audio_file, "array": samples, "sampling_rate": sampling_rate},
 
368
  return transcript
369
 
370
 
371
+ def _extract_audio_segment(segment, sampling_rate, start_sec, end_sec):
372
  """Extracts segment of audio samples (as an ndarray) from the given segment."""
373
  # The dataset only contains mono audio.
374
+ start_sample = int(start_sec * sampling_rate)
375
+ end_sample = min(int(end_sec * sampling_rate), segment.shape[0])
376
+ samples = segment[start_sample:end_sample]
 
377
  return samples
378
 
379