-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Waveform run more and more out of sync to audio #2890
Comments
Thanks Markus! This issue exists indeed. |
I think it is a problem with the calculation of cursor position maybe in connection with the zoom level. Because if i disable the autostart and jump directly to a later position in the audio, for example the last wavy lines, it is synchronous. |
Hmm, maybe. The cursor position is set as a percentage of the width of the waveform. Basically https://github.com/katspaugh/wavesurfer.js/blob/beta/src/wavesurfer.ts#L243 Maybe some precision is lost due to that math, or even CSS. However, in my tests, the desynchronization was sort of random. Sometimes it would be accurate, sometimes not on the same region of audio. |
Thanks, I think the calculation of the cursor position is correct. Currently I have the assumption that the event handler of the In the event documentation is the following hint:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/timeupdate_event Maybe there is a need for a timeout or the performance of the handler maybe optimized where it is possible, e.g. cache the getDuration result instead of get them from the media element. Maybe the frequenz of the smooth function / |
Interesting thought, definitely worth checking. Can be tested by removing both |
I've experimented with the following settings:
Even with the tick event commented out, when it jumps to the 3:40 mark on ready, there's already a mismatch between the audio and the waveform. |
I was also having some playback timing issues. After converting my mp3 file to CBR (constant bit rate), the issue seems to be gone and everything is working correctly now. It seems like the seek functionality is struggling with VBR (variable bit rate) audio files. Source: https://stackoverflow.com/questions/32144092/inconsistent-seeking-in-html5-audio-player |
@alexbegey that makes a lot of sense! Thanks for solving this mystery. |
Instead of converting my mp3 files to CBR, I have been running them through the program called VBRFix, which tweaks their tags/headers but afaik does not convert them to CBR. After running them through the program, the files work just fine in Wavesurfer. Where in the code does Wavesurfer read the LAME or Xing (or VBRI) tag of the audio file? Is it possible that it is currently set to read only one of those kinds of headers, and that it cannot recognize the other two? I ask because even mp3 and mp4/m4a (I can't remember which) files made by modern iPhones and software programs are tripping up Wavesurfer, but VBRFix somehow makes them work just by tweaking their headers to be supported by Wavesurfer. TIA |
Interesting finding, @skysnolimit08, thank you! |
It would be great if somebody else could verify what I've found, since I'm out of the country with no access to my materials right now and it's been a long time since I have thought about this. (It is still a common problem for my users, though) In terms of tweaking the headers in JS, I wouldn't know where to start, but it sounds like an ideal solution. I tried to find the actual source code of VBRFix to see what it does, but couldn't locate it. Maybe one of the standard audio diagnostics tools used (mp3tag? or even VBRFix itself) can be used to inspect the headers both before and after a problem file is run through VBRFix. We could see what type VBRFix changes the header to and what it says, then figure out how to replicate that in JS. |
Don't know if this is related to CBR or VBR but I am recording and audio with a library in react and when paused I pass the audio/mpeg blob to wavesurfer. But usually most of time when wavesurfer loads the audio the duration is different that what it actually is e.g. if the audio was paused at 30s then wavesurfer would return a number between 27-30s and when the audio is being played with wavesurfer the seeker slows down or just jitters for some time as the audio and visualisation are out of sync thus slowing down helps it to sync but looks really weird. And when I download the audio and play it using mac audio player it displays correct duration and runs smoothly. |
Hey @katspaugh , So I tried something similar to what @skysnolimit08 said above. |
@NegiBaba looks like specifying a fixed bit rate solves that issue for the Recorder plugin: E.g. RecordPlugin.create({
audioBitsPerSecond: 128000,
}) |
@katspaugh Yeah but I am actually using a different library to record audio, so now need to make changes to that library. I think we should have some note in the documentation regarding the same that wavesurfer works best if you provide a CBR audio file/blob to it and then link to more info about bit rate in audio. That can really help developers like me who would have to go through many issues in the library, what you say? |
Yes, it's in the FAQ in the readme. We could also add it as a docstring of the |
Thx @katspaugh and @alexbegey! It works for me with the conversion to CBR too. |
Context for anyone else stumbling upon this issue, on the manpage to VBRfix it says:
From what I can tell from reading about this, it seems like if you just set everything to be a CBR, the file size is going to be significantly larger, so the ideal solution would be to always insert a null frame at the beginning of every mp3 somehow... but I doubt realtime it'd be performant, so I don't think Wavesurfer.js can fix this (you'd just have to use VBRfix to all your files before you deploy them). I'm unsure if somehow the WebAudio.js shim already solves this like it says in the FAQ. Or if you can just specify I'd definitely like to set up all my Wavesurfer projects to stay in sync even with large files. 😆 |
When i play my audio file it works correctly but after some time the curve doesn't quite fit the audio file.
I'm using a podcast audiofile that is only spoken, so there are some pause between the words and sentences.
My audio file for testing https://media.bibliothek.kit.edu/world/2020/DIVA-2020-76_mp3.mp3
Besides that, I use the zoom sample implementation to zoom into the wave.
https://wavesurfer-js.org/examples/#zoom.js
At the beginning the wave is still synchronous. At minute 20 for example there is a pause in the wave, but the speaker speaks.
Wavesurfer.js version(s):
7.0.0-beta.8
Browser and operating system version(s):
Chrome
The text was updated successfully, but these errors were encountered: