HTML5 Web Speech API not working locally

后端 未结 2 1110
深忆病人
深忆病人 2021-01-05 22:26

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.



             


        
相关标签:
2条回答
  • 2021-01-05 22:37

    Detailed discussion why camera (and microphone are not working on localhost here):

    How to allow Chrome to access my camera on localhost?

    In short, it is explicitly blocked.

    0 讨论(0)
  • 2021-01-05 22:46

    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:// )

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

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