Skip to content
Closed
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 @@ -4,6 +4,7 @@

import com.alibaba.dashscope.base.HalfDuplexServiceParam;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.utils.JsonUtils;
import com.google.gson.JsonObject;
import java.nio.ByteBuffer;
import lombok.*;
Expand Down Expand Up @@ -80,6 +81,9 @@ public JsonObject getHttpBody() {
if (pitch != null) {
input.addProperty("pitch", pitch);
}
if (parameters != null && !parameters.isEmpty()) {
JsonUtils.merge(input, JsonUtils.parametersToJsonObject(parameters));
}

body.add("input", input);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public class OmniRealtimeConfig {
public JsonObject getConfig() {
Map<String, Object> config = new HashMap<>();
config.put(OmniRealtimeConstants.MODALITIES, modalities);
config.put(OmniRealtimeConstants.VOICE, voice);
if (voice != null) {
config.put(OmniRealtimeConstants.VOICE, voice);
}
config.put(OmniRealtimeConstants.INPUT_AUDIO_FORMAT, inputAudioFormat);
config.put(OmniRealtimeConstants.OUTPUT_AUDIO_FORMAT, outputAudioFormat);
if (enableInputAudioTranscription) {
Expand Down Expand Up @@ -95,8 +97,6 @@ public JsonObject getConfig() {
OmniRealtimeConstants.TRANSLATION_CORPUS, this.translationConfig.getCorpus());
}
config.put(OmniRealtimeConstants.TRANSLATION, translationConfig);
} else {
config.put(OmniRealtimeConstants.TRANSLATION, null);
}
// Add transcription configuration for qwen-asr-realtime
if (transcriptionConfig != null) {
Expand All @@ -119,7 +119,16 @@ public JsonObject getConfig() {
OmniRealtimeConstants.INPUT_AUDIO_TRANSCRIPTION_CORPUS,
this.transcriptionConfig.getCorpus());
}
config.put(OmniRealtimeConstants.INPUT_AUDIO_TRANSCRIPTION, transcriptionConfig);
Object existingConfig = config.get(OmniRealtimeConstants.INPUT_AUDIO_TRANSCRIPTION);
if (existingConfig instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> tempMap = (Map<String, Object>) existingConfig;
tempMap.putAll(transcriptionConfig);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The local variable transcriptionConfig (which is a Map) shadows the class field transcriptionConfig (which is an OmniRealtimeTranscriptionParam). This makes the code confusing and error-prone, as the same identifier refers to different types and objects within the same scope. It is highly recommended to rename the local map variable to something more distinct, such as transcriptionMap.

// 显式赋值:利用引用机制虽已更新,但显式 put 能极大增强代码的意图表达和可读性
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comment is written in Chinese, while the rest of the codebase uses English. For consistency and to ensure the code is maintainable by a wider audience, please use English for all comments.

Suggested change
// 显式赋值:利用引用机制虽已更新,但显式 put 能极大增强代码的意图表达和可读性
// Explicit assignment: although the map is updated via reference, explicit put enhances clarity and intent.

config.put(OmniRealtimeConstants.INPUT_AUDIO_TRANSCRIPTION, tempMap);
} else {
config.put(OmniRealtimeConstants.INPUT_AUDIO_TRANSCRIPTION, transcriptionConfig);
}
}
if (parameters != null) {
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void onFailure(WebSocket webSocket, Throwable t, Response response) {

if (isClosed.get()) {
log.debug("called close before but not working, close again in onFailure.");
close(1013, "call closed before");
close(1001, "call closed before");
return;
}

Expand Down Expand Up @@ -240,7 +240,7 @@ public void onFailure(WebSocket webSocket, Throwable t, Response response) {
public void onMessage(WebSocket webSocket, String text) {
if (isClosed.get()) {
log.debug("called close before but not working, close again in onMessage.");
close(1013, "call closed before");
close(1001, "call closed before");
return;
}
log.debug(text);
Expand Down Expand Up @@ -339,7 +339,7 @@ public void onMessage(WebSocket webSocket, ByteString bytes) {
// Invoked when a binary (type 0x2) message has been received.
if (isClosed.get()) {
log.debug("called close before but not working, close again in onMessage.");
close(1013, "call closed before");
close(1001, "call closed before");
return;
}
if (!isFirstMessage.get()) {
Expand All @@ -363,7 +363,7 @@ public void onOpen(WebSocket webSocket, Response response) {
// messages..
if (isClosed.get()) {
log.debug("called close before but not working, close again in onOpen.");
close(1013, "call closed before");
close(1001, "call closed before");
return;
}
isOpen.set(true);
Expand Down
Loading