Repository navigation
Fix garbled duration in info() output for files of 10 minutes or longer - #497
Merged
Merged
Conversation
`_SoundFileInfo._duration_str` formatted hours and minutes with `.0g`, which keeps one significant digit and switches to exponent notation from 10 on (15 minutes was shown as `2e+01:0.000 min`), and padded the seconds with `05.3f`, which is too narrow to ever pad. Use `.0f` / `02.0f` / `06.3f`, and round to milliseconds before splitting so that 119.9996 s is not shown as `01:60.000 min`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
repr(sf.info(file))prints the duration in scientific notation as soon as the minutes or hours field reaches 10, and never zero-pads the seconds:01:1.000 min01:01.000 min1e+01:0.000 min10:00.000 min2e+01:0.000 min15:00.000 min6e+01:59.000 min59:59.000 min1:01:1.500 h1:01:01.500 h3:2e+01:7.500 h3:15:07.500 h1e+01:00:0.000 h10:00:00.000 h01:60.000 min02:00.000 min(soundfile 0.14.0 at 3503941, libsndfile 1.2.2, Python 3.11, Linux x86_64)
Cause
_SoundFileInfo._duration_strformats hours and minutes with.0g.gwith precision 0 means one significant digit, so every value >= 10 is rounded to one digit and switches to exponent notation (format(15.0, '02.0g') == '2e+01'). The seconds use05.3f, butd.dddis already five characters wide, so the zero padding never applies; the width has to be 6.The
4e+01in the output quoted in #443 (6e+10:4e+01:3.719h) is this formatting; the frame count reported there is a separate matter.Change
.0f/02.0ffor hours and minutes and06.3ffor seconds.01:60.000 min.The
samplesandsbranches are unchanged, and so is thedurationattribute itself.Tests
info()had no test for the duration line. Added a parametrizedtest_info_durationcovering all four branches; 6 of its 8 cases fail on master.python -m pytest: 339 passed.pyright soundfile.pyreports the same two errors (line 188) before and after.Related work
durationattribute, so it does not resolve The duration of the audio read by the soundfile library is incorrect #443.blocks()without=; it changes other lines ofsoundfile.py.I found no issue or PR about the
info()duration format (searchedduration,_duration_str,e+01,info repr,scientific notation, open and closed).🤖 Generated with Claude Code