I would like to halt/wait the for-loop until the `window.speechSynthesis.speak(audio)` finishes reading the text, then go to next iteration. I have below code:

```
 var all = "Oak is strong and also gives shade \n \
    Cats and dogs each hate the other \n \
    The pipe began to rust while new \n Bye."

 sentences = all.split('\n')
      for (i = 0; i < sentences.length; i++) {
        sentence = sentences[i]
        console.log(sentences[i]);
        audio = new SpeechSynthesisUtterance(sentence)
        window.speechSynthesis.speak(audio)
         } 

```

Now what I want is that, once each `sentences[i]` is printed. The next `sentences[i]` will not be printed until `window.speechSynthesis.speak(audio)` is finished, once the speech is finished then the `sentences[i]` will be printed for the next iteration.

So how can I make the loop wait until a function is not finished?

**Note:** I can make it wait for a constant time, but I want a dynamic wait, i.e. the wait should be as long as`window.speechSynthesis.speak(audio)` takes time to finish the text.