Skip to content

Commit

Permalink
Remove deprecated #load_wav functions from io backend classes
Browse files Browse the repository at this point in the history
  • Loading branch information
iseessel committed Mar 5, 2021
1 parent 64551a6 commit 84d3c88
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 65 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Comment on the issue that you want to work on it and send a PR with your fix
We recommend using a `conda` environment to contribute efficiently to
torchaudio.

### Install PyTorch Nightly
### Install PyTorch Nightly

```bash
conda install pytorch -c pytorch-nightly
Expand Down Expand Up @@ -78,12 +78,12 @@ If you plan to modify the code or documentation, please follow the steps below:
2. If you have modified the code (new feature or bug-fix), [please add tests](.test/torchaudio_unittest/).
3. If you have changed APIs, [update the documentation](#Documentation).

For more details about pull requests,
please read [GitHub's guides](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request).
For more details about pull requests,
please read [GitHub's guides](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request).

If you would like to contribute a new model, please see [here](#New-model).

If you would like to contribute a new dataset, please see [here](#New-dataset).
If you would like to contribute a new dataset, please see [here](#New-dataset).

## Testing

Expand Down
10 changes: 2 additions & 8 deletions docs/source/backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ torchaudio.backend
Overview
~~~~~~~~

:mod:`torchaudio.backend` module provides implementations for audio file I/O functionalities, which are ``torchaudio.info``, ``torchaudio.load``, ``torchaudio.load_wav`` and ``torchaudio.save``.
:mod:`torchaudio.backend` module provides implementations for audio file I/O functionalities, which are ``torchaudio.info``, ``torchaudio.load``, and ``torchaudio.save``.

There are currently four implementations available.

* :ref:`"sox_io" <sox_io_backend>` (default on Linux/macOS)
* :ref:`"soundfile" <soundfile_backend>` (default on Windows)

.. note::
Instead of calling functions in ``torchaudio.backend`` directly, please use ``torchaudio.info``, ``torchaudio.load``, ``torchaudio.load_wav`` and ``torchaudio.save`` with proper backend set with :func:`torchaudio.set_audio_backend`.
Instead of calling functions in ``torchaudio.backend`` directly, please use ``torchaudio.info``, ``torchaudio.load``, and ``torchaudio.save`` with proper backend set with :func:`torchaudio.set_audio_backend`.

Availability
------------
Expand Down Expand Up @@ -58,9 +58,6 @@ load

.. autofunction:: torchaudio.backend.sox_io_backend.load

.. autofunction:: torchaudio.backend.sox_io_backend.load_wav


save
----

Expand Down Expand Up @@ -89,9 +86,6 @@ load

.. autofunction:: torchaudio.backend.soundfile_backend.load

.. autofunction:: torchaudio.backend.soundfile_backend.load_wav


save
----

Expand Down
4 changes: 0 additions & 4 deletions docs/source/torchaudio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ Refer to :ref:`backend` for the detail.

Load audio file into torch.Tensor object. Refer to :ref:`backend` for the detail.

.. function:: torchaudio.load_wav(filepath: str, ...)

Load audio file into torch.Tensor, Refer to :ref:`backend` for the detail.

.. function:: torchaudio.save(filepath: str, src: torch.Tensor, sample_rate: int, ...)

Save torch.Tensor object into an audio format. Refer to :ref:`backend` for the detail.
Expand Down
1 change: 0 additions & 1 deletion test/torchaudio_unittest/backend/utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def test_switch(self):
else:
assert torchaudio.get_audio_backend() == self.backend
assert torchaudio.load == self.backend_module.load
assert torchaudio.load_wav == self.backend_module.load_wav
assert torchaudio.save == self.backend_module.save
assert torchaudio.info == self.backend_module.info

Expand Down
3 changes: 2 additions & 1 deletion test/torchaudio_unittest/compliance/generate_fbank_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import torch
import torchaudio
import utils
from torchaudio_unittest import common_utils


def run(exe_path, scp_path, out_dir, wave_len, num_outputs, remove_files, log_level):
Expand Down Expand Up @@ -102,7 +103,7 @@ def decode(fn, sound_path, exe_path, scp_path, out_dir):
# print args for python
inputs['dither'] = 0.0
logging.info(inputs)
sound, sample_rate = torchaudio.load_wav(sound_path)
sound, sample_rate = common_utils.load_wav(sound_path, normalize=False)
kaldi_output_dict = {k: v for k, v in torchaudio.kaldi_io.read_mat_ark(out_fn)}
res = torchaudio.compliance.kaldi.fbank(sound, **inputs)
torch.set_printoptions(precision=10, sci_mode=False)
Expand Down
2 changes: 1 addition & 1 deletion test/torchaudio_unittest/compliance_kaldi_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _compliance_test_helper(self, sound_filepath, filepath_key, expected_num_fil
atol (float): absolute tolerance
rtol (float): relative tolerance
"""
sound, sr = torchaudio.load_wav(sound_filepath)
sound, sr = common_utils.load_wav(sound_filepath, normalize=False)
files = self.test_filepaths[filepath_key]

assert len(files) == expected_num_files, \
Expand Down
6 changes: 1 addition & 5 deletions torchaudio/backend/no_backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import Any, Callable, Optional, Tuple, Union
from typing import Callable, Optional, Tuple, Union

from torch import Tensor

Expand All @@ -14,10 +14,6 @@ def load(filepath: Union[str, Path],
raise RuntimeError('No audio I/O backend is available.')


def load_wav(filepath: Union[str, Path], **kwargs: Any) -> Tuple[Tensor, int]:
raise RuntimeError('No audio I/O backend is available.')


def save(filepath: str, src: Tensor, sample_rate: int, precision: int = 16, channels_first: bool = True) -> None:
raise RuntimeError('No audio I/O backend is available.')

Expand Down
23 changes: 0 additions & 23 deletions torchaudio/backend/soundfile_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,26 +424,3 @@ def save(
soundfile.write(
file=filepath, data=src, samplerate=sample_rate, subtype=subtype, format=format
)


@_mod_utils.requires_module("soundfile")
@_mod_utils.deprecated('Please use "torchaudio.load".', "0.9.0")
def load_wav(
filepath: str,
frame_offset: int = 0,
num_frames: int = -1,
channels_first: bool = True,
) -> Tuple[torch.Tensor, int]:
"""Load wave file.
This function is defined only for the purpose of compatibility against other backend
for simple usecases, such as ``torchaudio.load_wav(filepath)``.
The implementation is same as :py:func:`load`.
"""
return load(
filepath,
frame_offset,
num_frames,
normalize=False,
channels_first=channels_first,
)
17 changes: 0 additions & 17 deletions torchaudio/backend/sox_io_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,20 +313,3 @@ def save(
filepath = os.fspath(filepath)
torch.ops.torchaudio.sox_io_save_audio_file(
filepath, src, sample_rate, channels_first, compression, format, encoding, bits_per_sample)


@_mod_utils.requires_module('torchaudio._torchaudio')
@_mod_utils.deprecated('Please use "torchaudio.load".', '0.9.0')
def load_wav(
filepath: str,
frame_offset: int = 0,
num_frames: int = -1,
channels_first: bool = True,
) -> Tuple[torch.Tensor, int]:
"""Load wave file.
This function is defined only for the purpose of compatibility against other backend
for simple usecases, such as ``torchaudio.load_wav(filepath)``.
The implementation is same as :py:func:`load`.
"""
return load(filepath, frame_offset, num_frames, normalize=False, channels_first=channels_first)
2 changes: 1 addition & 1 deletion torchaudio/backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def set_audio_backend(backend: Optional[str]):
else:
raise NotImplementedError(f'Unexpected backend "{backend}"')

for func in ['save', 'load', 'load_wav', 'info']:
for func in ['save', 'load', 'info']:
setattr(torchaudio, func, getattr(module, func))


Expand Down

0 comments on commit 84d3c88

Please sign in to comment.