-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
torchaudio.load() for file-like object fails for mp3 files #2363
Comments
Hi @rbracco To use MP3 with file-like object, you need to pass |
Thank you! |
I'm having trouble loading mp3 even when specifying the format:
|
My first question would be, where did "test.mp3" come from, how certain are
you it's a properly formatted MP3, and can you share it for testing?
…On Fri, Jul 8, 2022 at 6:44 AM Dāvis Nicmanis ***@***.***> wrote:
I'm having trouble loading mp3 even when specifying the format:
Python 3.8.13 (default, Mar 28 2022, 11:38:47)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torchaudio
>>> torchaudio.get_audio_backend()
'sox_io'
>>> wav, sr = torchaudio.load("test.mp3", format="mp3")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/path/wav2vec/lib/python3.8/site-packages/torchaudio/backend/sox_io_backend.py", line 227, in load
return _fallback_load(filepath, frame_offset, num_frames, normalize, channels_first, format)
File "/path/wav2vec/lib/python3.8/site-packages/torchaudio/backend/sox_io_backend.py", line 29, in _fail_load
raise RuntimeError("Failed to load audio from {}".format(filepath))
RuntimeError: Failed to load audio from test.mp3
>>>
—
Reply to this email directly, view it on GitHub
<#2363 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALIBGAI4UB5EZIZGX6KI53LVTABA5ANCNFSM5VFEOX7Q>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
|
It's just a random mp3 file, I tested various files to verify that it's not the issue with the file. |
Starting 0.12, the MP3 decoder is switched to libavcodec. The error indicates that there is no installation of FFmpeg 4. Please install ffmpeg 4. |
Thank you, this solved the issue |
I can't seem to get it to load any mp3 files with ffmpeg version 4.4.2. Actual output:
|
FFmpeg 4.4 has different ABI, so C runtime does not pick it up. Can you try 4.1 - 4.3? |
Still no joy. Here's the more specific output below. This is on a mac and in a notebook if that helps. import subprocess
subprocess.check_output(['ffmpeg', '-version']) Output:
import torchaudio
SPEECH_FILE = "_cv_corpus/en/clips/common_voice_en_27988632.mp3"
waveform, sample_rate = torchaudio.load(SPEECH_FILE, format="mp3") Output:
|
@lukeellison Looks like the ffmpeg binary you have is static built. TorchAudio requires the shared libraries of libavXXX, such as |
Right, okay. |
It is good to show relevant error message instead of random runtime err |
yah confirming |
Is there an easy to get this without conda? e.g. conda's not on Colab by default, but pip is. pip's ffmpeg only goes up to v1.4. Installing via ! apt install ffmpeg
Reading package lists... Done
Building dependency tree
Reading state information... Done
ffmpeg is already the newest version (7:3.4.11-0ubuntu0.1).
The following package was automatically installed and is no longer required:
libnvidia-common-460
Use 'apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded. y = torchaudio.load('my_audio.mp3', format="mp3")
|
...Follow up: Nope. Even after installing
even after restarting the runtime and coming back, same error persists. So, ... SolutionForget torchaudio. Just do a
then
load with librosa and recast to |
On Google Colab, the following should install a supported FFmpeg. ‘’’ |
What about on systems for which we don't have root access, and environments that use a pip (not conda) install? |
For such environments, the availability of pre-built FFmpeg binary depends on the system. Some package managers such as brew on linux work without admin privilege. If that does not work for your system, the last resort is to install FFmpeg manually. You can, for example, refer to the GPU decoding tutorial to see what building FFmpeg looks like. Although it still requires codec libraries available somehow. Some hack I use sometimes is to copy the libraries files from some other locations. This works if both environments are same. exodus seems to facilitate this but I never tried by myself. |
None of the previous advice was working for me (ffmpeg=4.3, torchaudio=0.12.1). I upgraded ffmpeg to version 5.1.2, and now I can load mp3 files. |
Solution:make sure the ffmpeg codec libraries is linked to libtorchaudio Details:I spent two days to solve this problem, my situation is:
Question:though it works in torchaudio.load() function, i still failed to find 'mp3' in torchaudio.utils.sox_utils.list_read_formats() outputs:
|
For ffmpeg 4.2.8 (devel-package installed), I was able to achieve mp3 support on torchaudio 0.13.1 by explicit setting USE_FFMPEG=1 when building torchaudio from the sources |
I have same problem(ffmpeg=4.3, torchaudio=0.12)。I found /lib64/libavcodec.so.57 under /lib64. but /data/home/yiljiang/anaconda3/envs/mert/bin/../lib/libavcodec.so.58 under conda env directory. So I set
And then problem solved |
install torchaudio >= 1.9.0 |
Failed to load mp3 with ffmpeg==4.2.7 and torchaudio==2.0.1 |
🐛 Describe the bug
Description
This error occurs when trying to read a file-like object that contains an MP3 audio. This error does not occur for file-like objects that contain WAV audio.
Stack Trace
Reproducible Snippets
To reproduce with MP3:
To verify this is not an issue for WAV"
Relevant Documentation
These snippets copy exactly the torchaudio load filelike object documentation
Versions
torchaudio version: 0.11.0
The text was updated successfully, but these errors were encountered: