0

I'm using the js library p5.speech. I'm trying to get each strings throught the speech function. However, each time it repeats the same strings. So is the issue coming from my code or the js library (and in this case, what library should i use?)

  const btReport1 = document.getElementById('report1');
btReport1.addEventListener('click', function(e) {

myVoice.setVoice('Google UK English Female');
  for(var i=0; i<allData.length;i++){
    console.log("allData"+i+" = " + allData[i].profile.length);
     // myVoice.speak(allData[i].profile.length+" patients have "+ allData[i].food);;
     setTimeout(function afterTwoSeconds() { myVoice.speak(allData[i].profile.length+" dogs have "+ allData[i].food);}, 1000);
  }      
});

1 Answers1

0

In your for loop, try replacing var with let so that

for(var i=0; i<allData.length;i++){ 

becomes

for(let i=0; i<allData.length;i++){

For more info, see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let

rnli
  • 575
  • 8
  • 16