|
|
@@ -3,6 +3,7 @@ package org.dromara.talk.service.impl;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dromara.talk.domain.vo.TalkAgentVo;
|
|
|
import org.dromara.talk.service.ITtsService;
|
|
|
import org.java_websocket.client.WebSocketClient;
|
|
|
import org.java_websocket.handshake.ServerHandshake;
|
|
|
@@ -34,11 +35,11 @@ public class TtsServiceImpl implements ITtsService {
|
|
|
private static final String HOST_URL = "https://tts-api.xfyun.cn/v2/tts";
|
|
|
|
|
|
@Override
|
|
|
- public void synthesize(String text, ITtsService.AudioCallback callback) {
|
|
|
+ public void synthesize(String text, TalkAgentVo agentConfig, ITtsService.AudioCallback callback) {
|
|
|
try {
|
|
|
String wsUrl = getAuthUrl(HOST_URL, apiKey, apiSecret).replace("https://", "wss://");
|
|
|
URI uri = new URI(wsUrl);
|
|
|
- String requestJson = buildRequest(text);
|
|
|
+ String requestJson = buildRequest(text, agentConfig);
|
|
|
|
|
|
WebSocketClient client = new WebSocketClient(uri) {
|
|
|
@Override
|
|
|
@@ -83,16 +84,25 @@ public class TtsServiceImpl implements ITtsService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private String buildRequest(String text) {
|
|
|
+ private String buildRequest(String text, TalkAgentVo agentConfig) {
|
|
|
+ // 使用客服配置的TTS参数,如果没有则使用默认值
|
|
|
+ String vcn = agentConfig != null && agentConfig.getTtsVcn() != null ? agentConfig.getTtsVcn() : "x4_yezi";
|
|
|
+ Long speed = agentConfig != null && agentConfig.getTtsSpeed() != null ? agentConfig.getTtsSpeed() : 50L;
|
|
|
+ Long pitch = agentConfig != null && agentConfig.getTtsPitch() != null ? agentConfig.getTtsPitch() : 50L;
|
|
|
+ Long volume = agentConfig != null && agentConfig.getTtsVolume() != null ? agentConfig.getTtsVolume() : 50L;
|
|
|
+ Long bgs = agentConfig != null && agentConfig.getTtsBgs() != null ? agentConfig.getTtsBgs() : 0L;
|
|
|
+
|
|
|
return "{\n" +
|
|
|
" \"common\": {\"app_id\": \"" + appId + "\"},\n" +
|
|
|
" \"business\": {\n" +
|
|
|
" \"aue\": \"lame\",\n" +
|
|
|
" \"tte\": \"UTF8\",\n" +
|
|
|
" \"ent\": \"intp65\",\n" +
|
|
|
- " \"vcn\": \"x4_yezi\",\n" +
|
|
|
- " \"speed\": 50,\n" +
|
|
|
- " \"pitch\": 50\n" +
|
|
|
+ " \"vcn\": \"" + vcn + "\",\n" +
|
|
|
+ " \"speed\": " + speed + ",\n" +
|
|
|
+ " \"pitch\": " + pitch + ",\n" +
|
|
|
+ " \"volume\": " + volume + ",\n" +
|
|
|
+ " \"bgs\": " + bgs + "\n" +
|
|
|
" },\n" +
|
|
|
" \"data\": {\n" +
|
|
|
" \"status\": 2,\n" +
|