Use x-webkit-speech in an HTML/JavaScript extension

后端 未结 3 1288
不知归路
不知归路 2021-02-14 01:39

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 e

相关标签:
3条回答
  • 2021-02-14 02:00

    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.

    0 讨论(0)
  • 2021-02-14 02:06

    Dont worry, just try following it should help

    <!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>
    
    0 讨论(0)
  • 2021-02-14 02:20
    if (document.createElement("input").webkitSpeech === undefined) {
        alert("Speech input is not supported in your browser.");
    }
    

    you can use this code

    0 讨论(0)
提交回复
热议问题