JS Promise resolve not working on first iteration

I’m trying to play Animation of SVG path, and a voiceover generated by Microsoft tts. I have made a function.

  async function playWithSound(pathArrangement, i, len) {

         const synth = window.speechSynthesis;
         pathid = pathArrangement[i];
         script = scriptData[pathData[pathid].name];

         console.log(script)

         const utterance = new SpeechSynthesisUtterance(script);
         utterance.voice = neerjaVoice || synth.getVoices()[0];

         await synth.speak(utterance);
         utterance.onstart = () => {
            document.getElementById(pathid).style.animationPlayState = 'running';
            followPencil(pathid);
         }



         // Create a promise that resolves when the speech synthesis ends
         const speechEndPromise = new Promise((resolve) => {
            utterance.onend = resolve;
         });

         const animationEndPromise = new Promise((resolve) => {
            document.getElementById(pathid).addEventListener('animationend', () => {
               resolve();
            }, { once: true });
         });
         // wait for promises to resolve and call the next stack
         await Promise.all([animationEndPromise, speechEndPromise]);
         console.log("resolved both")

         i++;
         if (i < len) {
            playWithSound(pathArrangement, i, len);
         }
         return;
      }

The problem with the above function is that when the speech ends first before the animation ends for the first iteration then from nowhere the promise is resolved and it’s jumps to next iteration. But when the speech ends after the animation ends it works fine.

I have recorded a video you can see it here: video