84 lines
3.1 KiB
Java
84 lines
3.1 KiB
Java
|
|
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);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|