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

Add support for capturing interimResults (Real Time Hypothosis) #101

Open
alanjames1987 opened this issue Feb 17, 2015 · 13 comments
Open

Add support for capturing interimResults (Real Time Hypothosis) #101

alanjames1987 opened this issue Feb 17, 2015 · 13 comments

Comments

@alanjames1987
Copy link

It would be great to have an event listener which allows me to get hypothosis in real time, allowing the user to see what they are saying in real time, similar to how Android's speech input works.

I know the webkitSpeechRecognition allows this and I would be willing to add it once I have time.

@alanjames1987
Copy link
Author

If you're asking why I would want to have real time hypotheses it's because it would allow...

the user to see what they are saying in real time, similar to how Android's speech input works.

Basically to indicate that speech recognition is working.


If you're asking why I would want to add this feature once I have time then it's because I like this library and I want to see it have more features that other developers and I would use.

@alanjames1987
Copy link
Author

That reply has nothing to do with this thread.

@TalAter I don't know if the above comment is from a bot or a person trolling. In either case I will stop responding to it and defer to you to moderate.

@TalAter
Copy link
Owner

TalAter commented Aug 12, 2015

@alanjames1987 This is now possible in annyang v2.0.0

Since v2.0.0, the result, resultNoMatch, resultMatch callbacks are now called with a list of phrases the user said.

So you can do something like:

annyang.addCallback('result', function(phrases) {
  console.log('Speech recognized. Possible sentences said:');
  console.log(phrases);
});

@TalAter TalAter closed this as completed Aug 12, 2015
@alanjames1987
Copy link
Author

Does the 2.0.0 release allow for continuous / real time results?

I don't see a way to enable that.

@alanjames1987
Copy link
Author

Sorry, I was meaning interimResults. I don't see a way to enable that and that was what I was referring to when I called it "real time".

@TalAter
Copy link
Owner

TalAter commented Aug 12, 2015

No.

I think I didn't add it originally because I didn't want to try and match interim results with commands.

But with the new callbacks that can be called with parameters, we could maybe implement interim results as a callback.

We'll need to check if we can enable it without affecting current functionality...

What do you think about this approach?

@TalAter TalAter reopened this Aug 12, 2015
@alanjames1987
Copy link
Author

I think that would be a great approach.

@TalAter TalAter changed the title Real Time Hypothosis Add support for capturing interimResults (Real Time Hypothosis) Aug 13, 2015
@tar-gezed
Copy link

tar-gezed commented May 3, 2016

Hi, I wanted to use your awesome library but I need interimResults on my project :/
Is it possible to implement that ? No news on this issue since 2015 :(
Currently, it's very difficult for somebody to know if the application listen him without interimResult.
I only need a simple render like this one : https://www.google.com/intl/fr/chrome/demos/speech.html (grey interim results, black final results) :)

EDIT: I find a workaround but I think that implement interim results as a callback is a better solution.

  var recognition = annyang.getSpeechRecognizer();
  var final_transcript = '';
  recognition.interimResults = true;
  annyang.start();

      recognition.onresult = function(event) {
        var interim_transcript = '';
        final_transcript = '';
        for (var i = event.resultIndex; i < event.results.length; ++i) {
            if (event.results[i].isFinal) {
                final_transcript += event.results[i][0].transcript;
                console.log("final_transcript");
                console.log(final_transcript);
                annyang.trigger(final_transcript); //If the sentence is "final" for the Web Speech API, we can try to trigger the sentence
            } else {
                interim_transcript += event.results[i][0].transcript;
                console.log("interim_transcript");
                console.log(interim_transcript);
            }
        }
        final_transcript = capitalize(final_transcript);
        final_span.innerHTML = linebreak(final_transcript);
        interim_span.innerHTML = linebreak(interim_transcript);
      };

@busbyk
Copy link

busbyk commented Sep 2, 2016

Thanks @kant73 ! I used that code to implement interim results as well and it's working great.

@ojvribeiro
Copy link

The @kant73 solution for this issue worked perfectly for me.

@Thread7
Copy link

Thread7 commented Jan 11, 2017

I'm trying to get interim results. I see two people here that say they used the above method and it worked. I can't seem to get it to work. Has anything changed since this was posted. Here is my exact code. I had to change it slightly from Kant73's original just because I think he only posted a snippet.

<!DOCTYPE html>
<html class="no-js consumer" lang="en">
  <head>
  <script src='//cdnjs.cloudflare.com/ajax/libs/annyang/2.6.0/annyang.min.js'></script>
<script>
  annyang.start();
  var recognition = annyang.getSpeechRecognizer();
  var final_transcript = '';
  recognition.interimResults = true;
    recognition.onresult = function(event) {
    var interim_transcript = '';
    final_transcript = '';
    for (var i = event.resultIndex; i < event.results.length; ++i) {
        if (event.results[i].isFinal) {
            final_transcript += event.results[i][0].transcript;
            console.log("final_transcript="+final_transcript);
            annyang.trigger(final_transcript); //If the sentence is "final" for the Web Speech API, we can try to trigger the sentence
        } else {
            interim_transcript += event.results[i][0].transcript;
            console.log("interim_transcript="+interim_transcript);
        }
    }

    document.getElementById('123').innerHTML =  'interim='+interim_transcript+'<br/>final='+final_transcript;
	console.log('interim='+interim_transcript+'|final='+final_transcript);
  };
</script>
</head>
<body class="" id="grid">
<br/><br/>
 Annyang! Speech Test<br/><br/>
<div id='123'>
No results yet
 </div>
</body>
 </html>`

Thanks.

@Thread7
Copy link

Thread7 commented Jan 11, 2017

Argh. Sorry I figured it out 2 minutes after posting this. The interim went so fast that it only showed up in the console but never in the <div> on the screen. I figured I'd leave my above comment in case someone wants a full example that works (at least in the console).

@gicontz
Copy link

gicontz commented Jan 24, 2017

Thanks!!!! It saves me a lot :)

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

7 participants