Add iOS speech recognition support for web app?

2019-03-26 08:39发布

问题:

Currently, the HTML5 web speech api works great on google chrome for all devices except mobile iOS. Text-to-speech works, but speech-to-text is not supported. webkitSpeechRecognition is not supported. See: Chrome iOS webkit speech-recognition

I am unable to find a workaround. I would like to add speech recognition support for iOS to my current web app that uses speech recognition and speech synthesis. Any suggestions? Thank you.

回答1:

Try something like this

recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition || window.mozSpeechRecognition || window.msSpeechRecognition)();
recognition.lang = "en-US";
recognition.interimResults = false;
recognition.maxAlternatives = 5;
recognition.onresult = function(event) {
  speechResults = event.results[0][0].transcript;
};
recognition.start();

The way the recognition variable is setup allows support for a variety of browsers. I made a Weave at LiveWeave.