Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for kaldi-io #4042

Merged
merged 2 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, kaldiio, and pydub" if HAVE_PYDUB else "soundfile"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"soundfile, kaldiio, and pydub" -> "soundfile, and pydub"
Need to drop kaldio here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

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