JoaoCnh / react-native-android-voice

react-native-android-voice is a speech-to-text library for React Native for the Android Platform.
MIT License
101 stars 33 forks source link

Unfortunately app has stopped working #19

Closed sudhanshu6247 closed 7 years ago

sudhanshu6247 commented 8 years ago

whenever I tap on microphone and call the _buttonClick() function, it records voice for 2 seconds and then app gets crashed, giving error "unfortunately app has stopped working" please help.

JoaoCnh commented 8 years ago

Are you testing on a device? Which version of Android are you using?

Which versions of React-Native and such are you using?

I'm severely limited to which devices I can test with.

happierco commented 7 years ago

Same here. Testing on Samsung Note5, if no speech recognized I can try again but if it captures something, app crashes right after with the exception below.

(also crashes when there is a backdrop touch)

Shutting down VM

FATAL EXCEPTION: main
Process: com.voicerecognition, PID: 9872
java.lang.AbstractMethodError: abstract method "void com.facebook.react.bridge.ActivityEventListener.onActivityResult(android.app.Activity, int, int, android.content.Intent)"

    at com.facebook.react.bridge.ReactContext.onActivityResult(ReactContext.java:260)
    at com.facebook.react.XReactInstanceManagerImpl.onActivityResult(XReactInstanceManagerImpl.java:627)
    at com.facebook.react.ReactActivityDelegate.onActivityResult(ReactActivityDelegate.java:135)
    at com.facebook.react.ReactActivity.onActivityResult(ReactActivity.java:77)
    at android.app.Activity.dispatchActivityResult(Activity.java:7137)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4921)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4968)
    at android.app.ActivityThread.access$1600(ActivityThread.java:222)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1849)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7229)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
JoaoCnh commented 7 years ago

I'll investigate as soon as I can. It may need some updates because of React Native versions.

sudhanshu6247 commented 7 years ago

I was testing it on android device. In my case problem was due to 'ToastAndroid', when I removed 'ToastAndroid', it started working fine.

JoaoCnh commented 7 years ago

Ok @sudhanshu6247 that's actually helpful to know.

azraelti commented 7 years ago

@JoaoCnh , Hey, is there any updates for this?

kunsachdeva commented 7 years ago

@sudhanshu6247 is this working for you now? I'm facing the same issue. Which "ToastAndroid" are you talking about exactly?

de-code commented 7 years ago

Perhaps should be raised as a separate issue. The original issue seem to be a JS error in the user's code.

I've created a PR for the onActivityResult issue (which is due to a react native change)

sudhanshu6247 commented 7 years ago

@kunal95 yup, this is working for me. Original code was:

 async _buttonClick(){
try{
    //More Locales will be available upon release.
    var spokenText = await SpeechAndroid.startSpeech("Speak yo", SpeechAndroid.GERMAN);
    ToastAndroid.show(spokenText , ToastAndroid.LONG);
}catch(error){
    switch(error){
        case SpeechAndroid.E_VOICE_CANCELLED:
            ToastAndroid.show("Voice Recognizer cancelled" , ToastAndroid.LONG);
            break;
        case SpeechAndroid.E_NO_MATCH:
            ToastAndroid.show("No match for what you said" , ToastAndroid.LONG);
            break;
        case SpeechAndroid.E_SERVER_ERROR:
            ToastAndroid.show("Google Server Error" , ToastAndroid.LONG);
            break;
        /*And more errors that will be documented on Docs upon release*/
    }
}

}

I just removed ToastAndroid from each line.

My code is

       async _buttonClick(){
try{
    //More Locales will be available upon release.
    var text = await SpeechAndroid.startSpeech("Speak your message", SpeechAndroid.ENGLISH);
    this.props.sendMessage(text);
    console.log("spokenText", spokenText);
}catch(error){
  console.log("spokenText", error);
    switch(error){
        case SpeechAndroid.E_VOICE_CANCELLED:
            break;
        case SpeechAndroid.E_NO_MATCH:
            break;
        case SpeechAndroid.E_SERVER_ERROR:
            break;
        /*And more errors that will be documented on Docs upon release*/
    }
}
}
kunsachdeva commented 7 years ago

@sudhanshu6247 Thats's weird. I'm using RN 0.40.0 and I had to do bunch of changes in onActivityResult and add BaseActivityEventListener object to the module.

JoaoCnh commented 7 years ago

I've just published v0.5.0. Please check if issues still persist for any of you and please feel free to report new ones.

Many thanks to everyone who contributed for v0.5.0 with PRs

JoaoCnh commented 7 years ago

@kunal95 @sudhanshu6247 @de-code @azraelti Anyone try v0.5.0? Can this issue be closed?

JoaoCnh commented 7 years ago

@kunal95 @sudhanshu6247 @de-code @azraelti v0.5.1 has been published. If it works well I'll close this issue. Feel free to re-open