在HTML / JavaScript扩展中使用x-webkit-speech [英] Use x-webkit-speech in an HTML/JavaScript extension

查看:123
本文介绍了在HTML / JavaScript扩展中使用x-webkit-speech的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 x-webkit-speech 函数。 org / wiki / Google_Chromerel =nofollow>谷歌浏览器。然而,我尝试着试着看一堆例子,并且无法成功地调用函数。我见过其他人这样做,我真的不明白为什么我不能。我把JavaScript代码放到一个单独的文件中,但是我使用< script src =filename.js>这是我的x-webkit-speech ...的行....

I am trying to use the new x-webkit-speech function in a simple HTML/JavaScript extension in Google Chrome. I, however, have tried and tried looking at a bunch of examples and cannot get it to successfully call the function. I have seen other people do it, and I don't really get why I cannot. I put the JavaScript code into a separate file, but I include using <script src="filename.js"> this is my line for the x-webkit-speech....

<input id="speechInput" type="text" style="font-size:25px;" x-webkit-speech speech onwebkitspeechchange="onChange()" />

现在,如果我更改 onChange() alert(this.value)时,它会执行一个警报框,其中输入语音的值。所以我真的不明白为什么我不能只调用另一个函数。我不是最伟大的JavaScript或HTML程序员,但我已经研究了很多。每个人都有不同的定义,因为没有可靠的API,所以很难真正知道谁有正确的表单,因为他们似乎都以某种方式工作。

Now, if I change onChange() to alert(this.value), it executes an alert box with the value of the speech input in it. So I really do not understand why I cannot just call another function. I am not the greatest JavaScript or HTML programmer, but I have researched this a great deal. Everyone defines things differently, and since there is no solid API, it is hard to really know who has the correct form, because they all seem to work somehow.

我的 onChange 函数看起来像

function onChange() { alert("in onChange"); } 

我只是试着去测试它,并确定它会进入函数,但我什么也没得到。

I am just trying to test and make sure it's going to the function, but I get nothing.

推荐答案

我今天在玩这个功能,实际上你的代码似乎没问题,适合我。完整版本如下:

I was playing around with this feature today and actually your code seems to be OK and works for me. The full version would be the following:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Speech</title>
</head>

<script type="text/javascript" charset="utf-8">
    function onChange() {
        alert('changed');
    }
</script>

<body>

    <input id="speechInput" type="text" style="font-size:25px;"
           x-webkit-speech onwebkitspeechchange="onChange()" />

</body>
</html>

虽然我注意到如果Chrome无法识别语音,onChange()不会被调用。我正在使用Chrome 11.0.696.28测试版。如果您只针对基于webkit的浏览器(如Chrome或Safari),则语音属性也不是必需的。即使你把它放进去,它也不适用于Firefox 4.因为我没有它,所以不知道IE9。

Though I did notice that onChange() does not get called if Chrome fails to recognize the speech. I'm using Chrome 11.0.696.28 beta. Also the speech attribute is not necessary if you're targeting only webkit-based browsers like Chrome or Safari. And even if you leave it in, it doesn't work with Firefox 4. Not sure about IE9 since I don't have it.

这篇关于在HTML / JavaScript扩展中使用x-webkit-speech的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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