2025-12-04 15:04:46 +08:00
|
|
|
package com.cmvr.test.service;
|
|
|
|
|
|
2025-12-05 17:04:51 +08:00
|
|
|
import com.cmvr.common.utils.http.CallAPIUtil;
|
2025-12-04 15:04:46 +08:00
|
|
|
import com.cmvr.edge.client.model.EdgeCommonVO;
|
|
|
|
|
import com.cmvr.edge.client.service.EdgeBioHeadService;
|
|
|
|
|
import com.cmvr.test.enums.FlowiseActionEnum;
|
|
|
|
|
import com.cmvr.test.model.vo.FlowiseActionRequestVO;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
2025-12-05 17:04:51 +08:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
2025-12-04 15:04:46 +08:00
|
|
|
@Slf4j
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class FlowiseActionService {
|
|
|
|
|
private final EdgeBioHeadService edgeBioHeadService;
|
|
|
|
|
|
2025-12-05 17:04:51 +08:00
|
|
|
public String command(FlowiseActionRequestVO request) {
|
2025-12-04 15:04:46 +08:00
|
|
|
String terminalId = "4ed1246c465b97975f96c9ef8371a3bd";
|
|
|
|
|
String bioId = "bio_head";
|
|
|
|
|
String action = request.getAction();
|
|
|
|
|
FlowiseActionEnum actionEnum = FlowiseActionEnum.fromAction(action);
|
|
|
|
|
switch (actionEnum) {
|
|
|
|
|
// ==== 表情 ====
|
|
|
|
|
case SMILE:
|
2025-12-05 17:04:51 +08:00
|
|
|
return edgeBioHeadService.specialExpression(terminalId, bioId, 1);
|
2025-12-04 15:04:46 +08:00
|
|
|
case SURPRISED:
|
2025-12-05 17:04:51 +08:00
|
|
|
return edgeBioHeadService.specialExpression(terminalId, bioId, 2);
|
2025-12-04 15:04:46 +08:00
|
|
|
case ANGRY:
|
2025-12-05 17:04:51 +08:00
|
|
|
return edgeBioHeadService.specialExpression(terminalId, bioId, 3);
|
2025-12-04 15:04:46 +08:00
|
|
|
case SAD:
|
2025-12-05 17:04:51 +08:00
|
|
|
return edgeBioHeadService.specialExpression(terminalId, bioId, 4);
|
2025-12-04 15:04:46 +08:00
|
|
|
case SLEEP:
|
2025-12-05 17:04:51 +08:00
|
|
|
return edgeBioHeadService.specialExpression(terminalId, bioId, 5);
|
2025-12-04 15:04:46 +08:00
|
|
|
case YAWN:
|
2025-12-05 17:04:51 +08:00
|
|
|
return edgeBioHeadService.specialExpression(terminalId, bioId, 6);
|
2025-12-04 15:04:46 +08:00
|
|
|
|
2025-12-05 17:04:51 +08:00
|
|
|
// ==== 动作 ====
|
2025-12-04 15:04:46 +08:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
throw new UnsupportedOperationException("未实现的 Flowise Action: " + action);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-05 17:04:51 +08:00
|
|
|
|
|
|
|
|
public String chat(String terminalId, String text, String bioId) {
|
|
|
|
|
// 播放前调用张嘴
|
|
|
|
|
EdgeCommonVO edgeCommonVO = new EdgeCommonVO();
|
|
|
|
|
edgeCommonVO.setDeviceId(bioId);
|
|
|
|
|
edgeCommonVO.setTerminalId(terminalId);
|
|
|
|
|
try {
|
|
|
|
|
Map<String, String> body = new HashMap<>();
|
|
|
|
|
body.put("text", text);
|
|
|
|
|
body.put("voice", "x4_yezi");
|
|
|
|
|
|
|
|
|
|
// edgeBioHeadService.speakStart(edgeCommonVO);
|
|
|
|
|
CallAPIUtil.doPostJson("192.168.0.222:8080/tts/play", null, body);
|
|
|
|
|
} finally {
|
|
|
|
|
// 播放完成调用闭嘴
|
|
|
|
|
// edgeBioHeadService.speakStop(edgeCommonVO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "ok";
|
|
|
|
|
}
|
2025-12-04 15:04:46 +08:00
|
|
|
}
|
|
|
|
|
|