macdonst / SpeechRecognitionPlugin

W3C Web Speech API - Speech Recognition plugin for PhoneGap
MIT License
188 stars 97 forks source link

iOS 10 error kAFAssistantErrorDomain - Ionic 2 #88

Open ghost opened 7 years ago

ghost commented 7 years ago

Just create a new ionic 2 project and add your plugin. On iOS 10 give an error: Error happens, – {type: "error", error: 203}

Mode details: Error Domain=kAFAssistantErrorDomain Code=203 "Retry" UserInfo={NSLocalizedDescription=Retry, NSUnderlyingError=0x1702441a0 {Error Domain=SiriSpeechErrorDomain Code=1 "(null)"}}

On android works with no problem.

Same error with this plugin: https://github.com/pbakondy/cordova-plugin-speechrecognition

jcesarmobile commented 7 years ago

Are you testing on a real device or a simulator?

ghost commented 7 years ago

Ofc on a real device, simulator is not allowed to access the microphone!

jcesarmobile commented 7 years ago

Can you provide a sample Ionic 2 app with just the plugin to reproduce the problem? I've never used Ionic 2 and this problem is not present on regular Cordova apps

ghost commented 7 years ago

Give me 20min and i will upload a .rar project here if is ok

jcesarmobile commented 7 years ago

sure

ghost commented 7 years ago

Base code: πŸ”’ /SpeechRecognitionProject/src/pages/home

My steps:

To run my project:

It should be all πŸ‘

-> If you have error with sass: npm rebuild node-sass -> If you have error with permission: chmod 777 /Users/*your_profile*/*project_folder*/node_modules/.bin/ionic-app-scripts

jcesarmobile commented 7 years ago

Thanks for the project, it was very helpful to test on ionic.

But sadly I don't have any clue, I have tried a few times and I got the 203 once, and also the 209 if I click Start Speech multiple times without waiting for the result, but most times it works fine.

203 is GRAMMAR_LOAD_STATE_FAILURE, 209 is GRAMMAR_LOADING_START_FAILURE (https://developer.nuance.com/public/Help/DragonMobileSDKReference_iOS/Error-codes.html)

ghost commented 7 years ago

Hi @jcesarmobile, thx for your answer. Have you tested my project or a new one? If a new one, can you kindly share your code? Thx

I tested my project on an iPhone 5s with latest update (iOS 10.2.1). Tested under Wi-Fi, with airplane mode active. In this phone, i have a Sim card with no service available, just to unlock the device.

When the recognition starts, near the wifi icon appear a search icon too, idk why. Today I finally received a recognition back.

But I have to wait like 1min since I stopped talking. Under Android, as soon as I stop talking, i have a response back.

Now.. How i can handle this?

Thx again.

jcesarmobile commented 7 years ago

Yeah, I have to look if it's possible to control the time of the recognition, it's 1 minute as you say.

You can set interimResults to true, so it return results as soon as they are recognized instead of waiting for the whole minute to finish, but will continue with the recognition until the minute runs out. Maybe you can call stop as soon as you get the first result.

ghost commented 7 years ago

Now is working! This is a good workaround for now! @jcesarmobile, if you can solve this little bug (1min waiting on iOS), it would be perfect!

Thx you!

recognition: any;

constructor(public platform: Platform) {
    this.platform.ready().then(() => {
        this.recognition = new SpeechRecognition(); 
        this.recognition.lang = 'it';
        this.recognition.interimResults = true;

        this.recognition.onnomatch = (event => {
            console.log('No match found.');
        });

        this.recognition.onerror = (event => {
            console.log('Error happens: ', event);
        });

        this.recognition.onresult = (event => {
            if (event.results.length > 0) {
                console.log('Results: ', event.results[0][0].transcript);
                this.recognition.stop();
            }
        });  
    });
}

speech() {
    console.log('Speech start');
    this.recognition.start();
}
ButhSitha commented 7 years ago

HI @mosca90 how to solve this problem? i not found your solution? I got this error also!

Thank!

Pavel-Durov commented 6 years ago

I'm experiencing the same thing, in Ionic v1 app. Cordova error:

Error in Error callbackId: SpeechRecognition1097749174 : TypeError: null is not an object (evaluating 'this.observers.length = 0') callbackFromNative β€” cordova.js:311

Callback error

"Error Domain=kAFAssistantErrorDomain Code=203 "Retry" UserInfo={NSLocalizedDescription=Retry, NSUnderlyingError=0x1c06477a0 {Error Domain=SiriSpeechErrorDomain Code=1 "(null)"}}" Or

"Error Domain=kAFAssistantErrorDomain Code=209 "(null)"" = $1

That happens only on IOS devices for me, Android seems to be working just fine.

It seems like the plugin enters a faulted state, If I leave it idle for about 2 minutes it gets back to work....

IOS Version: 11.2.6 cordova: 4.5.4 ionic: 3.6.0 cordova-plugin-speechrecognition: 1.2.0

hezhk3 commented 5 years ago

"Error Domain=kAFAssistantErrorDomain Code=203 "Retry" UserInfo={NSLocalizedDescription=Retry, NSUnderlyingError=0x1c06477a0 {Error Domain=SiriSpeechErrorDomain Code=1 "(null)"}}"

This error means that it failed to recognize the speech. So you just need to let the users literally RETRY.