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

the total duration wavesurfer is giving me is wrong #3707

Open
Johnrobmiller opened this issue May 16, 2024 · 3 comments
Open

the total duration wavesurfer is giving me is wrong #3707

Johnrobmiller opened this issue May 16, 2024 · 3 comments
Labels

Comments

@Johnrobmiller
Copy link
Contributor

Johnrobmiller commented May 16, 2024

I have a audio file that is exactly 6.84 seconds long. I use js to and my OS to confirm that it exactly that duration. However, when I load it into Wavesurfer and call ws.getDuration(), wavesurfer is wrongly reporting that it is 6.81795 seconds long. This was causing a bug in my app that was difficult to troubleshoot.

The duration that wavesurfer is outputting ought to be exactly the same as the actual duration of the audio file.

Note: wavesurfer gets the duration wrong even if it is manually set in the options, as noted here #3656

@boristopalov
Copy link

Hey @Johnrobmiller, were you able to find a workaround for this? Running into the same issue

@shellRaining
Copy link
Contributor

I try to reproduce with below code

  audioEl.value.onloadedmetadata = () => {
    console.log("audioEl", audioEl.value?.duration);
  };
  const audioContext = new AudioContext();
  const audioBuffer = await fetch(audioURL)
    .then((value) => value.blob())
    .then((blob) => blob.arrayBuffer())
    .then((buffer) => audioContext.decodeAudioData(buffer));
  console.log("audioBuffer ", audioBuffer.duration);

and result is

audioEl 13.374694
audioBuffer  13.32297052154195

found that the result of audioContext is right, and another interesting discovery is, when I change the format from mp3 to wav, the result of audioEl and audioContext will be same.

public getDuration(): number {
let duration = super.getDuration() || 0
// Fall back to the decoded data duration if the media duration is incorrect
if ((duration === 0 || duration === Infinity) && this.decodedData) {
duration = this.decodedData.duration
}
return duration
}

wavesurfer tends to use the built-in duration of the audio element, which leads to inaccuracies. maybe we can exchange their order?

shellRaining added a commit to shellRaining/wavesurfer.js that referenced this issue Sep 2, 2024
@aburai
Copy link
Contributor

aburai commented Sep 2, 2024

maybe this info can help HTML audio object reporting wrong file duration

shellRaining added a commit to shellRaining/wavesurfer.js that referenced this issue Sep 3, 2024
shellRaining added a commit to shellRaining/wavesurfer.js that referenced this issue Sep 4, 2024
shellRaining added a commit to shellRaining/wavesurfer.js that referenced this issue Sep 4, 2024
shellRaining added a commit to shellRaining/wavesurfer.js that referenced this issue Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants