android-sdk
android-sdk copied to clipboard
The socket was disconnected for network reasons
If the socket is disconnected, what should I do to restart correctly
Re-run the method that calls recognize()
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
Could you post some code to help understand your question better?
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
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.
Session closed. Reason: Payload exceeds the 104857600 bytes limit.
Can I continue to call the service. RecognizeUsingWebSocket (options, this);
You can't send more than 100mb to the service. See https://console.bluemix.net/docs/services/speech-to-text/websockets.html#WSaudio
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)
The release version does not recognize speech but the debug version does