MCPcopy Create free account
hub / github.com/dashscope/dashscope-sdk-java / onEvent

Method onEvent

samples/QwenLiveQuickStart.java:65–87  ·  view source on GitHub ↗
(JsonObject event)

Source from the content-addressed store, hash-verified

63 Files.newOutputStream(output, StandardOpenOption.CREATE_NEW))) {
64 QwenLiveConversation conversation = new QwenLiveConversation(param, new QwenLiveCallback() {
65 @Override public void onEvent(JsonObject event) {
66 synchronized (audioFile) {
67 if (!accepting.get()) return;
68 try {
69 String type = event.has(FIELD_TYPE) ? event.get(FIELD_TYPE).getAsString() : "";
70 if (EVENT_SESSION_UPDATED.equals(type)) configured.countDown();
71 if (EVENT_SESSION_CLOSED.equals(type)) {
72 onError(new IOException("Session ended before audio idle window."));
73 }
74 if (EVENT_SESSION_OUTPUT_AUDIO_DELTA.equals(type)) {
75 JsonElement audio = event.get(FIELD_AUDIO);
76 if (audio == null || audio.isJsonNull()) audio = event.get(FIELD_DELTA);
77 if (audio == null || audio.isJsonNull()) throw new IOException("Audio event has no audio/delta data.");
78 byte[] bytes = Base64.getDecoder().decode(audio.getAsString());
79 if (bytes.length > 0) {
80 audioFile.write(bytes);
81 lastAudio.set(System.nanoTime());
82 }
83 }
84 } catch (IOException | RuntimeException e) { onError(e); }
85 audioFile.notifyAll();
86 }
87 }
88
89 @Override public void onClose(int code, String reason) {
90 onError(new IOException("WebSocket closed before output settled: " + code));

Callers

nothing calls this directly

Calls 5

onErrorMethod · 0.95
decodeMethod · 0.65
getMethod · 0.45
equalsMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected