Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

say.speak does not work in for loop #136

Open
HakimMalikOttey opened this issue Jan 12, 2024 · 1 comment
Open

say.speak does not work in for loop #136

HakimMalikOttey opened this issue Jan 12, 2024 · 1 comment

Comments

@HakimMalikOttey
Copy link

HakimMalikOttey commented Jan 12, 2024

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
Copy link

avoid async as variable also don't use resolve variable rename there are variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants