From 13f0af7362fc422fc6cc77fc6d3f7cfe09014d4c Mon Sep 17 00:00:00 2001 From: Matthew McIntire Date: Mon, 7 Feb 2022 13:01:18 -0800 Subject: [PATCH] Allow file-like objects for WavAudio.read_file --- dragonfly/engines/backend_kaldi/audio.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dragonfly/engines/backend_kaldi/audio.py b/dragonfly/engines/backend_kaldi/audio.py index 89e2efa1..6b5db35a 100644 --- a/dragonfly/engines/backend_kaldi/audio.py +++ b/dragonfly/engines/backend_kaldi/audio.py @@ -444,8 +444,11 @@ class WavAudio(object): @classmethod def read_file(cls, filename, realtime=False): """ Yields raw audio blocks from wav file, terminated by a None element. """ - if not os.path.isfile(filename): - raise IOError("'%s' is not a file. Please use a different file path.") + try: + if not os.path.isfile(filename): + raise IOError("'%s' is not a file. Please use a different file path.") + except TypeError: + pass # Allow file-like objects with contextlib.closing(wave.open(filename, 'rb')) as file: # Validate the wave file's header