python-soundfile icon indicating copy to clipboard operation
python-soundfile copied to clipboard

Capture libmpg123/libsndfile warnings

Open leoauri opened this issue 1 year ago • 2 comments

Hi there, in #421 suppressing warnings from underlying libraries is discussed.

In my case I would like to capture the errors, in order to discard mp3s which trigger warnings.

I tried something like:

import librosa
import io
from contextlib import redirect_stderr
f = io.StringIO()
with redirect_stderr(f):
    librosa.load('file.mp3')

But the errors go straight to stderr and are not captured by the context manager. Presumably something going on in a subprocess or something.

Any ideas on picking up libmpg123 warnings?

leoauri avatar May 30 '24 12:05 leoauri

Presumably, libsndfile is writing straight to STDERR. It seems a bit odd that redirect_stderr doesn't catch that, but perhaps it only operates on the python level?

bastibe avatar May 31 '24 06:05 bastibe

I tried redirecting the Warning: Xing stream size off by more than 1% messages using this method, which works for e.g. Blender and TensorFlow C-level logs, but it did not work in this case.

This may be because I am calling sf.read in subprocesses (with torch's DataLoader)... I will try confining it to the main process.

update: it fails to capture the output in that case, too.

jkyl avatar Nov 18 '24 18:11 jkyl