bastibe / python-soundfile

SoundFile is an audio library based on libsndfile, CFFI, and NumPy
BSD 3-Clause "New" or "Revised" License
701 stars 108 forks source link

Capture libmpg123/libsndfile warnings #435

Open leoauri opened 4 months ago

leoauri commented 4 months ago

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?

bastibe commented 4 months ago

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?