GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — STT: Close websocket after all data processed · semtle/java-sdk@3f72243

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/websocket
    • WebSocketManager.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/websocket/WebSocketManager.java‎

Copy file name to clipboardExpand all lines: speech-to-text/src/main/java/com/ibm/watson/developer_cloud/speech_to_text/v1/websocket/WebSocketManager.java
+27-23Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,15 @@ public void onMessage(WebSocket webSocket, String message) {
144144
}
145145
} else if (json.has(RESULTS) || json.has(SPEAKER_LABELS)) {
146146
callback.onTranscription(GSON.fromJson(message, SpeechResults.class));
147+
147148
} else if (json.has(STATE)) {
149+
// A listen state after everything has been sent over
150+
// indicates everything has been processed
151+
if (!audioThread.isAlive()) {
152+
socket.close(CLOSE_NORMAL, "Transcription completed");
153+
return;
154+
}
155+
148156
// notify that the service is ready to receive audio
149157
callback.onListening();
150158
}
@@ -162,33 +170,29 @@ public void onOpen(final WebSocket socket, Response response) {
162170
if (!socket.send(buildStartMessage(options))) {
163171
callback.onError(new IOException("WebSocket unavailable"));
164172
} else {
165-
if (audioThread == null) {
166-
// Send the InputStream on a different Thread. Elsewise, interim results cannot be
167-
// received,
168-
// because the Thread that called SpeechToText.recognizeUsingWebSocket is blocked.
169-
audioThread = new Thread() {
170-
@Override
171-
public void run() {
172-
sendInputStream(stream);
173+
// Send the InputStream on a different Thread. Elsewise, interim results cannot be
174+
// received,
175+
// because the Thread that called SpeechToText.recognizeUsingWebSocket is blocked.
176+
audioThread = new Thread() {
177+
@Override
178+
public void run() {
179+
sendInputStream(stream);
173180

174-
// Do not send the stop message, if the socket has been closed already, for example
175-
// because of
176-
// the inactivity timeout.
177-
if (socketOpen) {
178-
// If the socket is still open after the sending finishes, for example because the
179-
// user closed
180-
// the microphone AudioInputStream, send a stop message.
181-
if (!socket.send(buildStopMessage())) {
182-
LOG.log(Level.SEVERE, "Stop message discarded because WebSocket is unavailable");
183-
}
181+
// Do not send the stop message, if the socket has been closed already, for example
182+
// because of
183+
// the inactivity timeout.
184+
if (socketOpen) {
185+
// If the socket is still open after the sending finishes, for example because the
186+
// user closed
187+
// the microphone AudioInputStream, send a stop message.
188+
if (!socket.send(buildStopMessage())) {
189+
LOG.log(Level.SEVERE, "Stop message discarded because WebSocket is unavailable");
184190
}
185191
}
186-
};
192+
}
193+
};
187194

188-
audioThread.start();
189-
} else {
190-
socket.close(CLOSE_NORMAL, "Transcription completed");
191-
}
195+
audioThread.start();
192196
}
193197
}
194198

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.