compulim / web-speech-cognitive-services

Polyfill Web Speech API with Cognitive Services Bing Speech for both speech-to-text and text-to-speech service.
https://compulim.github.io/web-speech-cognitive-services
MIT License
63 stars 18 forks source link

Why is `event.resultIndex` always undefined? #99

Open janluke opened 4 years ago

janluke commented 4 years ago

If the event is always about the last result, why not setting it to length(event.results) - 1?

compulim commented 3 years ago

Can you explain where this code is?

janluke commented 3 years ago

Sorry, I was very unclear. I'm referring to SpeechRecognitionEvent when listening also for interim results. I opened this issue in May, so I don't remember if I looked into your code, but I'd say you probably just forget to initialize event.resultIndex. I wrote this code in May (read the comment):

/**
 * @param event: a SpeechRecognitionEvent
 */
function handleSpeechRecognitionEvent(checker, event) {
    /* [event.resultIndex] is the index of the first element in [event.results] that has changed,
     * which is [length - 1] most of the times given that user speaks a word at a time.
     * event.resultIndex is always undefined when using the microsoft wrapper library; probably a bug.
     * @TODO: just set [startIndex] to [event.resultIndex] when the bug is solved
     */
    let lastIndex = event.results.length - 1;
    let startIndex = (event.resultIndex !== undefined) ? event.resultIndex : lastIndex;
    ...