Skip to content

Commit 953fc65

Browse files
committed
Support frame_offset and num_frames in load hack
1 parent f74f004 commit 953fc65

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/torchaudio/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,18 @@
4848
from torchaudio.utils import wav_utils
4949
def load(
5050
uri: str,
51+
frame_offset: int = 0,
52+
num_frames: int = -1,
5153
normalize: bool = True,
5254
channels_first: bool = True,
5355
) -> Tuple[torch.Tensor, int]:
54-
return wav_utils.load_wav(uri, normalize, channels_first)
56+
data, sample_rate = wav_utils.load_wav(uri, normalize, channels_first=False)
57+
if num_frames == -1:
58+
num_frames = data.shape[0] - frame_offset
59+
data = data[frame_offset:frame_offset+num_frames]
60+
if channels_first:
61+
data = data.transpose(0, 1)
62+
return data, sample_rate
5563

5664
def save(
5765
uri: str,

0 commit comments

Comments
 (0)