Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,16 @@ public void onError(Exception e) {
*/
public void onDisconnected() { };

/* (non-Javadoc)
* @see com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.RecognizeCallback#onInactivityTimeout(java.lang.RuntimeException)
*/
@Override
public void onInactivityTimeout(RuntimeException runtimeException) { };

/* (non-Javadoc)
* @see com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.RecognizeCallback#onListening()
*/
@Override
public void onListening() { };

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/*
* Copyright 2015 IBM Corp. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.ibm.watson.developer_cloud.speech_to_text.v1.websocket;

Expand Down Expand Up @@ -47,4 +46,16 @@ public interface RecognizeCallback {
* Called when a WebSocket connection was closed.
*/
void onDisconnected();

/**
* Called when there is an inactivity timeout.
*
* @param runtimeException the runtime exception
*/
void onInactivityTimeout(RuntimeException runtimeException);

/**
* Called when the service is listening for audio.
*/
void onListening();
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,21 @@ public void onMessage(WebSocket webSocket, String message) {
if (json.has(ERROR)) {
String error = json.get(ERROR).getAsString();

// Only call onError() if a real error occured. The STT service sends
// Only call onError() if a real error occurred. The STT service sends
// {"error" : "No speech detected for 5s"} for valid timeouts, configured by
// RecognizeOptions.Builder.inactivityTimeout()
if (!error.startsWith(TIMEOUT_PREFIX)) {
callback.onError(new RuntimeException(error));
} else {
// notify that the service timeouts because of inactivity
callback.onInactivityTimeout(new RuntimeException(error));
}
} else if (json.has(RESULTS) || json.has(SPEAKER_LABELS)) {
callback.onTranscription(GSON.fromJson(message, SpeechResults.class));
} else if (json.has(STATE)) {
// notify that the service is ready to receive audio
callback.onListening();

if (audioThread == null) {
// Send the InputStream on a different Thread. Elsewise, interim results cannot be
// received,
Expand Down