JavaScript alone can’t solve this because audioplayback is handled by Anki on the back end, outside of reach for card scripts. They do not have access to the ongoing playback state or information about the duration of audio files. There is no API for requesting a playback of several files or catching a playback finish event either.
The potential workarounds, in addition to the already mentioned one, would be:
- Write an add-on that will implement the required API for card scripts to use (will take a lot of effort and won’t work on mobile)
- Store information about audio files’ durations in Anki fields explicitly (can be facilitated by a much simpler add-on, which won’t need to run constantly, so mobile remains an option)
- Use
<audio>tags instead of[sound:]when inserting audio into fields (will make audio playback fully accessible to JS scripts, but will mess with Anki’s tracking of unused files) - Use the AnkiWeb site for reviews instead of the app (it inserts all
[sound:]as<audio>tags anyway and does not ruin unused files tracking, but will require adapting card templates to work in the web version)