|
|
@@ -9,6 +9,7 @@ import org.dromara.talk.service.ITtsService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
@@ -22,8 +23,8 @@ public class ChatServiceImpl implements IChatService {
|
|
|
private final ITalkAgentService talkAgentService;
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, Object> processMessage(String userMessage, Long agentId) {
|
|
|
- log.info("处理用户消息: {}, 客服ID: {}", userMessage, agentId);
|
|
|
+ public Map<String, Object> processMessage(String userMessage, Long agentId, String agentGender, List<Map<String, String>> ttsVcnList) {
|
|
|
+ log.info("处理用户消息: {}, 客服ID: {}, 客服性别: {}", userMessage, agentId, agentGender);
|
|
|
|
|
|
// 获取客服配置
|
|
|
TalkAgentVo agentConfig = null;
|
|
|
@@ -31,8 +32,15 @@ public class ChatServiceImpl implements IChatService {
|
|
|
agentConfig = talkAgentService.queryById(agentId);
|
|
|
}
|
|
|
|
|
|
- // 生成回复
|
|
|
- String reply = generateReply(userMessage);
|
|
|
+ // 生成回复(预留AI接口,返回包含发言人和文本的JSON)
|
|
|
+ Map<String, String> aiResult = generateReply(userMessage, agentGender, ttsVcnList, agentConfig);
|
|
|
+ String reply = aiResult.get("replyText");
|
|
|
+ String selectedVcn = aiResult.get("ttsVcn");
|
|
|
+
|
|
|
+ // 如果AI选择了发言人,更新客服配置
|
|
|
+ if (selectedVcn != null && agentConfig != null) {
|
|
|
+ agentConfig.setTtsVcn(selectedVcn);
|
|
|
+ }
|
|
|
|
|
|
// 合成语音(传递客服配置)
|
|
|
String audioBase64 = synthesizeAudio(reply, agentConfig);
|
|
|
@@ -50,9 +58,27 @@ public class ChatServiceImpl implements IChatService {
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
- private String generateReply(String userMessage) {
|
|
|
- // 默认回复(后期接入AI)
|
|
|
- return userMessage;
|
|
|
+ private Map<String, String> generateReply(String userMessage, String agentGender, List<Map<String, String>> ttsVcnList, TalkAgentVo agentConfig) {
|
|
|
+ // 组装发送给AI的JSON数据
|
|
|
+ Map<String, Object> aiRequest = new HashMap<>();
|
|
|
+ aiRequest.put("userMessage", userMessage);
|
|
|
+ aiRequest.put("agentGender", agentGender);
|
|
|
+ aiRequest.put("ttsVcnList", ttsVcnList);
|
|
|
+ aiRequest.put("currentVcn", agentConfig != null ? agentConfig.getTtsVcn() : null);
|
|
|
+
|
|
|
+ log.info("AI接口预留 - 请求数据: {}", aiRequest);
|
|
|
+
|
|
|
+ // TODO: 后续接入AI,发送 aiRequest 给AI服务
|
|
|
+ // AI应返回格式: {"ttsVcn": "选择的发言人", "replyText": "回复文本"}
|
|
|
+
|
|
|
+ // 暂时返回默认值
|
|
|
+ Map<String, String> aiResponse = new HashMap<>();
|
|
|
+ aiResponse.put("ttsVcn", agentConfig != null ? agentConfig.getTtsVcn() : "x4_yezi");
|
|
|
+ aiResponse.put("replyText", userMessage);
|
|
|
+
|
|
|
+ log.info("AI接口预留 - 响应数据: {}", aiResponse);
|
|
|
+
|
|
|
+ return aiResponse;
|
|
|
}
|
|
|
|
|
|
private String synthesizeAudio(String text, TalkAgentVo agentConfig) {
|