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

Handle MP3 files with soundfile #145

Merged
merged 5 commits into from
Jan 22, 2024
Merged

Handle MP3 files with soundfile #145

merged 5 commits into from
Jan 22, 2024

Conversation

hagenw
Copy link
Member

@hagenw hagenw commented Jan 19, 2024

Closes #119

This adds reading and metadata support for MP3 files using soundfile >=0.11.0 soundfile>=0.12.1.
I have not added writing support for MP3 files as this depends on the system wide installation of libsndfile (compare bastibe/python-soundfile#348), whereas for reading the libsndfile library bundled with soundfile is used (hence the dependency on soundfile>=0.11.0 soundfile>=0.12.1).
If we think writing support for MP3 is needed as well, I would propose to add it in another pull request.

It also updates the benchmark page with the new results.
For the "Reading files" benchmark it presents now all results in a single figure. For the "Accessing metadata" benchmark,
results for MP4 are still shown in an extra figure as it takes much longer than for the other formats.

The good news is that the proposed changes make processing of MP3 faster (results as average per file):

benchmark main this branch
Reading files 0.07 s 0.03 s
Accessing metadata 0.19 s 0.0002 s

Benchmark page

image

/cc @frankenjoe

Copy link

codecov bot commented Jan 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (be5b555) 100.0% compared to head (02e6d83) 100.0%.

Additional details and impacted files
Files Coverage Δ
audiofile/core/info.py 100.0% <ø> (ø)
audiofile/core/io.py 100.0% <ø> (ø)
audiofile/core/utils.py 100.0% <100.0%> (ø)

Copy link
Member

@schruefer schruefer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for the update, unfortunately, I'm not quite sure what the update does.
The main change is that we require a newer soundfiles version and that all tests and benchmarks are updated accordingly, right?

tests/test_audiofile.py Show resolved Hide resolved
@hagenw
Copy link
Member Author

hagenw commented Jan 22, 2024

Hey, thanks for the update, unfortunately, I'm not quite sure what the update does. The main change is that we require a newer soundfiles version and that all tests and benchmarks are updated accordingly, right?

Yes, we require soundfile>=0.12.1 as this comes with a pre-build libsndfile that does support reading of MP3 files (which was introduced in libsndfile in version 1.1.0).
BTW, you can check for the libsndfile that is used by soundfile with:

import soundfile

soundfile.__libsndfile_version__

soundfile 0.12.1 returns '1.2.0'.

In addition, it updates the tests as MP3 was used in some tests to represent an audio format not supported by soundfile, which is no longer true. In those cases I switched the test to MP4.

And the most files were changed as part of the updated benchmark pages, which now include the results for the changes of this pull request.

@schruefer
Copy link
Member

Okay, great, makes a lot of sense to me!
I was just a little bit confused because I was looking for some bigger code changes to use libsndfile.
Sounds good to me!

@hagenw hagenw merged commit 15355bd into main Jan 22, 2024
34 checks passed
@hagenw hagenw deleted the mp3-as-sndfile branch January 22, 2024 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use libsndfile for reading/writing MP3
2 participants