audio icon indicating copy to clipboard operation
audio copied to clipboard

torchaudio.sox_effects.apply_effects_file failed to load from `.mp3` format

Open maxwellzh opened this issue 3 years ago • 2 comments

🐛 Describe the bug

Directly load .mp3 audio with torchaudio.sox_effects.apply_effects_file will fail:

import torchaudio

file = "clips/common_voice_id_25649986.mp3"
effects = [['speed', '0.9'], ['rate', '48000']]
torchaudio.sox_effects.apply_effects_file(file, effects)
# output:
# RuntimeError: Failed to load audio from clips/common_voice_id_25649986.mp3

But torchaudio.load could make it:

# this won't produce error.
torchaudio.sox_effects.apply_effects_tensor(
    torchaudio.load(file)[0], 48000, effects
)

Versions

Collecting environment information... PyTorch version: 1.12.1 Is debug build: False CUDA used to build PyTorch: 11.3 ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.5 LTS (x86_64) GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 Clang version: Could not collect CMake version: version 3.10.2 Libc version: glibc-2.27

Python version: 3.10.4 (main, Mar 31 2022, 08:41:55) [GCC 7.5.0] (64-bit runtime) Python platform: Linux-4.15.0-142-generic-x86_64-with-glibc2.27 Is CUDA available: True CUDA runtime version: 11.3.58 GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3090 GPU 1: NVIDIA GeForce RTX 3090 GPU 2: NVIDIA GeForce RTX 3090 GPU 3: NVIDIA GeForce RTX 3090 GPU 4: NVIDIA GeForce RTX 3090 GPU 5: NVIDIA GeForce RTX 3090 GPU 6: NVIDIA GeForce RTX 3090 GPU 7: NVIDIA GeForce RTX 3090 GPU 8: NVIDIA GeForce RTX 3090 GPU 9: NVIDIA GeForce RTX 3090

Nvidia driver version: 470.74 cuDNN version: Probably one of the following: /usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn.so.8 /usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8 /usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_adv_train.so.8 /usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8 /usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8 /usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8 /usr/local/cuda-11.1/targets/x86_64-linux/lib/libcudnn_ops_train.so.8 HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True

Versions of relevant libraries: [pip3] numpy==1.23.1 [pip3] torch==1.12.1 [pip3] torch-edit-distance==0.3.0 [pip3] torchaudio==0.12.1 [pip3] torchvision==0.13.1 [conda] blas 1.0 mkl defaults [conda] cudatoolkit 11.3.1 h2bc3f7f_2 defaults [conda] mkl 2021.4.0 h06a4308_640 defaults [conda] mkl-service 2.4.0 py310h7f8727e_0 defaults [conda] mkl_fft 1.3.1 py310hd6ae3a3_0 defaults [conda] mkl_random 1.2.2 py310h00e6091_0 defaults [conda] numpy 1.23.0 pypi_0 pypi [conda] numpy-base 1.23.1 py310hcba007f_0 defaults [conda] pytorch 1.12.1 py3.10_cuda11.3_cudnn8.3.2_0 pytorch [conda] pytorch-mutex 1.0 cuda pytorch [conda] torch-edit-distance 0.3.0 dev_0 [conda] torchaudio 0.12.1 py310_cu113 pytorch [conda] torchvision 0.13.1 py310_cu113 pytorch

maxwellzh avatar Sep 19 '22 12:09 maxwellzh

Hi @maxwellzh

This is due to the change made in v0.12. Loading MP3 is now delegated to FFmpeg in TorchAudio, but apply_effects_file cannot do that. As an alternative, can you load the MP3 into Tensor and call apply_effects_tensor on it?

mthrok avatar Sep 20 '22 06:09 mthrok

@mthrok apply_effects_tensor is OK, as I said in the bug description

# this won't produce error.
torchaudio.sox_effects.apply_effects_tensor(
    torchaudio.load(file)[0], 48000, effects
)

So I think torchaudio should deprecate apply_effects_file function or maybe at least update the document.

maxwellzh avatar Sep 20 '22 06:09 maxwellzh

I also experienced this and agree with @maxwellzh's solution to deprecate apply_effects_file or fix the docs as this was an unexpected breaking change for some of us, and will cause a confusing bug for others. Thank you both for work on this issue!

rbracco avatar Oct 17 '22 17:10 rbracco

Hi folks

With the recent change in libsox, this issue should be resolved. with https://github.com/pytorch/audio/pull/3497, torchaudio now relies on externally installed libsox, and most libsox distributions have mp3 support.

mthrok avatar Jul 31 '23 16:07 mthrok