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

Method main

samples/Qwen3AsrRealtimeUsage.java:20–127  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

18 private static final int SLEEP_INTERVAL_MS = 30; // Sleep interval in milliseconds
19
20 public static void main(String[] args) throws InterruptedException, LineUnavailableException {
21
22 OmniRealtimeParam param = OmniRealtimeParam.builder()
23 .model("qwen3-asr-flash-realtime")
24 .apikey(System.getenv("DASHSCOPE_API_KEY"))
25 .build();
26
27 OmniRealtimeConversation conversation = null;
28 final AtomicReference<OmniRealtimeConversation> conversationRef = new AtomicReference<>(null);
29 conversation = new OmniRealtimeConversation(param, new OmniRealtimeCallback() {
30 @Override
31 public void onOpen() {
32 System.out.println("connection opened");
33 }
34 @Override
35 public void onEvent(JsonObject message) {
36 String type = message.get("type").getAsString();
37 switch(type) {
38 case "session.created":
39 System.out.println("start session: " + message.get("session").getAsJsonObject().get("id").getAsString());
40 break;
41 case "conversation.item.input_audio_transcription.completed":
42 System.out.println("question: " + message.get("transcript").getAsString());
43 break;
44 case "response.audio_transcript.delta":
45 System.out.println("got llm response delta: " + message.get("delta").getAsString());
46 break;
47 case "input_audio_buffer.speech_started":
48 System.out.println("======VAD Speech Start======");
49 break;
50 case "input_audio_buffer.speech_stopped":
51 System.out.println("======VAD Speech Stop======");
52 break;
53 case "response.done":
54 System.out.println("======RESPONSE DONE======");
55 if (conversationRef.get() != null) {
56 System.out.println("[Metric] response: " + conversationRef.get().getResponseId() +
57 ", first text delay: " + conversationRef.get().getFirstTextDelay() +
58 " ms, first audio delay: " + conversationRef.get().getFirstAudioDelay() + " ms");
59 }
60 break;
61 default:
62 break;
63 }
64 }
65 @Override
66 public void onClose(int code, String reason) {
67 System.out.println("connection closed code: " + code + ", reason: " + reason);
68 }
69 });
70 conversationRef.set(conversation);
71 try {
72 conversation.connect();
73 } catch (NoApiKeyException e) {
74 throw new RuntimeException(e);
75 }
76
77

Callers

nothing calls this directly

Calls 11

connectMethod · 0.95
setCorpusTextMethod · 0.95
updateSessionMethod · 0.95
appendAudioMethod · 0.95
commitMethod · 0.95
createResponseMethod · 0.95
closeMethod · 0.95
builderMethod · 0.80
buildMethod · 0.65
modelMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected