HTML5 Web Speech API无法在本地运行 [英] HTML5 Web Speech API not working locally

查看:796
本文介绍了HTML5 Web Speech API无法在本地运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使此代码工作,并且不知道为什么它不能在本地工作。我在CodePen.io上尝试过相同的功能。

I am trying to make this code work and don't know why is it not working locally. I tried the same on CodePen.io and it works.

<html>
<head>
    <title>Voice API</title>

</head>

<body>
    <button onClick="func()">Click Me</button>
    <script>
        function func()
        {
            alert('Hello');
            var recognition = new webkitSpeechRecognition();
            recognition.continuous = true;
            recognition.interimResults = true;
            recognition.onresult = function(event) 
            { 
                alert(event.results[0][0].transcript); 
            }
            recognition.start();
        }
    </script>
</body>

有任何建议吗?

推荐答案

您可以尝试添加以下代码段以查看正在生成的错误。

You could try adding the following snippet to see what error is being generated.

recognition.onerror = function(event) {
    console.log(event.error);
});

有可能吐出'不允许',这通常意味着用户代理不允许出于安全,隐私或用户偏好的原因而发生的任何语音输入(因为您通过文件在本地运行它://)

Chances are its spitting out a 'not-allowed' which generally means that the user agent is not allowing any speech input to occur for reasons of security, privacy or user preference (as you're running it locally through a file:// )

您是否尝试过提供该页面在本地Web服务器下,如(IIS或Node)?

Have you tried serving the page under a local Web Server such as (IIS or Node) ?

这篇关于HTML5 Web Speech API无法在本地运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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