Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 15 additions & 10 deletions src/torchaudio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,21 @@ def load(
- Not all audio formats supported by torchaudio backends may be supported
by TorchCodec.
"""
return load_with_torchcodec(
uri,
frame_offset=frame_offset,
num_frames=num_frames,
normalize=normalize,
channels_first=channels_first,
format=format,
buffer_size=buffer_size,
backend=backend,
)
try:
return load_with_torchcodec(
uri,
frame_offset=frame_offset,
num_frames=num_frames,
normalize=normalize,
channels_first=channels_first,
format=format,
buffer_size=buffer_size,
backend=backend,
)
except Exception as e:
if str(uri) not in str(e):
raise type(e)(f"Failed to load audio from {uri}: {e}") from e
raise


def save(
Expand Down
4 changes: 2 additions & 2 deletions src/torchaudio/_torchcodec.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ def load_with_torchcodec(
# Get sample rate from metadata
sample_rate = decoder.metadata.sample_rate
if sample_rate is None:
raise RuntimeError("Unable to determine sample rate from audio metadata")
raise RuntimeError(f"Unable to determine sample rate from audio metadata for {uri}")

# Decode the entire file first, then subsample manually
# This is the simplest approach since torchcodec uses time-based indexing
try:
audio_samples = decoder.get_all_samples()
except Exception as e:
raise RuntimeError(f"Failed to decode audio samples: {e}") from e
raise RuntimeError(f"Failed to decode audio samples from {uri}: {e}") from e

data = audio_samples.data

Expand Down