package com.cmvr.test.service; import com.cmvr.common.utils.http.CallAPIUtil; 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; import java.util.HashMap; import java.util.Map; @Slf4j @Service @RequiredArgsConstructor public class FlowiseActionService { private final EdgeBioHeadService edgeBioHeadService; public String command(FlowiseActionRequestVO request) { String terminalId = "4ed1246c465b97975f96c9ef8371a3bd"; String bioId = "bio_head"; String action = request.getAction(); FlowiseActionEnum actionEnum = FlowiseActionEnum.fromAction(action); switch (actionEnum) { // ==== 表情 ==== case SMILE: return edgeBioHeadService.specialExpression(terminalId, bioId, 1); case SURPRISED: return edgeBioHeadService.specialExpression(terminalId, bioId, 2); case ANGRY: return edgeBioHeadService.specialExpression(terminalId, bioId, 3); case SAD: return edgeBioHeadService.specialExpression(terminalId, bioId, 4); case SLEEP: return edgeBioHeadService.specialExpression(terminalId, bioId, 5); case YAWN: return edgeBioHeadService.specialExpression(terminalId, bioId, 6); // ==== 动作 ==== default: throw new UnsupportedOperationException("未实现的 Flowise Action: " + action); } } public String chat(String terminalId, String text, String bioId) { // 播放前调用张嘴 EdgeCommonVO edgeCommonVO = new EdgeCommonVO(); edgeCommonVO.setDeviceId(bioId); edgeCommonVO.setTerminalId(terminalId); try { Map 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"; } }