11

Google Chromex-webkit-speechの単純な HTML/JavaScript 拡張機能で新しい関数を使用しようとしています。しかし、私はたくさんの例を試してみましたが、関数を正常に呼び出すことができません。私は他の人がそれをしているのを見たことがありますが、私ができない理由がよくわかりません。JavaScript コードを別のファイルに入れましたが、 <script src="filename.js"> を使用してインクルードします。これは 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 がないため、正しい形式を持っているのが誰なのかを本当に知るのは困難です。

私のonChange機能は次のようになります

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

私はそれが機能することをテストして確認しようとしていますが、何も得られません。

4

3 に答える 3

8

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>

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.

于 2011-04-05T06:53:07.820 に答える
-2

心配しないで、それに従ってみてください。

<!DOCTYPE html> 
<html>
<meta charset="utf-8" />  
<title>Speech Input Test</title>  
<h2>Speech Input Test</h2>
<input id="speech-input-field" type="text" x-webkit-speech="">
<html>
于 2012-10-01T14:28:29.157 に答える