Skip to content

Commit f74f004

Browse files
committed
Use existing wav_utils
1 parent 43c4602 commit f74f004

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

src/torchaudio/__init__.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,16 @@
4545
# CI cannot currently build with ffmpeg>4, but torchcodec is buggy with ffmpeg4. This hack
4646
# allows CI to build with ffmpeg4 and works around load/test bugginess.
4747
if "pytest" in sys.modules:
48-
from scipy.io import wavfile
48+
from torchaudio.utils import wav_utils
4949
def load(
50-
uri: Union[BinaryIO, str, os.PathLike],
51-
frame_offset: int = 0,
52-
num_frames: int = -1,
50+
uri: str,
51+
normalize: bool = True,
5352
channels_first: bool = True,
54-
format: Optional[str] = None,
55-
buffer_size: int = 4096,
56-
backend: Optional[str] = None,
5753
) -> Tuple[torch.Tensor, int]:
58-
rate, data = wavfile.read(uri)
59-
if data.ndim == 1:
60-
data = data[:,None]
61-
if num_frames == -1:
62-
num_frames = data.shape[0] - frame_offset
63-
data = data[frame_offset:frame_offset + num_frames]
64-
if channels_first:
65-
data = data.T
66-
return data, rate
54+
return wav_utils.load_wav(uri, normalize, channels_first)
6755

6856
def save(
69-
uri: Union[str, os.PathLike],
57+
uri: str,
7058
src: torch.Tensor,
7159
sample_rate: int,
7260
channels_first: bool = True,
@@ -77,7 +65,7 @@ def save(
7765
backend: Optional[str] = None,
7866
compression: Optional[Union[float, int]] = None,
7967
):
80-
wavfile.write(uri, sample_rate, src.numpy())
68+
wav_utils.save_wav(uri, src, sample_rate, channels_first=channels_first)
8169
else:
8270
def load(
8371
uri: Union[BinaryIO, str, os.PathLike],

test/torchaudio_unittest/common_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from .func_utils import torch_script
2727
from .image_utils import get_image, rgb_to_gray, rgb_to_yuv_ccir, save_image
2828
from .parameterized_utils import load_params, nested_params
29-
from .wav_utils import get_wav_data, load_wav, normalize_wav, save_wav
29+
from torchaudio.utils.wav_utils import get_wav_data, load_wav, normalize_wav, save_wav
3030
import pytest
3131

3232
class RequestMixin:

0 commit comments

Comments
 (0)