Skip to content
Merged
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
1 change: 0 additions & 1 deletion docs/source/functional.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Utility
mask_along_axis_iid
mu_law_encoding
mu_law_decoding
apply_codec
resample
loudness
convolve
Expand Down
2 changes: 0 additions & 2 deletions src/torchaudio/functional/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
add_noise,
amplitude_to_DB,
apply_beamforming,
apply_codec,
compute_deltas,
convolve,
create_dct,
Expand Down Expand Up @@ -111,7 +110,6 @@
"riaa_biquad",
"treble_biquad",
"vad",
"apply_codec",
"resample",
"edit_distance",
"pitch_shift",
Expand Down
46 changes: 0 additions & 46 deletions src/torchaudio/functional/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"mask_along_axis_iid",
"sliding_window_cmn",
"spectral_centroid",
"apply_codec",
"resample",
"edit_distance",
"loudness",
Expand Down Expand Up @@ -1301,51 +1300,6 @@ def spectral_centroid(
return (freqs * specgram).sum(dim=freq_dim) / specgram.sum(dim=freq_dim)


@deprecated("Please migrate to :py:class:`torchaudio.io.AudioEffector`.", remove=False)
def apply_codec(
waveform: Tensor,
sample_rate: int,
format: str,
channels_first: bool = True,
compression: Optional[float] = None,
encoding: Optional[str] = None,
bits_per_sample: Optional[int] = None,
) -> Tensor:
r"""
Apply codecs as a form of augmentation.

.. devices:: CPU

Args:
waveform (Tensor): Audio data. Must be 2 dimensional. See also ```channels_first```.
sample_rate (int): Sample rate of the audio waveform.
format (str): File format.
channels_first (bool, optional):
When True, both the input and output Tensor have dimension `(channel, time)`.
Otherwise, they have dimension `(time, channel)`.
compression (float or None, optional): Used for formats other than WAV.
For more details see :py:func:`torchaudio.backend.sox_io_backend.save`.
encoding (str or None, optional): Changes the encoding for the supported formats.
For more details see :py:func:`torchaudio.backend.sox_io_backend.save`.
bits_per_sample (int or None, optional): Changes the bit depth for the supported formats.
For more details see :py:func:`torchaudio.backend.sox_io_backend.save`.

Returns:
Tensor: Resulting Tensor.
If ``channels_first=True``, it has `(channel, time)` else `(time, channel)`.
"""
from torchaudio.backend import _sox_io_backend

with tempfile.NamedTemporaryFile() as f:
torchaudio.backend._sox_io_backend.save(
f.name, waveform, sample_rate, channels_first, compression, format, encoding, bits_per_sample
)
augmented, sr = _sox_io_backend.load(f.name, channels_first=channels_first, format=format)
if sr != sample_rate:
augmented = resample(augmented, sr, sample_rate)
return augmented


_CPU = torch.device("cpu")


Expand Down
34 changes: 0 additions & 34 deletions test/torchaudio_unittest/functional/functional_cpu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,3 @@ def test_lfilter_9th_order_filter_stability(self):
class TestFunctionalFloat64(Functional, PytorchTestCase):
dtype = torch.float64
device = torch.device("cpu")


@unittest.skip("deprecated")
class TestApplyCodec(TorchaudioTestCase):
def _smoke_test(self, format, compression, check_num_frames):
"""
The purpose of this test suite is to verify that apply_codec functionalities do not exhibit
abnormal behaviors.
"""
sample_rate = 8000
num_frames = 3 * sample_rate
num_channels = 2
waveform = torch.rand(num_channels, num_frames)

augmented = F.apply_codec(waveform, sample_rate, format, True, compression)
assert augmented.dtype == waveform.dtype
assert augmented.shape[0] == num_channels
if check_num_frames:
assert augmented.shape[1] == num_frames

def test_wave(self):
self._smoke_test("wav", compression=None, check_num_frames=True)

@parameterized.expand([(96,), (128,), (160,), (192,), (224,), (256,), (320,)])
def test_mp3(self, compression):
self._smoke_test("mp3", compression, check_num_frames=False)

@parameterized.expand([(0,), (1,), (2,), (3,), (4,), (5,), (6,), (7,), (8,)])
def test_flac(self, compression):
self._smoke_test("flac", compression, check_num_frames=False)

@parameterized.expand([(-1,), (0,), (1,), (2,), (3,), (3.6,), (5,), (10,)])
def test_vorbis(self, compression):
self._smoke_test("vorbis", compression, check_num_frames=False)