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 @@ -71,6 +71,12 @@ public void onError(Exception e) {
* @see com.ibm.watson.developer_cloud.speech_to_text.v1.websocket.RecognizeCallback#onListening()
*/
@Override
public void onListening() { };
public void onListening() { }

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ public interface RecognizeCallback {
* Called when the service is listening for audio.
*/
void onListening();

/**
* Called after the service returns the final result for the transcription.
*/
void onTranscriptionComplete();
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public void onMessage(WebSocket webSocket, String message) {
if (!isListening) {
isListening = true;
} else {
callback.onTranscriptionComplete();
socket.close(CLOSE_NORMAL, "Transcription completed");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import org.junit.Assume;
import org.junit.Before;
Expand Down Expand Up @@ -65,6 +66,7 @@ public class SpeechToTextIT extends WatsonServiceTest {
private static final String SAMPLE_WAV = String.format(SPEECH_RESOURCE, "sample1.wav");
private static final String TWO_SPEAKERS_WAV = String.format(SPEECH_RESOURCE, "twospeakers.wav");
private static final String SAMPLE_WAV_WITH_PAUSE = String.format(SPEECH_RESOURCE, "sound-with-pause.wav");
private static final Logger LOG = Logger.getLogger(SpeechToTextIT.class.getName());

private CountDownLatch lock = new CountDownLatch(1);
private SpeechToText service;
Expand Down Expand Up @@ -294,12 +296,17 @@ public void testRecognizeWebSocket() throws FileNotFoundException, InterruptedEx

@Override
public void onConnected() {
System.out.println("onConnected()");
LOG.info("onConnected()");
}

@Override
public void onDisconnected() {
System.out.println("onDisconnected()");
LOG.info("onDisconnected()");
}

@Override
public void onTranscriptionComplete() {
LOG.info("onTranscriptionComplete()");
lock.countDown();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ public void testClosingInputStreamClosesWebSocket() throws Exception {
callback.assertConnected();
callback.assertDisconnected();
callback.assertNoErrors();
callback.assertOnTranscriptionComplete();
}

private static class TestRecognizeCallback implements RecognizeCallback {
Expand All @@ -908,6 +909,8 @@ private static class TestRecognizeCallback implements RecognizeCallback {

private final BlockingQueue<Object> onConnectedCalls = new LinkedBlockingQueue<>();

private final BlockingQueue<Object> onTranscriptionCompleteCalls = new LinkedBlockingQueue<>();

@Override
public void onTranscription(SpeechResults speechResults) {
this.speechResults.add(speechResults);
Expand All @@ -928,6 +931,12 @@ public void onDisconnected() {
this.onDisconnectedCalls.add(new Object());
}

void assertOnTranscriptionComplete() {
if (this.onTranscriptionCompleteCalls.size() == 1) {
throw new AssertionError("There were " + this.errors.size() + " calls to onTranscriptionComplete");
}
}

void assertConnected() {
try {
Object connectedEvent = this.onConnectedCalls.poll(10, TimeUnit.SECONDS);
Expand Down Expand Up @@ -961,5 +970,11 @@ public void onInactivityTimeout(RuntimeException runtimeException) { }

@Override
public void onListening() { }

@Override
public void onTranscriptionComplete() {
this.onTranscriptionCompleteCalls.add(new Object());

}
}
}