1

I never working with this language, am only help a friend. I am trying play sound of a word. But are executing very quickly.

audio.vue

methods: {
    .then(setTimeout(() => {
      const arr = 'test'
      Array.prototype.forEach.call(arr, char => {
        audio.playChar(char) //Passing each char separately, wait 1 second before execure next iterator
      })
    }, 
    ...
  }
}

audio.js

 playTest (char) {
    return new Promise((resolve, reject) => {
      const audio = new Audio()
      audio.src = `.../alert/pt/${char}.mp3` //playing separately but very quickly
      audio.onended = resolve
      audio.onerror = reject
      audio.play()
    })
  },
Diego Venâncio
  • 5,698
  • 2
  • 49
  • 68

1 Answers1

1

If you want to delay each execution of the function add an integer to the setTimeout after the function.

audio.vue:

methods: {
    .then(setTimeout(() => {
      const arr = 'test'
      Array.prototype.forEach.call(arr, char => {
        audio.playChar(char) //Passing each char separately, wait 1 second before execure next iterator
      })
    }, 1000 //<== add 1000 milliseconds to your setTimeout
    ...
  }
}
Bedir
  • 476
  • 1
  • 6
  • 17
  • Thanks for help, I dont was very clear in my question, update now. Whats I need is something of 'wait 1 second before execure next iterator'. Example: const arr = 'test'... audio.play(), wait 1 second next iterator audio.play(), etc – Diego Venâncio Apr 30 '19 at 14:56
  • Oh, well what is the delay you have in your setTimeout? – Bedir Apr 30 '19 at 15:09