android-sdk icon indicating copy to clipboard operation
android-sdk copied to clipboard

The socket was disconnected for network reasons

Open INTKILOW opened this issue 6 years ago • 9 comments

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

INTKILOW avatar Dec 04 '18 09:12 INTKILOW

Re-run the method that calls recognize()

germanattanasio avatar Dec 04 '18 15:12 germanattanasio

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

INTKILOW avatar Dec 05 '18 07:12 INTKILOW

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

lpatino10 avatar Dec 05 '18 16:12 lpatino10

 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

INTKILOW avatar Dec 06 '18 01:12 INTKILOW

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.

germanattanasio avatar Dec 06 '18 17:12 germanattanasio

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

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

INTKILOW avatar Dec 07 '18 09:12 INTKILOW

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

germanattanasio avatar Dec 07 '18 21:12 germanattanasio

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 avatar Dec 12 '18 07:12 INTKILOW

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

INTKILOW avatar Dec 12 '18 08:12 INTKILOW