Chrome版本60 SpeechRecognition

Nic*_*dis 11 google-chrome

版本60之后,非HTTPS网站禁用了webkitSpeechRecognition.这主要是用于发展目的的主要问题.有没有办法绕过/禁用此安全功能?

问题是,应该询问您是否要访问麦克风的弹出窗口从不在HTTP上显示,但它在HTTPS上.

为DEV设置HTTPS并不容易,所以我真的需要一种方法来绕过它.

Her*_*ral 1

我在本地尝试过,没有 HTTPS,效果很好。如果文件直接从文件系统提供,但在静态文件服务器的帮助下(我正在使用python3 -m http.server)的帮助下,我设法让它工作。

希望能帮助到你!

<html>
    <head>
        <title>Teste</title>
    </head>
    <body>
        <button id="btn">capture</button>
        <script src="https://code.jquery.com/jquery-3.2.1.min.js"> </script>
        <script>
            $(document).ready(function(){
                var recognition = new webkitSpeechRecognition();
                recognition.onresult = function(event) { 
                  console.log(event) 
                }
                var started = false;
                $('#btn').click(function(){
                    if (started){
                        recognition.stop();
                        $(this).html('capture');
                        started = false;
                    }
                    else{
                        recognition.start();
                        started = true;
                        $(this).html('stop');
                    }
                });
            })
        </script>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

编辑:jQuery 不是必需的。这只是我的一个老习惯:-)