Skip to content

Commit 512dc35

Browse files
authored
param build fixes for audio models (#208)
* fix(websocket): fix close code error used * feat(model/cosyvoice): add parameters support in body build * feat(model/live-translate): fix params build
1 parent 14cee10 commit 512dc35

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/main/java/com/alibaba/dashscope/audio/http_tts/HttpSpeechSynthesisParam.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.alibaba.dashscope.base.HalfDuplexServiceParam;
66
import com.alibaba.dashscope.exception.InputRequiredException;
7+
import com.alibaba.dashscope.utils.JsonUtils;
78
import com.google.gson.JsonObject;
89
import java.nio.ByteBuffer;
910
import lombok.*;
@@ -80,6 +81,9 @@ public JsonObject getHttpBody() {
8081
if (pitch != null) {
8182
input.addProperty("pitch", pitch);
8283
}
84+
if (parameters != null && !parameters.isEmpty()) {
85+
JsonUtils.merge(input, JsonUtils.parametersToJsonObject(parameters));
86+
}
8387

8488
body.add("input", input);
8589

src/main/java/com/alibaba/dashscope/audio/omni/OmniRealtimeConfig.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public class OmniRealtimeConfig {
5858
public JsonObject getConfig() {
5959
Map<String, Object> config = new HashMap<>();
6060
config.put(OmniRealtimeConstants.MODALITIES, modalities);
61-
config.put(OmniRealtimeConstants.VOICE, voice);
61+
if (voice != null) {
62+
config.put(OmniRealtimeConstants.VOICE, voice);
63+
}
6264
config.put(OmniRealtimeConstants.INPUT_AUDIO_FORMAT, inputAudioFormat);
6365
config.put(OmniRealtimeConstants.OUTPUT_AUDIO_FORMAT, outputAudioFormat);
6466
if (enableInputAudioTranscription) {
@@ -95,8 +97,6 @@ public JsonObject getConfig() {
9597
OmniRealtimeConstants.TRANSLATION_CORPUS, this.translationConfig.getCorpus());
9698
}
9799
config.put(OmniRealtimeConstants.TRANSLATION, translationConfig);
98-
} else {
99-
config.put(OmniRealtimeConstants.TRANSLATION, null);
100100
}
101101
// Add transcription configuration for qwen-asr-realtime
102102
if (transcriptionConfig != null) {
@@ -119,7 +119,15 @@ public JsonObject getConfig() {
119119
OmniRealtimeConstants.INPUT_AUDIO_TRANSCRIPTION_CORPUS,
120120
this.transcriptionConfig.getCorpus());
121121
}
122-
config.put(OmniRealtimeConstants.INPUT_AUDIO_TRANSCRIPTION, transcriptionConfig);
122+
Object existingConfig = config.get(OmniRealtimeConstants.INPUT_AUDIO_TRANSCRIPTION);
123+
if (existingConfig instanceof Map) {
124+
@SuppressWarnings("unchecked")
125+
Map<String, Object> tempMap = (Map<String, Object>) existingConfig;
126+
tempMap.putAll(transcriptionConfig);
127+
config.put(OmniRealtimeConstants.INPUT_AUDIO_TRANSCRIPTION, tempMap);
128+
} else {
129+
config.put(OmniRealtimeConstants.INPUT_AUDIO_TRANSCRIPTION, transcriptionConfig);
130+
}
123131
}
124132
if (parameters != null) {
125133
for (Map.Entry<String, Object> entry : parameters.entrySet()) {

src/main/java/com/alibaba/dashscope/protocol/okhttp/OkHttpWebSocketClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public void onFailure(WebSocket webSocket, Throwable t, Response response) {
207207

208208
if (isClosed.get()) {
209209
log.debug("called close before but not working, close again in onFailure.");
210-
close(1013, "call closed before");
210+
close(1001, "call closed before");
211211
return;
212212
}
213213

@@ -240,7 +240,7 @@ public void onFailure(WebSocket webSocket, Throwable t, Response response) {
240240
public void onMessage(WebSocket webSocket, String text) {
241241
if (isClosed.get()) {
242242
log.debug("called close before but not working, close again in onMessage.");
243-
close(1013, "call closed before");
243+
close(1001, "call closed before");
244244
return;
245245
}
246246
log.debug(text);
@@ -339,7 +339,7 @@ public void onMessage(WebSocket webSocket, ByteString bytes) {
339339
// Invoked when a binary (type 0x2) message has been received.
340340
if (isClosed.get()) {
341341
log.debug("called close before but not working, close again in onMessage.");
342-
close(1013, "call closed before");
342+
close(1001, "call closed before");
343343
return;
344344
}
345345
if (!isFirstMessage.get()) {
@@ -363,7 +363,7 @@ public void onOpen(WebSocket webSocket, Response response) {
363363
// messages..
364364
if (isClosed.get()) {
365365
log.debug("called close before but not working, close again in onOpen.");
366-
close(1013, "call closed before");
366+
close(1001, "call closed before");
367367
return;
368368
}
369369
isOpen.set(true);

0 commit comments

Comments
 (0)