Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The socket was disconnected for network reasons #68

Open
INTKILOW opened this issue Dec 4, 2018 · 9 comments
Open

The socket was disconnected for network reasons #68

INTKILOW opened this issue Dec 4, 2018 · 9 comments
Labels

Comments

@INTKILOW
Copy link

INTKILOW commented Dec 4, 2018

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

@germanattanasio
Copy link
Contributor

Re-run the method that calls recognize()

@INTKILOW
Copy link
Author

INTKILOW commented Dec 5, 2018

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
Copy link
Contributor

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

@INTKILOW
Copy link
Author

INTKILOW commented Dec 6, 2018

 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
Copy link
Contributor

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
Copy link
Author

INTKILOW commented Dec 7, 2018

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

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

@germanattanasio
Copy link
Contributor

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

@INTKILOW
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants