Skip to content

Commit

Permalink
Drop support for kaldi-io (#4042)
Browse files Browse the repository at this point in the history
* Drop support for kaldi-io

Signed-off-by: smajumdar <titu1994@gmail.com>

* Remove kaldiio from list

Signed-off-by: smajumdar <titu1994@gmail.com>
  • Loading branch information
titu1994 committed Apr 22, 2022
1 parent ea201d2 commit 431c561
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
20 changes: 4 additions & 16 deletions nemo/collections/asr/parts/preprocessing/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@
from nemo.utils import logging

# TODO @blisc: Perhaps refactor instead of import guarding
HAVE_KALDI_PYDUB = True
HAVE_PYDUB = True
try:
from kaldiio.matio import read_kaldi
from kaldiio.utils import open_like_kaldi
from pydub import AudioSegment as Audio
from pydub.exceptions import CouldntDecodeError
except ModuleNotFoundError:
HAVE_KALDI_PYDUB = False
HAVE_PYDUB = False


available_formats = sf.available_formats()
Expand Down Expand Up @@ -156,18 +154,8 @@ def from_file(
f"Loading {audio_file} via SoundFile raised RuntimeError: `{e}`. "
f"NeMo will fallback to loading via pydub."
)
elif HAVE_KALDI_PYDUB and isinstance(audio_file, str) and audio_file.strip()[-1] == "|":
f = open_like_kaldi(audio_file, "rb")
sample_rate, samples = read_kaldi(f)
if offset > 0:
samples = samples[int(offset * sample_rate) :]
if duration > 0:
samples = samples[: int(duration * sample_rate)]
if not int_values:
abs_max_value = np.abs(samples).max()
samples = np.array(samples, dtype=np.float) / abs_max_value

if HAVE_KALDI_PYDUB and samples is None:
if HAVE_PYDUB and samples is None:
try:
samples = Audio.from_file(audio_file)
sample_rate = samples.frame_rate
Expand All @@ -183,7 +171,7 @@ def from_file(
logging.error(f"Loading {audio_file} via pydub raised CouldntDecodeError: `{err}`.")

if samples is None:
libs = "soundfile, kaldiio, and pydub" if HAVE_KALDI_PYDUB else "soundfile"
libs = "soundfile, and pydub" if HAVE_PYDUB else "soundfile"
raise Exception(f"Your audio file {audio_file} could not be decoded. We tried using {libs}.")

return cls(samples, sample_rate, target_sr=target_sr, trim=trim, orig_sr=orig_sr)
Expand Down
1 change: 0 additions & 1 deletion requirements/requirements_asr.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
braceexpand
editdistance
inflect
kaldi-io
librosa
marshmallow
packaging
Expand Down

0 comments on commit 431c561

Please sign in to comment.