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

Could not get isFinal == true #91

Closed
ThanhLNP opened this issue Mar 12, 2021 · 9 comments
Closed

Could not get isFinal == true #91

ThanhLNP opened this issue Mar 12, 2021 · 9 comments

Comments

@ThanhLNP
Copy link

ThanhLNP commented Mar 12, 2021

Sorry for asking this question here
the following code cannot get final_transcript value, can anyone help me?

<script type="text/javascript">
    var final_transcript = '';
    var recognizing;
    var recognition = new webkitSpeechRecognition();
    recognition.continuous = true;
    recognition.interimResults = true;
    reset();

    recognition.onend = reset();

    recognition.onresult = function(event) {

        var interim_transcript = '';
        for (var i = event.resultIndex; i < event.results.length; ++i) {
            if (event.results[i].isFinal) {
                final_transcript += event.results[i][0].transcript;
            } else {
                interim_transcript += event.results[i][0].transcript;
                console.log(interim_transcript)
            }
        }
        textarea.value += final_transcript;
    }

    function reset() {
        recognizing = false;
        button.innerHTML = "Click to Speak";
    }

    function toggleStartStop() {
        if (recognizing) {
            recognition.stop();
            reset();
        } else {
            recognition.start();
            recognizing = true;
            button.innerHTML = "Click to Stop";
        }
    }
</script>

<textarea id="textarea" rows=10 cols=80></textarea>
<button id="button" onclick="toggleStartStop()"></button>
@foolip
Copy link
Member

foolip commented Mar 12, 2021

@ThanhLNP can you elaborate a little bit? Are you running this code on some browser and never get an event where event.results[i].isFinal is true? I suspect that's because of recognition.continuous = true, but isn't this the behavior you expected?

@ThanhLNP
Copy link
Author

Thank you for the reply,
i'm running on chrome,
and I still want recognition.continuous = true,
but i don't get isFinal like on this demo page https://www.google.com/intl/en/chrome/demos/speech.html

@ThanhLNP
Copy link
Author

Is there a way I can get isFinal = true while recognition.continuous = true?

@foolip
Copy link
Member

foolip commented Mar 17, 2021

@ThanhLNP if you set recognition.interimResults = false, do you get a different behavior?

Is the behavior you're expect that you always see a final event where isFinal is true, even if the interim results ended up being correct?

@ThanhLNP
Copy link
Author

Yes, that's what I mean

For example, when I say "one" I want to get "1" right after
keep saying "two" then I just get "2" right after

Thank you

@foolip
Copy link
Member

foolip commented Mar 18, 2021

@ThanhLNP I was wondering about the case where the interim result is actually correct. Let's say I speak "hello world" and get a first "result" event for "hello" with isFinal being false, but it turns out that "hello" is correct. Are you then expecting another "result" event with "hello" but with isFinal being true? Or is the problem specifically about numbers, "one" vs. "1"?

It would be helpful if you could share a log of the result events you see, what the resultIndex is, and what's in the results list in each event.

@ThanhLNP
Copy link
Author

Yes, the problem is with numbers
but the real problem is I want to get word by word as soon as I say (with recognition.continuous = true), not just get it after stop
as with this demo page: https://www.google.com/intl/en/chrome/demos/speech.html, I see that words are bold after a while, not after stopping

@ThanhLNP
Copy link
Author

ThanhLNP commented Mar 22, 2021

after I added some other handlers I finally got the final_transcript value, I have a demo clip you can check out.

I just want to say that I get the final_transcript value quite slowly, and it returns a lot of times (you can see in the clip)

Your project is wonderful, thank you, and hope it gets better and better
https://drive.google.com/file/d/1MYyN9Z8EXIZfEebdkZFRTIosx8jiso65/view?usp=sharing

continuous = true;
...
recognition.onresult = function(event) {
if (continuous) {
var interim_transcript = '';

    for (var i = event.resultIndex; i < event.results.length; ++i) {
        if (event.results[i].isFinal) {
            final_transcript = event.results[i][0].transcript;
        } else {
            interim_transcript = event.results[i][0].transcript;
        }
    }
} else {
    final_transcript = event.results[0][0].transcript;
}

console.log(final_transcript);

*** some other handles ***

};

@foolip
Copy link
Member

foolip commented Mar 26, 2021

@ThanhLNP thanks for putting together the demo! At this point it seems fairly clear that this isn't necessarily an issue with the spec, which defines all of the events being fired here, but an implementation issue, where Chrome is not behaving the way you're expecting it. Would you be able to file an issue https://crbug.com/new with a test case attached?

@foolip foolip closed this as completed Mar 26, 2021
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