macdonst / SpeechRecognitionPlugin

W3C Web Speech API - Speech Recognition plugin for PhoneGap
MIT License
189 stars 95 forks source link

ReferenceError: Can't find variable: SpeechRecognition on IOS #119

Closed pratikq23 closed 5 years ago

pratikq23 commented 5 years ago

At this line: var recognition = new SpeechRecognition(); i'm getting error ReferenceError: Can't find variable: SpeechRecognition on ios.

It is working on android. But not on IOS

jcesarmobile commented 5 years ago

I can't reproduce. Try deleting and adding the platform again.

pratikq23 commented 5 years ago

i tried deleting the platform and adding it again but it is not working. How you refer the SpeechRecognition object in IOS.

jcesarmobile commented 5 years ago

I just created a new cordova project and pasted the sample code on the readme

<script type="text/javascript">
var recognition;
document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
    recognition = new SpeechRecognition();
    recognition.onresult = function(event) {
        if (event.results.length > 0) {
            q.value = event.results[0][0].transcript;
            q.form.submit();
        }
    }
}
</script>
<form action="http://www.example.com/search">
    <input type="search" id="q" name="q" size=60>
    <input type="button" value="Click to Speak" onclick="recognition.start()">
</form>

Maybe you are trying to use it before deviceready?

pratikq23 commented 5 years ago

Thank you for your reply:) I'm using in it into separate component. I call this function on click self.listen = function() { var recognition = new SpeechRecognition(); recognition.lang = data.LANGUAGE; recognition.onresult = function(event) { if (event.results.length > 0) {

        value1: event.results[0][0].transcript

    }
  };
  recognition.start();

}

It is working smooth on android but not in IOS.