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:
- If Siri / Listen to 'Hey Siri' option is enabled in Mac settings, then I am not getting any response in .onresult method.
- 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.
- Voice is not properly getting captured in Safari like chrome. Sometimes some words are skipped.
- 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)