HTML5 Web Speech API not working locally

I am trying to get this code to work and don’t know why it doesn’t work locally. I tried the same thing 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> 

Any suggestions?

+5
source share
2 answers

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

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

Most likely, he spits out “invalid”, which usually means that the user agent does not allow you to enter any kind of speech input for reasons of security, privacy or user preference (since you use it locally through the file: //)

Have you tried serving the page under a local web server, for example (IIS or Node)?

+7
source

A detailed discussion of why the camera (and the microphone do not work on the local host here):

How to allow Chrome access to my camera on a local hosting?

In short, it is clearly blocked.

0
source

Source: https://habr.com/ru/post/1209074/


All Articles