BirdVox / birdvoxdetect

A pre-trained deep learning system for detecting bird flight calls in continuous recordings
MIT License
76 stars 15 forks source link

MP3 support #75

Closed lostanlen closed 3 years ago

lostanlen commented 3 years ago

Requested by Davyd Betchkal

Pasting Justin Salmon's reply here:

Currently BVD and BVC rely on the soundfile python library for audio I/O, which in turn relies on the libsndfile library, which doesn't support mp3 (yet). While there are other python audio libraries that do support mp3 loading, we rely on the functionality of soundfile, in particular seeking to load a segment of an audiofile without having to load all the data into memory, which is important for robust processing of long recordings. My colleagues Vincent and Jason can probably comment on this in greater detail.

That said, we realize that this is an important feature and we would love to support it if we can. We'll try to do some digging around this to see what we can do - perhaps there are alternative builds of libsndfile that do support mp3 that we could leverage, potentially at the cost of a custom installation process for users who require this feature.

lostanlen commented 3 years ago

@dbetchkal feel free to make a PR if you have the time! otherwise i'll triage it for 0.6+

lostanlen commented 3 years ago

A solution proposed by Dan Stowell on the BirdVox mailing list

I have a geeky method for MP3 support for long files. It works in Linux/Mac only - and it's geeky. But here it is, in case any of you benefit from it:

In order to read a long-duration MP3 file into BirdVoxDetect (or any other WAV-streaming analysis), you can create a "unix pipe" and use it together with an MP3 decoder command such as lame or sox. This will feed the MP3 into your software without occupying any disk space.

In a new terminal window, run these 3 lines (replacing MYMP3PATH):

fifo=/tmp/mp3decoding01.fifo mkfifo $fifo lame --decode --silent MYMP3PATH $fifo

Then in Python, treat /tmp/mp3decoding01.fifo as if it was a wave file to be read into BirdVoxDetect. No extra disk space is needed, it's all on-the-fly.

This can't be done in Windows, I think.

Feel free to re-open this issue if anyone needs to run BVD on MP3 files on Windows.