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

Method main

samples/TingWuRealtimeUsage.java:53–101  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

51 };
52
53 public static void main(String[] args) {
54 TingWuRealtimeParam tingWuRealtimeParam = TingWuRealtimeParam.builder()
55 .model("tingwu-industrial-instruction")
56 .format("pcm")
57 .sampleRate(16000)
58 .terminology("terminology") //please replace with your terminology
59 .appId("your-app-id")
60 .apiKey("your-api-key")
61 .build();
62
63 Path filePath = Paths.get("local-path/test.pcm");
64 // 创建任务
65 TingWuRealtime tingWuRealtime = new TingWuRealtime();
66 // 启动任务
67 tingWuRealtime.call(tingWuRealtimeParam, tingWuRealtimeCallback);
68 try {
69 Thread.sleep(100);
70 } catch (InterruptedException e) {
71 throw new RuntimeException(e);
72 }
73 // 发送音频
74 try (FileInputStream fis = new FileInputStream(filePath.toFile())) {
75 // chunk size set to 100 ms for 16KHz sample rate
76 byte[] buffer = new byte[3200];
77 int bytesRead;
78 // Loop to read chunks of the file
79 while ((bytesRead = fis.read(buffer)) != -1) {
80 ByteBuffer byteBuffer;
81 if (bytesRead < buffer.length) {
82 byteBuffer = ByteBuffer.wrap(buffer, 0, bytesRead);
83 } else {
84 byteBuffer = ByteBuffer.wrap(buffer);
85 }
86 // Send the ByteBuffer to the translation and recognition instance
87 tingWuRealtime.sendAudioFrame(byteBuffer);
88 Thread.sleep(100);
89 buffer = new byte[3200];
90 }
91 tingWuRealtime.stop();
92 Thread.sleep(1000 * 10); // wait for 10 seconds
93 tingWuRealtime.getDuplexApi().close(1000, "bye");
94 } catch (Exception e) {
95 e.printStackTrace();
96 tingWuRealtime.getDuplexApi().close(1000, "bye");
97 }
98
99
100 System.exit(0);
101 }
102}

Callers

nothing calls this directly

Calls 11

callMethod · 0.95
sendAudioFrameMethod · 0.95
stopMethod · 0.95
apiKeyMethod · 0.80
formatMethod · 0.80
builderMethod · 0.80
buildMethod · 0.65
closeMethod · 0.65
modelMethod · 0.45
getMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected