SpeechRecognition having issues in Safari (v17.1)

I was trying to implement a speech recognition using the web speech API (see the doc for webkit API).

Below is the code : (Angular -Typescript -v14)

if ('webkitSpeechRecognition' in window) {
          var webkitSpeechRecognition;
	      var SpeechRecognition = SpeechRecognition;
	      const vSearch = new webkitSpeechRecognition() || new SpeechRecognition();
	      vSearch.continuous = true;
	      vSearch.interimresults = false;
	      vSearch.lang = 'en-US';
	      vSearch.start(); //start listening

     vSearch.onresult = (e) => { //onResults
	        let voiceSearchResults = e.results[0][0].transcript;
	        console.log("result: ",voiceSearchResults)
     }

      vSearch.onend = () => {
        vSearch.stop(); //stop listening

      }
}
else{
console.log("webkitspeech recognition not supported in browser");
}


Now this piece of code works perfectly in Chrome. But when I run this is Safari I found the below issues:

  1. If Siri / Listen to 'Hey Siri' option is enabled in Mac settings, then I am not getting any response in .onresult method.
  2. If Siri is disabled, then after the Microphone permission is given, we will need to wait for 2-3 seconds and then speak, otherwise voice is not getting captured.
  3. Voice is not properly getting captured in Safari like chrome. Sometimes some words are skipped.
  4. in Chrome, once we speak and stops, then onResult is triggered automatically. But in Safari, I had to write another condition for vSearch.stop() after 5 seconds. Otherwise microphone will be listening continuously.


It is said in the documentation that webkitspeech is supproted in Safari v14 or above.


Kindly share any inputs that will help solving this.



Thanks in advance.

MacBook Pro (2021)

Posted on Feb 23, 2024 1:36 AM

Reply

Similar questions

There are no replies.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

SpeechRecognition having issues in Safari (v17.1)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.