Skip to content

Commit 1c38f95

Browse files
committed
Give installation error message if torchcodec not installed
1 parent 78bbf70 commit 1c38f95

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/torchaudio/utils/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
def load_torchcodec(file, normalize=True, channels_first=True, **args):
88
if not normalize:
99
raise Exception("Torchcodec does not support non-normalized file reading")
10-
from torchcodec.decoders import AudioDecoder
10+
try:
11+
from torchcodec.decoders import AudioDecoder
12+
except:
13+
raise Exception("To use this feature, you must install torchcodec. See https://github.com/pytorch/torchcodec for installation instructions")
1114
decoder = AudioDecoder(file)
1215
if 'start_seconds' in args or 'stop_seconds' in args:
1316
samples = decoder.get_samples_played_in_range(**args)

0 commit comments

Comments
 (0)