say.speak does not work in for loop
Opened this issue · 1 comments
HakimMalikOttey commented
While I can load the entire string into say.speak and have it say what I need to say, my goal for this project is to split the string into a list, and to iteratively have say.speak shout out each string in the list. However, the speak function does not say the text when put in any loop, but works fine if its outside of a loop.
const responseData = response.text.split(/\r?\n/);
if(responseData.length == 0){
say.speak("Sorry. I do not think I heard that right.");
}
else{
var sayPromise = [];
for(var i = 0; i < responseData.length;i++){
const resolve = () => {
return new Promise((resolve) => {
say.speak(responseData[i],"Alex",1,(err)=>{
resolve();
});
})};
sayPromise.push(resolve);
}
for(const async of sayPromise){
const result = await async();
} }
vladcorn commented
avoid async
as variable also don't use resolve
variable rename there are variables