From bc6be908b6137565d299fd0d68fcaeea0db57c4c Mon Sep 17 00:00:00 2001 From: stream Date: Thu, 4 Dec 2025 15:04:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9Eflowise=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/test/TeFlowiseController.java | 30 +++++++ .../cmvr/framework/config/SecurityConfig.java | 2 +- .../cmvr/test/enums/FlowiseActionEnum.java | 41 +++++++++ .../edge/vi/ViPlayOperateService.java | 33 ++++---- .../test/model/vo/FlowiseActionRequestVO.java | 12 +++ .../test/service/FlowiseActionService.java | 83 +++++++++++++++++++ 6 files changed, 185 insertions(+), 16 deletions(-) create mode 100644 cmvr-iot-admin/src/main/java/com/cmvr/web/controller/test/TeFlowiseController.java create mode 100644 cmvr-iot-test/src/main/java/com/cmvr/test/enums/FlowiseActionEnum.java create mode 100644 cmvr-iot-test/src/main/java/com/cmvr/test/model/vo/FlowiseActionRequestVO.java create mode 100644 cmvr-iot-test/src/main/java/com/cmvr/test/service/FlowiseActionService.java diff --git a/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/test/TeFlowiseController.java b/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/test/TeFlowiseController.java new file mode 100644 index 0000000..39b854c --- /dev/null +++ b/cmvr-iot-admin/src/main/java/com/cmvr/web/controller/test/TeFlowiseController.java @@ -0,0 +1,30 @@ +package com.cmvr.web.controller.test; + +import com.cmvr.common.core.controller.BaseController; +import com.cmvr.common.core.domain.AjaxResult; +import com.cmvr.test.model.vo.FlowiseActionRequestVO; +import com.cmvr.test.service.FlowiseActionService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Api(tags = "测试--flowise服务") +@RestController +@RequestMapping("/flowise") +@RequiredArgsConstructor +public class TeFlowiseController extends BaseController { + + + private final FlowiseActionService flowiseActionService; + + @ApiOperation("执行指令") + @PostMapping("/action") + public AjaxResult action(@RequestBody FlowiseActionRequestVO request) { + return AjaxResult.ok(flowiseActionService.execute(request)); + } + +} \ No newline at end of file diff --git a/cmvr-iot-framework/src/main/java/com/cmvr/framework/config/SecurityConfig.java b/cmvr-iot-framework/src/main/java/com/cmvr/framework/config/SecurityConfig.java index 7f05ffe..864f08a 100644 --- a/cmvr-iot-framework/src/main/java/com/cmvr/framework/config/SecurityConfig.java +++ b/cmvr-iot-framework/src/main/java/com/cmvr/framework/config/SecurityConfig.java @@ -114,7 +114,7 @@ public class SecurityConfig requests.antMatchers("/login", "/register", "/captchaImage").permitAll() // 静态资源,可匿名访问 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() - .antMatchers("/kws/**","/ws/**","/api/grpc/**","/show/**","/node-red/**","/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() + .antMatchers("/flowise/**","/kws/**","/ws/**","/api/grpc/**","/show/**","/node-red/**","/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() // 除上面外的所有请求全部需要鉴权认证 .anyRequest().authenticated(); }) diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/enums/FlowiseActionEnum.java b/cmvr-iot-test/src/main/java/com/cmvr/test/enums/FlowiseActionEnum.java new file mode 100644 index 0000000..433f456 --- /dev/null +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/enums/FlowiseActionEnum.java @@ -0,0 +1,41 @@ +package com.cmvr.test.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum FlowiseActionEnum { + // ===== 说话 ===== + SPEAK("speak", "tts说话"), + + // ===== 表情控制 ===== + SMILE("smile", "微笑"), + SURPRISED("surprised", "惊讶"), + ANGRY("angry", "愤怒"), + SAD("sad", "悲伤"), + SLEEP("sleep", "睡觉"), + YAWN("yawn", "打哈欠"), + + // ===== 机械臂动作(预留)===== + WAVE("wave", "挥手"), + GRAB("grab", "抓取"), + POINT("point", "指向"), + HEART("heart", "比心"), + RAISE_HAND("raise_hand", "举手"), + RESET_ARM("reset_arm", "机械臂归位"); + + private final String action; + private final String description; + + + // 根据 action 字符串反查枚举 + public static FlowiseActionEnum fromAction(String action) { + for (FlowiseActionEnum e : values()) { + if (e.action.equalsIgnoreCase(action)) { + return e; + } + } + throw new IllegalArgumentException("未实现的 flowise action: " + action); + } +} diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/vi/ViPlayOperateService.java b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/vi/ViPlayOperateService.java index 50ce611..9b607aa 100644 --- a/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/vi/ViPlayOperateService.java +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/flow/runtime/operator/edge/vi/ViPlayOperateService.java @@ -44,28 +44,31 @@ public class ViPlayOperateService implements EdgeOperateService { String deviceId = inputParams.getString("deviceId"); String audioPath = inputParams.getString("audioPath"); String terminalId = message.getTerminalId(); - log.info("播放语料成功,deviceId={},audioPath={},terminalId={}", deviceId, audioPath, terminalId); // 播放前调用张嘴 EdgeCommonVO edgeCommonVO = new EdgeCommonVO(); edgeCommonVO.setDeviceId(deviceId); edgeCommonVO.setTerminalId(terminalId); edgeBioHeadService.speakStart(edgeCommonVO); - edgeSpeakerService.playAudio(terminalId, deviceId, audioPath); - // 等待播放完成 - while (true) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - SpeakerCommand.GetSpeakerStateCommand.Feedback status = edgeSpeakerService.getStatus(terminalId, deviceId); - boolean isRunning = status.getState().getIsRunning(); - if (!isRunning) { - break; + try { + edgeSpeakerService.playAudio(terminalId, deviceId, audioPath); + // 等待播放完成 + while (true) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + SpeakerCommand.GetSpeakerStateCommand.Feedback status = edgeSpeakerService.getStatus(terminalId, deviceId); + boolean isRunning = status.getState().getIsRunning(); + if (!isRunning) { + break; + } } + } finally { + // 播放完成调用闭嘴 + edgeBioHeadService.speakStop(edgeCommonVO); } - // 播放完成调用闭嘴 - edgeBioHeadService.speakStop(edgeCommonVO); + // todo 本机测试播放 // playAudio(audioPath); return TaskNodeExecuteResult.success(); diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/model/vo/FlowiseActionRequestVO.java b/cmvr-iot-test/src/main/java/com/cmvr/test/model/vo/FlowiseActionRequestVO.java new file mode 100644 index 0000000..638a6b5 --- /dev/null +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/model/vo/FlowiseActionRequestVO.java @@ -0,0 +1,12 @@ +package com.cmvr.test.model.vo; + +import lombok.Data; + +@Data +public class FlowiseActionRequestVO { + + private String action; + + + +} diff --git a/cmvr-iot-test/src/main/java/com/cmvr/test/service/FlowiseActionService.java b/cmvr-iot-test/src/main/java/com/cmvr/test/service/FlowiseActionService.java new file mode 100644 index 0000000..737c0ed --- /dev/null +++ b/cmvr-iot-test/src/main/java/com/cmvr/test/service/FlowiseActionService.java @@ -0,0 +1,83 @@ +package com.cmvr.test.service; + +import cmvr.api.SpeakerCommand; +import com.cmvr.edge.client.model.EdgeCommonVO; +import com.cmvr.edge.client.service.EdgeBioHeadService; +import com.cmvr.edge.client.service.EdgeSpeakerService; +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; + +@Slf4j +@Service +@RequiredArgsConstructor +public class FlowiseActionService { + private final EdgeBioHeadService edgeBioHeadService; + private final EdgeSpeakerService edgeSpeakerService; + + public String execute(FlowiseActionRequestVO request) { + String terminalId = "4ed1246c465b97975f96c9ef8371a3bd"; + String spkId = "spk1"; + String bioId = "bio_head"; + String action = request.getAction(); + FlowiseActionEnum actionEnum = FlowiseActionEnum.fromAction(action); + String result; + switch (actionEnum) { + // ==== 说话 ==== + case SPEAK: + EdgeCommonVO edgeCommonVO = new EdgeCommonVO(); + edgeCommonVO.setTerminalId(terminalId); + edgeCommonVO.setDeviceId(bioId); + try { + edgeBioHeadService.speakStart(edgeCommonVO); + result = edgeSpeakerService.playAudio( + terminalId, + spkId, + "/home/share/assets/audio/show_1114/单次对话_标准女_中性_四川话_关闭主驾车窗,调高空调温度,切换为外循环,开启空气净化.wav"); + + // 等待播放完成 + while (true) { + try { + Thread.sleep(200); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + SpeakerCommand.GetSpeakerStateCommand.Feedback status = edgeSpeakerService.getStatus(terminalId, spkId); + boolean isRunning = status.getState().getIsRunning(); + if (!isRunning) { + break; + } + } + try { + Thread.sleep(500); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } finally { + edgeBioHeadService.speakStop(edgeCommonVO); + } + return result; + + // ==== 表情 ==== + case SMILE: + return "微笑"; + case SURPRISED: + return "惊讶"; + case ANGRY: + return "愤怒"; + case SAD: + return "悲伤"; + case SLEEP: + return "睡觉"; + case YAWN: + return "打哈欠"; + + + default: + throw new UnsupportedOperationException("未实现的 Flowise Action: " + action); + } + } +} +