feat: 新增flowise调用接口
This commit is contained in:
parent
4fdc4e7cd7
commit
bc6be908b6
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -114,7 +114,7 @@ public class SecurityConfig
|
|||||||
requests.antMatchers("/login", "/register", "/captchaImage").permitAll()
|
requests.antMatchers("/login", "/register", "/captchaImage").permitAll()
|
||||||
// 静态资源,可匿名访问
|
// 静态资源,可匿名访问
|
||||||
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").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();
|
.anyRequest().authenticated();
|
||||||
})
|
})
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -44,28 +44,31 @@ public class ViPlayOperateService implements EdgeOperateService {
|
|||||||
String deviceId = inputParams.getString("deviceId");
|
String deviceId = inputParams.getString("deviceId");
|
||||||
String audioPath = inputParams.getString("audioPath");
|
String audioPath = inputParams.getString("audioPath");
|
||||||
String terminalId = message.getTerminalId();
|
String terminalId = message.getTerminalId();
|
||||||
log.info("播放语料成功,deviceId={},audioPath={},terminalId={}", deviceId, audioPath, terminalId);
|
|
||||||
// 播放前调用张嘴
|
// 播放前调用张嘴
|
||||||
EdgeCommonVO edgeCommonVO = new EdgeCommonVO();
|
EdgeCommonVO edgeCommonVO = new EdgeCommonVO();
|
||||||
edgeCommonVO.setDeviceId(deviceId);
|
edgeCommonVO.setDeviceId(deviceId);
|
||||||
edgeCommonVO.setTerminalId(terminalId);
|
edgeCommonVO.setTerminalId(terminalId);
|
||||||
edgeBioHeadService.speakStart(edgeCommonVO);
|
edgeBioHeadService.speakStart(edgeCommonVO);
|
||||||
edgeSpeakerService.playAudio(terminalId, deviceId, audioPath);
|
try {
|
||||||
// 等待播放完成
|
edgeSpeakerService.playAudio(terminalId, deviceId, audioPath);
|
||||||
while (true) {
|
// 等待播放完成
|
||||||
try {
|
while (true) {
|
||||||
Thread.sleep(1000);
|
try {
|
||||||
} catch (InterruptedException e) {
|
Thread.sleep(500);
|
||||||
throw new RuntimeException(e);
|
} catch (InterruptedException e) {
|
||||||
}
|
throw new RuntimeException(e);
|
||||||
SpeakerCommand.GetSpeakerStateCommand.Feedback status = edgeSpeakerService.getStatus(terminalId, deviceId);
|
}
|
||||||
boolean isRunning = status.getState().getIsRunning();
|
SpeakerCommand.GetSpeakerStateCommand.Feedback status = edgeSpeakerService.getStatus(terminalId, deviceId);
|
||||||
if (!isRunning) {
|
boolean isRunning = status.getState().getIsRunning();
|
||||||
break;
|
if (!isRunning) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
// 播放完成调用闭嘴
|
||||||
|
edgeBioHeadService.speakStop(edgeCommonVO);
|
||||||
}
|
}
|
||||||
// 播放完成调用闭嘴
|
|
||||||
edgeBioHeadService.speakStop(edgeCommonVO);
|
|
||||||
// todo 本机测试播放
|
// todo 本机测试播放
|
||||||
// playAudio(audioPath);
|
// playAudio(audioPath);
|
||||||
return TaskNodeExecuteResult.success();
|
return TaskNodeExecuteResult.success();
|
||||||
|
|||||||
@ -0,0 +1,12 @@
|
|||||||
|
package com.cmvr.test.model.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FlowiseActionRequestVO {
|
||||||
|
|
||||||
|
private String action;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user