marl/pysox

Is there a faster way to read audio-information from files?

stefan-falk opened this issue · 2 comments

I am using sox in order to read some meta-information for audio sample.

return dict(
    encoding=sox.file_info.encoding(audio_fp),
    depth=sox.file_info.bitdepth(audio_fp),
    channels=sox.file_info.channels(audio_fp),
    rate=sox.file_info.sample_rate(audio_fp),
    samples=sox.file_info.num_samples(audio_fp),
)

However, this becomes incredibly slow for a larger number of samples. The reason is very obvious, because each call would open and read the file.

I couldn't find a faster way to do this. There is a method sox.file_info.info() but this is really just doing the same thing I do (code, docs).

Why is there no faster way to do is like open the file once and read all the information?


See also my question on stackoverflow

sox.file_info is just a Python wrapper around the soxi shell command.

Why is there no faster way to do is like open the file once and read all the information?

There might be a faster way if you know in advance that you want to read a certain type of audio file (e.g., WAV).

Perhaps you can try this other library: https://pypi.org/project/audio-metadata/ ?
It support WAV, FLAC, MP3, and OGG

I understand. Thank you for the reply. I am going to take a look at audio-metadata - thanks for the hint!

The issue can be closed then I guess.