feat: add duration-only audio file API#1122
Open
Traviskn wants to merge 2 commits into
Open
Conversation
mdydek
requested changes
Jun 26, 2026
mdydek
left a comment
Collaborator
There was a problem hiding this comment.
Thank you for the contribution. Two things I would like to address:
- I think that it should not be a method of a context, I would like to leave core web audio api classes as close to their web equivalent (there is no property like that)
- web is probably much more flexible when it comes to available resources, I would like to see implementation also on this side (either using audio tag or audiocontext)
Contributor
Author
|
Thanks for the feedback! I’ll update this PR 👍 |
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.
Summary
Adds a
getAudioDurationutility for reading an audio file’s duration without decoding the full file into anAudioBuffer.This exposes the API in two places:
getAudioDuration(input)as a top-level utilityBaseAudioContext#getAudioDuration(input)The native implementation uses a duration-only decoder path so callers can inspect local audio files without allocating memory for the full PCM payload.
Motivation
Some apps need to validate or display recording durations before playback or upload. Using
decodeAudioDatafor that can be expensive because it decodes the entire file into memory, which can cause memory pressure or crashes for longer recordings. In my case, lower end devices would crash with an out-of-memory error when usingdecodeAudioDatato get the duration of the resulting audio buffer.getAudioDurationprovides a lighter-weight path for this use case.I have applied this new API to my own app as a patch and have confirmed that it works.
Checklist