From 76def1def383735a90a87e8c2f166b1ca70d874c Mon Sep 17 00:00:00 2001 From: Sam Anklesaria Date: Tue, 2 Sep 2025 17:55:05 +0000 Subject: [PATCH 1/2] Remove the apply_codec function --- src/torchaudio/functional/functional.py | 45 ------------------------- 1 file changed, 45 deletions(-) diff --git a/src/torchaudio/functional/functional.py b/src/torchaudio/functional/functional.py index 5d4284d595..5285e9416d 100644 --- a/src/torchaudio/functional/functional.py +++ b/src/torchaudio/functional/functional.py @@ -1301,51 +1301,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") From d0602dd1e61b295036e7ca241b69205458a6b1f7 Mon Sep 17 00:00:00 2001 From: Sam Anklesaria Date: Tue, 2 Sep 2025 18:40:45 +0000 Subject: [PATCH 2/2] Remove references to apply_codec --- docs/source/functional.rst | 1 - src/torchaudio/functional/__init__.py | 2 -- src/torchaudio/functional/functional.py | 1 - .../functional/functional_cpu_test.py | 34 ------------------- 4 files changed, 38 deletions(-) diff --git a/docs/source/functional.rst b/docs/source/functional.rst index f58a6730b8..158ae54869 100644 --- a/docs/source/functional.rst +++ b/docs/source/functional.rst @@ -23,7 +23,6 @@ Utility mask_along_axis_iid mu_law_encoding mu_law_decoding - apply_codec resample loudness convolve diff --git a/src/torchaudio/functional/__init__.py b/src/torchaudio/functional/__init__.py index 1c3b86b5da..1227b932c8 100644 --- a/src/torchaudio/functional/__init__.py +++ b/src/torchaudio/functional/__init__.py @@ -32,7 +32,6 @@ add_noise, amplitude_to_DB, apply_beamforming, - apply_codec, compute_deltas, convolve, create_dct, @@ -111,7 +110,6 @@ "riaa_biquad", "treble_biquad", "vad", - "apply_codec", "resample", "edit_distance", "pitch_shift", diff --git a/src/torchaudio/functional/functional.py b/src/torchaudio/functional/functional.py index 5285e9416d..9c904120c4 100644 --- a/src/torchaudio/functional/functional.py +++ b/src/torchaudio/functional/functional.py @@ -34,7 +34,6 @@ "mask_along_axis_iid", "sliding_window_cmn", "spectral_centroid", - "apply_codec", "resample", "edit_distance", "loudness", diff --git a/test/torchaudio_unittest/functional/functional_cpu_test.py b/test/torchaudio_unittest/functional/functional_cpu_test.py index 7168d685ea..d4f1b4578e 100644 --- a/test/torchaudio_unittest/functional/functional_cpu_test.py +++ b/test/torchaudio_unittest/functional/functional_cpu_test.py @@ -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)