Skip to content

Commit 149492f

Browse files
committed
check if librosa is imported
1 parent b8a7a1b commit 149492f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

mltu/preprocessors.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ class AudioReader:
5959
"""
6060
try:
6161
import librosa
62-
except ImportError:
63-
raise ImportError("librosa is required to read Audio. Please install it with `pip install librosa`.")
62+
librosa.__version__
63+
except AttributeError:
64+
raise ImportError("librosa is required to read WAV files. Please install it with `pip install librosa`.")
6465

6566
def __init__(
6667
self,
@@ -104,10 +105,12 @@ class WavReader:
104105
frame_step (int): Step size between frames in samples.
105106
fft_length (int): Number of FFT components.
106107
"""
108+
# Check if librosa is installed
107109
try:
108110
import librosa
109-
except ImportError:
110-
raise ImportError("librosa is required to read Audio. Please install it with `pip install librosa`.")
111+
librosa.__version__
112+
except AttributeError:
113+
raise ImportError("librosa is required to read WAV files. Please install it with `pip install librosa`.")
111114

112115
def __init__(
113116
self,

0 commit comments

Comments
 (0)