watson-developer-cloud / android-sdk

:high_brightness: Android SDK to use the IBM Watson services.
http://watson-developer-cloud.github.io/android-sdk/
Apache License 2.0
145 stars 96 forks source link

The socket was disconnected for network reasons #68

Open INTKILOW opened 5 years ago

INTKILOW commented 5 years ago

If the socket is disconnected, what should I do to restart correctly

germanattanasio commented 5 years ago

Re-run the method that calls recognize()

INTKILOW commented 5 years ago

Only callback 'onError' after network disconnect The log Com. IBM. Watson. Developer_cloud. Android. If audio. MicrophoneInputStream: Pipe is closed Do I need to manually call websocket.close() or websocket.cancel() to free the current connection

lpatino10 commented 5 years ago

Could you post some code to help understand your question better?

INTKILOW commented 5 years ago
 IamOptions iamOptions = new IamOptions.Builder()
  .apiKey("***")
  .build();

service = new SpeechToText(iamOptions);

service.setEndPoint("https://gateway-tok.watsonplatform.net/speech-to-text/api");
microphoneHelper = new MicrophoneHelper(getActivity());

MicrophoneInputStream m =  microphoneHelper.getInputStream(false);

RecognizeOptions options = new RecognizeOptions.Builder()
  .audio(m)
  .contentType(ContentType.RAW.toString())
  .timestamps(true)
  .wordConfidence(true)
  //.profanityFilter(true)
  .model("ar-AR_BroadbandModel")
  .interimResults(true)
  .inactivityTimeout(5000)
  .build();
m.setOnAmplitudeListener(new AmplitudeListener() {
    @Override
    public void onSample(double amplitude, double volume) {
        Log.e("TalkFragment","(:160)"+volume);
        volumeBar.setProgress((int)volume);
    }
});

service.recognizeUsingWebSocket(options ,new BaseRecognizeCallback(){
    @Override
    public void onTranscription(SpeechRecognitionResults speechResults) {
        Log.e("TalkFragment","(:173)"+"==========="+speechResults);
        if(!isFinish) return;

        SpeechRecognitionResult speechRecognitionResult =  speechResults.getResults().get(0);
        if(speechRecognitionResult.isFinalResults()){
            List<SpeechRecognitionAlternative> alternatives =  speechRecognitionResult.getAlternatives();
            isFinish = false;
            e.onNext(alternatives.get(0).getTranscript());
        }
    }

    @Override
    public void onConnected() {
        Log.e("Main3","(:73)"+"onConnected");
    }

    @Override
    public void onError(Exception x) {
      Log.e("TalkFragment","(:200)"+x.getMessage());

    }

    @Override
    public void onListening() {
        Log.e("Main3","(:83)"+"onListening");
    }

    @Override
    public void onDisconnected() {
        Log.e("TalkFragment","(:212)"+"onDisconnected");
    }
});

———————————————————————————————————————————————

When I turn off wifi, there is only onError callback. How should I reconnect now

germanattanasio commented 5 years ago

If you get an error, log that error using

@Override
public void onError(Exception x) {
  Log.e("Error recognizing audio","(:200)"+x.getMessage());
  startRecognition();
}

Where startRecognition() is:

public void startRecognition() {
  service.recognizeUsingWebSocket(options, this);
}

Something like that.

INTKILOW commented 5 years ago

Session closed. Reason: Payload exceeds the 104857600 bytes limit.

Can I continue to call the service. RecognizeUsingWebSocket (options, this);

germanattanasio commented 5 years ago

You can't send more than 100mb to the service. See https://console.bluemix.net/docs/services/speech-to-text/websockets.html#WSaudio

INTKILOW commented 5 years ago
java.lang.UnsatisfiedLinkError: Can't obtain class com.sun.jna.Pointer
    at com.sun.jna.Native.initIDs(Native Method)
    at com.sun.jna.Native.<clinit>(Native.java:148)
    at com.sun.jna.s.<clinit>(NativeLibrary.java:84)
    at com.sun.jna.s.b(NativeLibrary.java:342)
    at com.ibm.watson.developer_cloud.android.library.a.a.a.<clinit>(JNAOpus.java:43)
    at com.ibm.watson.developer_cloud.android.library.a.a.c.a(OggOpusEnc.java:65)
    at com.ibm.watson.developer_cloud.android.library.a.a.c.<init>(OggOpusEnc.java:52)
    at com.ibm.watson.developer_cloud.android.library.a.d.run(MicrophoneCaptureThread.java:72)
INTKILOW commented 5 years ago

The release version does not recognize speech but the debug version does