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

[question] voice-recognition: is for-loop on results required? #39

Open
masonlouchart opened this issue Dec 7, 2017 · 0 comments
Open

Comments

@masonlouchart
Copy link
Collaborator

masonlouchart commented Dec 7, 2017

There is 2 questions I would like to ask about this snippet.

for (var i = e.resultIndex; i < e.results.length; ++i) {
that.text = e.results[i][0].transcript;
e.result = that.text;
}

Why the voice-recognition element is working?

Due to the prefix increment of i in the for-loop, I expect a TypeError because cannot read "0" of undefined no matter is the array length. I added a log and the i variable seems incremented after a loop.

capture d ecran 2017-12-07 a 14 42 02

Do we need a for-loop?

I think what we need is simply read the last entry of the results array. AFAIK, the resultIndex variable is the index of the last result received. So the for-loop do 1 loop on the last entry right?

Thanks to help me to understand how it's working. 👨‍🎓

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

1 participant