Skip to content
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

Supress "PySoundFile failed. Trying audioread instead." warning #1015

Closed
Vichoko opened this issue Nov 8, 2019 · 19 comments
Closed

Supress "PySoundFile failed. Trying audioread instead." warning #1015

Vichoko opened this issue Nov 8, 2019 · 19 comments
Labels
question Issues asking for help doing something

Comments

@Vichoko
Copy link

Vichoko commented Nov 8, 2019

I'm trying to load an mp3 file with librosa.load(path) and it returns the following warning:

>>> import librosa
>>> librosa.load('mysong.mp3')
/data/anaconda3/envs/aidio/lib/python3.7/site-packages/librosa/core/audio.py:146: UserWarning: PySoundFile failed. Trying audioread instead.
  warnings.warn('PySoundFile failed. Trying audioread instead.')
(array([-0.00183699, -0.00195219,  0.00391953, ..., -0.00337326,
        0.00295902,  0.00624093], dtype=float32), 22050)

As I'm doing this multiple times it floods the stdout.
So I have some questions:

  1. Why is this a warning? Does it imply something bad?
  2. Can I hide this warning text? As it floods my stdout in my batch operations.
@bmcfee bmcfee added the question Issues asking for help doing something label Nov 11, 2019
@bmcfee
Copy link
Member

bmcfee commented Nov 11, 2019

1. Why is this a warning? Does it imply something bad?

It's a warning, not an error. This warning will always occur when loading mp3 because libsndfile does not (yet/currently) support the mp3 format. Librosa tries to use libsndfile first, and if that fails, it will fall back on the audioread package, which is a bit slower and more brittle, but supports more formats.

2\. Can I hide this warning text? As it floods my stdout in my batch operations.

Yes, you can always filter warnings. https://docs.python.org/3/library/warnings.html

@lostanlen
Copy link
Contributor

I think we can say that the Q has been answered. I am going to close this. Feel free to re-open if needed.

@Vichoko
Copy link
Author

Vichoko commented Nov 19, 2019

Any idea how to fix it?
The performance issue worries me because I need to load a ton of files and a speedup would be cool
I got the error on a freshly set Ubuntu 18 conda environment.

@bmcfee
Copy link
Member

bmcfee commented Nov 19, 2019

Any idea how to fix it?

There is nothing to fix: this is operating as intended.

Again, this is not an error, it is a warning. Your code will work just fine, it just will fall back on the (slower) audioread decoder. This is unavoidable for now, since libsndfile still does not support mp3.

If you're really concerned about speed, you could transcode your mp3s into a more permissive format (eg ogg vorbis).

@Vichoko
Copy link
Author

Vichoko commented Nov 20, 2019

Ok, i got it now.
Thank you for the help 👍

@Vichoko
Copy link
Author

Vichoko commented Jan 15, 2020

Any idea how to avoid getting this warnings printed on STDOUT?

I tried launching script with python -W ignore <script> and adding:

import warnings
warnings.filterwarnings('ignore')

At the beginning of the scripts and this User Warnings keep poping out.

Edit: Nevermind it was my issue.

@riven314
Copy link

@bmcfee I encountered the same issue and thanks for the address.
Meanwhile you mentioned audioread leads to slower performance and it's more brittle, could you elaborate more on how it is brittle because I would like to know its potential drawbacks. Besides that, would like to know if audioread would lead to any audio quality degration.

@bmcfee
Copy link
Member

bmcfee commented May 12, 2020

could you elaborate more on how it is brittle because I would like to know its potential drawbacks. Besides that, would like to know if audioread would lead to any audio quality degration.

Sure. The "brittle" comment mainly refers to software health. The audioread package has very minimal test coverage, and its dependency chain varies substantially across platforms and environments. Much of this is hidden from the end user, but it does make it difficult to debug and diagnose errors.

In terms of quality degradation, it should be fine. In principle, these formats should all decode to the same bit stream, but there will always be subtle differences arising from frame alignment, floating point rounding error, etc. MP3 decoders are notorious for this kind of thing.

@egbertn
Copy link

egbertn commented Mar 31, 2022

This is definitely a problem as of today.
"UserWarning: PySoundFile failed. Trying audioread instead"

When I get this warning, my python process hangs. So, i am loading an mp3 e.g. but this has problems. Cannot explain, but I am seeing this behavior, and I am working already many hours on this.

@bmcfee
Copy link
Member

bmcfee commented Mar 31, 2022

This is definitely a problem as of today.

Again, this is a warning and not an error. If it's hanging when you load an mp3, that's a problem with audioread (or more likely, whatever decoder it is using) and not with librosa.

@egbertn
Copy link

egbertn commented Mar 31, 2022

This is definitely a problem as of today.

Again, this is a warning and not an error. If it's hanging when you load an mp3, that's a problem with audioread (or more likely, whatever decoder it is using) and not with librosa.

Ok, I found out why this happens. When the wav file is corrupt it gives this warning. I later found that my wavs sometimes were corrupt. It should crash, but the process just hangs.

@bluenote10
Copy link
Contributor

The intention of the warning is good, but in practice it can still be a bit counter productive, e.g. when working with mp3 files. In this case the warnings conveys little information after having seen it many times.

The issue is that the warning encourages "bad", i.e., overly broad or even complete disabling of warnings like suggested in the post above. Turning off all warnings to silence this particular warning is harmful, because it can hide relevant warnings. Setting up a specific filterwarning is possible, but somewhat tricky and tedious, and the above "solution" is evidence that most users don't want to spend the time to do it properly.

Instead I'd love to have a boolean kwarg use_audioread (or allow_audioread, no_warning, ...), which I could specifically turn on in cases where I know I need audioread. This feels cleaner and more accessible than messing with filterwarnings. I can prepare to PR to demonstrate the idea...

@bmcfee
Copy link
Member

bmcfee commented Sep 6, 2022

Instead I'd love to have a boolean kwarg use_audioread (or allow_audioread, no_warning, ...), which I could specifically turn on in cases where I know I need audioread. This feels cleaner and more accessible than messing with filterwarnings. I can prepare to PR to demonstrate the idea...

I appreciate the motivation here, but I expect the entire point to be moot in the very near future. libsndfile supports mp3 now, and we're basically waiting on a release of python-soundfile (currently on b6 for the 0.11 release) for this to be supported out of the box with no additional effort from our side.

Once soundfile releases with mp3 support, this warning should almost never appear - and when it does, it's a sign that something actually is very wrong!

At any rate, our eventual plan is to deprecate and remove audioread support #1456 , but it is a bit of a question-mark about how long that will take in practice based on release cycles.

@bluenote10
Copy link
Contributor

@bmcfee Great to hear, then I'll hold my horses 😉

@javaprogrammer32072
Copy link

h

@sanxchep
Copy link

heyy faced is problem today while loading m4a file,
File is a valid m4a file,

  1. Tried importing it on jupyter running librosa 0.9.2, worked with warning shown,
  2. Tried importing it on django environment running same librosa 0.9.2, throws the same warning as exception,

Screenshot from 2022-10-10 13-36-01
Screenshot from 2022-10-10 13-35-08

Can anyone help?

@sanxchep
Copy link

Sorry, my bad I had to install ffmpeg
it worked after that.

apt install ffmpeg

https://stackoverflow.com/questions/62774301/can%C2%B4t-use-librosa-with-python-3

@Ritika457
Copy link

I was working with .flac files using librosa and I am getting this warning:
UserWarning: PySoundFile failed. Trying audioread instead.
warnings.warn("PySoundFile failed. Trying audioread instead.")
Can anybody help me with this ?

@bmcfee
Copy link
Member

bmcfee commented Nov 17, 2023

Either your flac files are corrupted, or your libsndfile was compiled without flac support. For the latter, you can check it by running

>>> import soundfile
>>> soundfile.available_formats()

to make sure that FLAC is listed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues asking for help doing something
Development

No branches or pull requests

9 participants