webkitSpeechRecognition是"落后"在搜集结果背后 [英] webkitSpeechRecognition is "lagging" behind when gathering results

查看:175
本文介绍了webkitSpeechRecognition是"落后"在搜集结果背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

等不及要尝试一下<一个href=\"http://updates.html5rocks.com/2013/01/Voice-Driven-Web-Apps-Introduction-to-the-Web-Speech-API\"相对=nofollow称号=网络语音API>网络语音API 。
我复制了code正是从这篇文章,和我有,你讲的问题,但没有任何反应,直到你说话试。

Had an itch to try out the Web Speech API. I copied the code exactly from the article, and I'm having an issue where you speak, but nothing happens until you speak AGAIN.

[小提琴: http://jsfiddle.net/w75v2tm5/ ]

JS:

if (!('webkitSpeechRecognition' in window)) {
    //handle error stuff here...
} else {
    var recognition = new webkitSpeechRecognition();
    recognition.continuous = true;
    recognition.interimResults = false;

    recognition.start();

    var final_transcript = '';

    recognition.onresult = function (event) {
        var interim_transcript = '';
        if (typeof (event.results) == 'undefined') {
            recognition.onend = null;
            recognition.stop();
            upgrade();
            return;
        }
        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;
            }
        }
        document.getElementsByTagName('div')[0].innerText = final_transcript;
    };

}

例如,如果我说世界,你好中,&lt; DIV&GT;我已经建立了以显示结果不会显示Hello World的,直到我说的话,或做了一个声音。但是,如果我说的话,那会不会显示,直到我说的话一次。

For example, if I were to say "Hello world", the <div> I have set up to display the results would not display "Hello world" until I said something else, or made a sound. But if I said something else, THAT would not be displayed until I said something else AGAIN.

变量final_t​​ranscript是抱着preVIOUS结果,而不是。它只需1的关闭。

The variable "final_transcript" is holding the PREVIOUS result, and not what I just said. It's off by just 1.

要给你一个更好的主意...

To give you a better idea...

我说:世界,你好

final_t​​ranscript ='';

final_transcript = '';

[等待...]

我说:测试

final_t​​ranscript =世界,你好

final_transcript = 'Hello world'

而这只是还在继续。在code未能抄写什么,我说,因为我说了。十分怪异。

And this just continues. The code is failing to transcribe what I am saying AS I am saying it. Very weird.

有什么想法,为什么这可能是?

Any thoughts as to why this could be?

推荐答案

有某种建于超时,之后你会得到,即使没有更多的输入结果(似乎是大约5-10秒) 。

There is some kind of built in timeout, after which you will get the result even if there is no more input (seems to be around 5-10 seconds).

在这种情况下,你会得到最终的 onresult 事件,以及在 onend 事件。你将不得不调用 recognition.start()再次,如果你想保留接受输入。

In this case you will get the final onresult event, as well as the onend event. You will have to call recognition.start() again if you wish to keep accepting input.

另外,如果设置

recognition.interimResults = true;

您将获得 onresult 与非最终结果的事件,你可以决定是否要你获得最终的之前显示它们。

you will get onresult events with non final results, and you can decide if you want to display them before you get the final ones.

另一个选项是关闭与连续

The other option is to turn off continuous with

recognition.continuous = false;

您将得到一个结果后不久,输入(音频)停止。
您也将获得 onend 事件。结果
如果您想继续的认可,你将不得不再次调用

you will get a result shortly after the input (audio) stopped. You will also get the onend event.
If you wish to continue the recognition you will have to call again

recognition.start();

onend 事件处理程序。结果
在非HTTPS页面,这将导致权限栏再次弹出。

in the onend event handler.
On a non HTTPS page, this will cause the permission bar to pop up again.

请参见例如

这篇关于webkitSpeechRecognition是&QUOT;落后&QUOT;在搜集结果背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆