Merge branch 'test-training2' of https://git.code.tencent.com/lian-cbtc/rtss-server into test-training2-zhouyin
This commit is contained in:
commit
abde6c0e17
@ -75,4 +75,19 @@ public class TaskExecutorConfiguration {
|
|||||||
taskExecutor.initialize();
|
taskExecutor.initialize();
|
||||||
return taskExecutor;
|
return taskExecutor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 语音识别业务处理线程
|
||||||
|
*/
|
||||||
|
@Bean("voiceDiscriminateExecutor")
|
||||||
|
public TaskExecutor voiceDiscriminateExecutor(Environment env) {
|
||||||
|
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
|
||||||
|
taskExecutor.setThreadNamePrefix("ns-voice-discriminate-executor-");
|
||||||
|
taskExecutor.setCorePoolSize(2);
|
||||||
|
taskExecutor.setMaxPoolSize(2);
|
||||||
|
taskExecutor.setQueueCapacity(100);
|
||||||
|
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
taskExecutor.initialize();
|
||||||
|
return taskExecutor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package club.joylink.rtss.services.voice.discriminate;
|
||||||
|
|
||||||
|
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateResult;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 纠正源信息问题
|
||||||
|
*/
|
||||||
|
@Service("correctSourceServiceImpl")
|
||||||
|
public class CorrectSourceServiceImpl implements VoiceTransactionalService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doExec(VoiceDiscriminateResult result, Simulation simulation) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,48 +0,0 @@
|
|||||||
package club.joylink.rtss.services.voice.discriminate;
|
|
||||||
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.OperateResult;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.ReplyResult;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.Stage;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateResult;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.ATS.operation.AtsOperationDispatcher;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.conversation.ConversationManagerService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行指令
|
|
||||||
*/
|
|
||||||
@Service("execCommandServiceImpl")
|
|
||||||
public class ExecCommandServiceImpl implements VoiceDiscriminateStepService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private AtsOperationDispatcher atsOperationDispatcher;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ConversationManagerService conversationManagerService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doExec(VoiceDiscriminateResult result, Simulation simulation) {
|
|
||||||
result.setStage(Stage.EXEC_COMMAND);
|
|
||||||
// 执行操作
|
|
||||||
try {
|
|
||||||
if (result.getOperateResult() != null) {
|
|
||||||
OperateResult operateResult = result.getOperateResult();
|
|
||||||
atsOperationDispatcher.execute(simulation, operateResult.getMember(), operateResult.getType().name(), operateResult.getParams());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
result.setSuccess(false);
|
|
||||||
result.setMsg(Stage.EXEC_COMMAND.getDesc() + "执行失败:" + e.getMessage());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 执行回复
|
|
||||||
if (result.getReplyContentResult() != null) {
|
|
||||||
ReplyResult replyResult = result.getReplyContentResult();
|
|
||||||
replyResult.getSimulationMemberList().forEach(member -> {
|
|
||||||
conversationManagerService.conversationChat(simulation, member, replyResult.getContent(), null);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
package club.joylink.rtss.services.voice.discriminate;
|
|
||||||
|
|
||||||
import club.joylink.rtss.services.voice.VoiceService;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.Stage;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateResult;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
|
||||||
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
|
|
||||||
import club.joylink.rtss.vo.client.voice.VoiceRecognitionVO;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 对原始语音文件进行解析
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service("loadVoiceFileServiceImpl")
|
|
||||||
public class LoadVoiceFileServiceImpl implements VoiceDiscriminateStepService {
|
|
||||||
/**
|
|
||||||
* 语音解析服务
|
|
||||||
*/
|
|
||||||
@Autowired
|
|
||||||
private VoiceService voiceService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doExec(VoiceDiscriminateResult result, Simulation simulation) {
|
|
||||||
result.setStage(Stage.LOAD);
|
|
||||||
try {
|
|
||||||
VoiceRecognitionVO vo = VoiceRecognitionVO.load(result.getFile());
|
|
||||||
VoiceRecognitionResult voiceRecognitionResult = voiceService.voiceRecognition(vo);
|
|
||||||
String originVoiceContent = voiceRecognitionResult.getResult();
|
|
||||||
String originVoicePinYin = translateToPinYin(originVoiceContent);
|
|
||||||
result.setOriginContent(originVoiceContent);
|
|
||||||
result.setOriginPinYin(originVoicePinYin);
|
|
||||||
} catch (Exception e) {
|
|
||||||
result.setSuccess(false);
|
|
||||||
result.setMsg(e.getCause().getMessage());
|
|
||||||
log.error(result.getStage().getDesc(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 翻译标准
|
|
||||||
* @param result
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String translateToPinYin(String result) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
package club.joylink.rtss.services.voice.discriminate;
|
|
||||||
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.Stage;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateResult;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateRule;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.CollectionUtils;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 匹配原始指令
|
|
||||||
*/
|
|
||||||
@Service("matchCommandServiceImpl")
|
|
||||||
public class MatchCommandServiceImpl implements VoiceDiscriminateStepService {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关键字匹配方法
|
|
||||||
*/
|
|
||||||
private final Map<String, BiFunction<String, VoiceDiscriminateRule, List<String>>> keyWordsMatchMethodMap = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 关键字匹配接口
|
|
||||||
*/
|
|
||||||
private final BiFunction<String, VoiceDiscriminateRule, List<String>> defaultKeyWordsMatch = (originContent, ruleInfo) -> {
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doExec(VoiceDiscriminateResult result, Simulation simulation) {
|
|
||||||
result.setStage(Stage.MATCH_COMMAND);
|
|
||||||
// 加载本地图的规则信息列表
|
|
||||||
List<VoiceDiscriminateRule> ruleList = List.of(new VoiceDiscriminateRule());
|
|
||||||
// 匹配指令
|
|
||||||
BiFunction<String, VoiceDiscriminateRule, List<String>> matchMethod = null;
|
|
||||||
List<String> matchGroupList = null;
|
|
||||||
for (VoiceDiscriminateRule rule : ruleList) {
|
|
||||||
matchMethod = keyWordsMatchMethodMap.getOrDefault(rule.getKwMatchMethod(), defaultKeyWordsMatch);
|
|
||||||
matchGroupList = matchMethod.apply(result.getMatchOriginContent(), rule);
|
|
||||||
if (!CollectionUtils.isEmpty(matchGroupList)) {
|
|
||||||
result.setRule(rule);
|
|
||||||
result.setMatchGroupList(matchGroupList);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 出错,未匹配到指令
|
|
||||||
result.setSuccess(false);
|
|
||||||
result.setMsg(result.getStage().getDesc() + ",未匹配到对应指令");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,11 @@
|
|||||||
package club.joylink.rtss.services.voice.discriminate;
|
package club.joylink.rtss.services.voice.discriminate;
|
||||||
|
|
||||||
|
import club.joylink.rtss.simulation.cbtc.ATS.operation.AtsOperationDispatcher;
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.*;
|
import club.joylink.rtss.simulation.cbtc.discriminate.*;
|
||||||
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
@ -12,29 +15,35 @@ import java.util.List;
|
|||||||
* 操作解析
|
* 操作解析
|
||||||
*/
|
*/
|
||||||
@Service("operateParseServiceImpl")
|
@Service("operateParseServiceImpl")
|
||||||
public class OperateParseServiceImpl implements VoiceDiscriminateStepService {
|
public class OperateParseServiceImpl implements VoiceTransactionalService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AtsOperationDispatcher atsOperationDispatcher;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Async("voiceDiscriminateExecutor")
|
||||||
public void doExec(VoiceDiscriminateResult result, Simulation simulation) {
|
public void doExec(VoiceDiscriminateResult result, Simulation simulation) {
|
||||||
result.setStage(Stage.OPERATE_PARSE);
|
if (!result.isSuccess()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
OperateRule operateRule = result.getRule().getExecOperateRule();
|
OperateRule operateRule = result.getRule().getExecOperateRule();
|
||||||
if (operateRule == null) {
|
if (operateRule == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// 参数解析
|
||||||
List<ParamExtractResult> paramExtractResults = result.getParamExtractResultList();
|
List<ParamExtractResult> paramExtractResults = result.getParamExtractResultList();
|
||||||
OperateResult operateResult = new OperateResult(operateRule.getType());
|
OperateResult operateResult = new OperateResult(operateRule.getType());
|
||||||
result.setOperateResult(operateResult);
|
|
||||||
for (CommandParamRule paramRule : operateRule.getParamRules()) {
|
for (CommandParamRule paramRule : operateRule.getParamRules()) {
|
||||||
if (paramRule.getIndex() == null) {
|
if (paramRule.getIndex() == null) {
|
||||||
operateResult.putParam(paramRule.getName(), paramRule.getParseRule().extractParam(simulation, null));
|
operateResult.putParam(paramRule.getName(), paramRule.getParseRule().extractParam(simulation, null));
|
||||||
} else if (paramRule.getIndex() < paramExtractResults.size()) {
|
} else if (paramRule.getIndex() < paramExtractResults.size()) {
|
||||||
operateResult.putParam(paramRule.getName(), paramRule.getParseRule().extractParam(simulation, paramExtractResults.get(paramRule.getIndex())));
|
operateResult.putParam(paramRule.getName(), paramRule.getParseRule().extractParam(simulation, paramExtractResults.get(paramRule.getIndex())));
|
||||||
} else {
|
} else {
|
||||||
result.setSuccess(false);
|
|
||||||
result.setMsg(Stage.OPERATE_PARSE.getDesc() + "解析参数出错");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 成员解析
|
||||||
MemberRule memberRule = operateRule.getMemberRule();
|
MemberRule memberRule = operateRule.getMemberRule();
|
||||||
if (memberRule != null) {
|
if (memberRule != null) {
|
||||||
List<String> groupList = result.getMatchGroupList();
|
List<String> groupList = result.getMatchGroupList();
|
||||||
@ -44,16 +53,19 @@ public class OperateParseServiceImpl implements VoiceDiscriminateStepService {
|
|||||||
} else if (memberRule.getIndex() < paramExtractResults.size()) {
|
} else if (memberRule.getIndex() < paramExtractResults.size()) {
|
||||||
simulationMemberList = memberRule.getParseRule().matchMember(simulation, groupList.get(memberRule.getIndex()));
|
simulationMemberList = memberRule.getParseRule().matchMember(simulation, groupList.get(memberRule.getIndex()));
|
||||||
} else {
|
} else {
|
||||||
result.setSuccess(false);
|
|
||||||
result.setMsg(Stage.OPERATE_PARSE.getDesc() + "解析成员出错");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isEmpty(simulationMemberList)) {
|
if (CollectionUtils.isEmpty(simulationMemberList)) {
|
||||||
result.setSuccess(false);
|
|
||||||
result.setMsg(Stage.OPERATE_PARSE.getDesc() + "未找到匹配成员");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
operateResult.setMember(simulationMemberList.get(0));
|
operateResult.setMember(simulationMemberList.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 执行操作
|
||||||
|
try {
|
||||||
|
atsOperationDispatcher.execute(simulation, operateResult.getMember(), operateResult.getType().name(), operateResult.getParams());
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
package club.joylink.rtss.services.voice.discriminate;
|
|
||||||
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.ParamExtractResult;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.ParamExtractRule;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.Stage;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateResult;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析参数
|
|
||||||
*/
|
|
||||||
@Service("paramExtractServiceImpl")
|
|
||||||
public class ParamExtractServiceImpl implements VoiceDiscriminateStepService {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doExec(VoiceDiscriminateResult result, Simulation simulation) {
|
|
||||||
result.setStage(Stage.PARAM_EXTRACT);
|
|
||||||
List<String> groupList = result.getMatchGroupList();
|
|
||||||
List<ParamExtractRule> paramsRules = result.getRule().getParamsRules();
|
|
||||||
List<ParamExtractResult> paramExtractResults = new ArrayList<>(paramsRules.size());
|
|
||||||
ParamExtractResult extractResult = null;
|
|
||||||
for (ParamExtractRule rule : paramsRules) {
|
|
||||||
if (groupList.size() < rule.getIndex()) {
|
|
||||||
result.setSuccess(false);
|
|
||||||
result.setMsg("提取参数出错");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
extractResult = rule.getParseRule().matchParam(simulation, groupList.get(rule.getIndex()));
|
|
||||||
paramExtractResults.add(extractResult);
|
|
||||||
}
|
|
||||||
result.setParamExtractResultList(paramExtractResults);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,11 @@
|
|||||||
package club.joylink.rtss.services.voice.discriminate;
|
package club.joylink.rtss.services.voice.discriminate;
|
||||||
|
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.conversation.ConversationManagerService;
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.*;
|
import club.joylink.rtss.simulation.cbtc.discriminate.*;
|
||||||
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
@ -11,19 +14,24 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* 合成回复内容
|
* 合成回复内容
|
||||||
*/
|
*/
|
||||||
@Service("replyServiceImpl")
|
@Service("replyParseServiceImpl")
|
||||||
public class ReplyServiceImpl implements VoiceDiscriminateStepService {
|
public class ReplyParseServiceImpl implements VoiceTransactionalService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ConversationManagerService conversationManagerService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Async("voiceDiscriminateExecutor")
|
||||||
public void doExec(VoiceDiscriminateResult result, Simulation simulation) {
|
public void doExec(VoiceDiscriminateResult result, Simulation simulation) {
|
||||||
result.setStage(Stage.REPLY_CONTENT);
|
if (!result.isSuccess()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
ReplyRule replyRule = result.getRule().getReplyRule();
|
ReplyRule replyRule = result.getRule().getReplyRule();
|
||||||
if (replyRule == null) {
|
if (replyRule == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<ParamExtractResult> paramExtractResults = result.getParamExtractResultList();
|
List<ParamExtractResult> paramExtractResults = result.getParamExtractResultList();
|
||||||
ReplyResult replyResult = new ReplyResult(replyRule.getParamRules().size());
|
ReplyResult replyResult = new ReplyResult(replyRule.getParamRules().size());
|
||||||
result.setReplyContentResult(replyResult);
|
|
||||||
try {
|
try {
|
||||||
for (CommandParamRule paramRule : replyRule.getParamRules()) {
|
for (CommandParamRule paramRule : replyRule.getParamRules()) {
|
||||||
if (paramRule.getIndex() == null) {
|
if (paramRule.getIndex() == null) {
|
||||||
@ -31,14 +39,11 @@ public class ReplyServiceImpl implements VoiceDiscriminateStepService {
|
|||||||
} else if (paramRule.getIndex() < paramExtractResults.size()) {
|
} else if (paramRule.getIndex() < paramExtractResults.size()) {
|
||||||
replyResult.addParams(paramRule.getParseRule().extractParam(simulation, paramExtractResults.get(paramRule.getIndex())));
|
replyResult.addParams(paramRule.getParseRule().extractParam(simulation, paramExtractResults.get(paramRule.getIndex())));
|
||||||
} else {
|
} else {
|
||||||
result.setSuccess(false);
|
|
||||||
result.setMsg(Stage.REPLY_CONTENT.getDesc() + "解析参数出错");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
result.setSuccess(false);
|
return;
|
||||||
result.setMsg(Stage.REPLY_CONTENT.getDesc() + "解析参数出错");
|
|
||||||
}
|
}
|
||||||
// 格式化回复语句
|
// 格式化回复语句
|
||||||
Object[] objArr = new Object[replyResult.getParamList().size()];
|
Object[] objArr = new Object[replyResult.getParamList().size()];
|
||||||
@ -54,16 +59,17 @@ public class ReplyServiceImpl implements VoiceDiscriminateStepService {
|
|||||||
} else if (memberRule.getIndex() < paramExtractResults.size()) {
|
} else if (memberRule.getIndex() < paramExtractResults.size()) {
|
||||||
simulationMemberList = memberRule.getParseRule().matchMember(simulation, groupList.get(memberRule.getIndex()));
|
simulationMemberList = memberRule.getParseRule().matchMember(simulation, groupList.get(memberRule.getIndex()));
|
||||||
} else {
|
} else {
|
||||||
result.setSuccess(false);
|
|
||||||
result.setMsg(Stage.REPLY_CONTENT.getDesc() + "解析成员出错");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isEmpty(simulationMemberList)) {
|
if (CollectionUtils.isEmpty(simulationMemberList)) {
|
||||||
result.setSuccess(false);
|
|
||||||
result.setMsg(Stage.REPLY_CONTENT.getDesc() + "未找到匹配成员");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
replyResult.setSimulationMemberList(simulationMemberList);
|
replyResult.setSimulationMemberList(simulationMemberList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 执行回复
|
||||||
|
replyResult.getSimulationMemberList().forEach(member -> {
|
||||||
|
conversationManagerService.conversationChat(simulation, member, replyResult.getContent(), null);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package club.joylink.rtss.services.voice.discriminate;
|
package club.joylink.rtss.services.voice.discriminate;
|
||||||
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.Stage;
|
|
||||||
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateResult;
|
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateResult;
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -9,9 +8,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 语音识别服务类(多例)
|
* 语音识别服务类(多例)
|
||||||
@ -21,62 +17,27 @@ import java.util.*;
|
|||||||
public class VoiceDiscriminateService {
|
public class VoiceDiscriminateService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier(value = "loadVoiceFileServiceImpl")
|
private VoiceParseService voiceParseService;
|
||||||
private VoiceDiscriminateStepService LoadVoiceFileService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
@Qualifier(value = "matchCommandServiceImpl")
|
|
||||||
private VoiceDiscriminateStepService MatchCommandService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
@Qualifier(value = "paramExtractServiceImpl")
|
|
||||||
private VoiceDiscriminateStepService paramExtractService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier(value = "operateParseServiceImpl")
|
@Qualifier(value = "operateParseServiceImpl")
|
||||||
private VoiceDiscriminateStepService operateParseService;
|
private VoiceTransactionalService operateParseService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier(value = "replyServiceImpl")
|
@Qualifier(value = "replyParseServiceImpl")
|
||||||
private VoiceDiscriminateStepService replyService;
|
private VoiceTransactionalService replyParseService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier(value = "execCommandServiceImpl")
|
@Qualifier(value = "correctSourceServiceImpl")
|
||||||
private VoiceDiscriminateStepService execCommandService;
|
private VoiceTransactionalService correctSourceService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 执行步骤
|
|
||||||
*/
|
|
||||||
private List<VoiceDiscriminateStepService> stepList = new LinkedList<>();
|
|
||||||
|
|
||||||
@PostConstruct
|
|
||||||
public void initStepList() {
|
|
||||||
stepList.add(LoadVoiceFileService);
|
|
||||||
stepList.add(MatchCommandService);
|
|
||||||
stepList.add(paramExtractService);
|
|
||||||
stepList.add(operateParseService);
|
|
||||||
stepList.add(replyService);
|
|
||||||
stepList.add(execCommandService);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接受语音文件、资源等必要条件,解析开始
|
* 接受语音文件、资源等必要条件,解析开始
|
||||||
*/
|
*/
|
||||||
public VoiceDiscriminateResult doAnalysis(Simulation simulation, MultipartFile file) {
|
public void doAnalysis(Simulation simulation, MultipartFile file) {
|
||||||
VoiceDiscriminateResult result = new VoiceDiscriminateResult();
|
VoiceDiscriminateResult result = voiceParseService.doParse(simulation, file);
|
||||||
result.setSuccess(true);
|
operateParseService.doExec(result, simulation); // 指令执行
|
||||||
result.setFile(file);
|
replyParseService.doExec(result, simulation); // 回复执行
|
||||||
for (VoiceDiscriminateStepService step : stepList) {
|
correctSourceService.doExec(result, simulation);// 原信息纠错
|
||||||
if (result.isSuccess()) {
|
|
||||||
step.doExec(result, simulation);
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (result.isSuccess()) {
|
|
||||||
result.setStage(Stage.SUCCESS);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package club.joylink.rtss.services.voice.discriminate;
|
||||||
|
|
||||||
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateResult;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 语音解析步骤服务
|
||||||
|
*/
|
||||||
|
public interface VoiceParseService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析语音任务
|
||||||
|
*
|
||||||
|
* @param simulation 仿真
|
||||||
|
* @param file 文件
|
||||||
|
* @return 解析结果
|
||||||
|
*/
|
||||||
|
VoiceDiscriminateResult doParse(Simulation simulation, MultipartFile file);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对语音文字进行任务
|
||||||
|
*
|
||||||
|
* @param simulation 仿真
|
||||||
|
* @param content 语音文字
|
||||||
|
* @return 解析结果
|
||||||
|
*/
|
||||||
|
VoiceDiscriminateResult doParse(Simulation simulation, String content);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,128 @@
|
|||||||
|
package club.joylink.rtss.services.voice.discriminate;
|
||||||
|
|
||||||
|
import club.joylink.rtss.services.voice.VoiceService;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.discriminate.ParamExtractResult;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.discriminate.ParamExtractRule;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateResult;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateRule;
|
||||||
|
import club.joylink.rtss.vo.client.voice.VoiceRecognitionResult;
|
||||||
|
import club.joylink.rtss.vo.client.voice.VoiceRecognitionVO;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 语音文件解析服务
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class VoiceParseServiceImpl implements VoiceParseService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 语音解析服务
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private VoiceService voiceService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关键字匹配方法
|
||||||
|
*/
|
||||||
|
private final Map<String, BiFunction<String, VoiceDiscriminateRule, List<String>>> keyWordsMatchMethodMap = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关键字匹配接口
|
||||||
|
*/
|
||||||
|
private final BiFunction<String, VoiceDiscriminateRule, List<String>> defaultKeyWordsMatch = (originContent, ruleInfo) -> null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VoiceDiscriminateResult doParse(Simulation simulation, MultipartFile file) {
|
||||||
|
VoiceRecognitionVO vo = VoiceRecognitionVO.load(file);
|
||||||
|
VoiceRecognitionResult voiceRecognitionResult = voiceService.voiceRecognition(vo);
|
||||||
|
return doParse(simulation, voiceRecognitionResult.getResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VoiceDiscriminateResult doParse(Simulation simulation, String content) {
|
||||||
|
VoiceDiscriminateResult result = new VoiceDiscriminateResult();
|
||||||
|
if (StringUtils.isEmpty(content)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result.setSuccess(true);
|
||||||
|
result.setOriginContent(content);
|
||||||
|
result.setOriginPinYin(translateToPinYin(content));
|
||||||
|
// 匹配指令
|
||||||
|
matchCommand(simulation, result);
|
||||||
|
// 参数抽取
|
||||||
|
if (result.isSuccess()) {
|
||||||
|
paramExtract(simulation, result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 翻译标准拼音
|
||||||
|
*
|
||||||
|
* @param content 语音文字
|
||||||
|
* @return 拼音信息
|
||||||
|
*/
|
||||||
|
private String translateToPinYin(String content) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 匹配指令
|
||||||
|
*
|
||||||
|
* @param simulation 仿真
|
||||||
|
* @param result 结果信息
|
||||||
|
*/
|
||||||
|
private void matchCommand(Simulation simulation, VoiceDiscriminateResult result) {
|
||||||
|
// 加载本地图的规则信息列表:从数据库中获取
|
||||||
|
List<VoiceDiscriminateRule> ruleList = List.of(new VoiceDiscriminateRule());
|
||||||
|
// 匹配指令
|
||||||
|
BiFunction<String, VoiceDiscriminateRule, List<String>> matchMethod = null;
|
||||||
|
List<String> matchGroupList = null;
|
||||||
|
for (VoiceDiscriminateRule rule : ruleList) {
|
||||||
|
matchMethod = keyWordsMatchMethodMap.getOrDefault(rule.getKwMatchMethod(), defaultKeyWordsMatch);
|
||||||
|
matchGroupList = matchMethod.apply(result.getMatchOriginContent(), rule);
|
||||||
|
if (!CollectionUtils.isEmpty(matchGroupList)) {
|
||||||
|
result.setRule(rule);
|
||||||
|
result.setMatchGroupList(matchGroupList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 出错,未匹配到指令
|
||||||
|
result.setSuccess(false);
|
||||||
|
result.setMsg("未匹配到对应指令");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数抽取
|
||||||
|
*
|
||||||
|
* @param simulation 仿真
|
||||||
|
* @param result 结果信息
|
||||||
|
*/
|
||||||
|
private void paramExtract(Simulation simulation, VoiceDiscriminateResult result) {
|
||||||
|
List<String> groupList = result.getMatchGroupList();
|
||||||
|
List<ParamExtractRule> paramsRules = result.getRule().getParamsRules();
|
||||||
|
List<ParamExtractResult> paramExtractResults = new ArrayList<>(paramsRules.size());
|
||||||
|
ParamExtractResult extractResult = null;
|
||||||
|
for (ParamExtractRule rule : paramsRules) {
|
||||||
|
if (groupList.size() < rule.getIndex()) {
|
||||||
|
result.setSuccess(false);
|
||||||
|
result.setMsg("提取参数出错");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
extractResult = rule.getParseRule().matchParam(simulation, groupList.get(rule.getIndex()));
|
||||||
|
paramExtractResults.add(extractResult);
|
||||||
|
}
|
||||||
|
result.setParamExtractResultList(paramExtractResults);
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,10 @@ package club.joylink.rtss.services.voice.discriminate;
|
|||||||
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateResult;
|
import club.joylink.rtss.simulation.cbtc.discriminate.VoiceDiscriminateResult;
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
|
|
||||||
public interface VoiceDiscriminateStepService {
|
/**
|
||||||
|
* 语音业务执行步骤,无返回值不影响其他业务步骤执行
|
||||||
|
*/
|
||||||
|
public interface VoiceTransactionalService {
|
||||||
|
|
||||||
void doExec(VoiceDiscriminateResult result, Simulation simulation);
|
void doExec(VoiceDiscriminateResult result, Simulation simulation);
|
||||||
}
|
}
|
@ -1,23 +0,0 @@
|
|||||||
package club.joylink.rtss.simulation.cbtc.discriminate;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 阶段
|
|
||||||
*/
|
|
||||||
@Getter
|
|
||||||
public enum Stage {
|
|
||||||
LOAD("加载文件"),
|
|
||||||
MATCH_COMMAND("匹配语音指令"),
|
|
||||||
PARAM_EXTRACT("参数提取"),
|
|
||||||
OPERATE_PARSE("操作解析"),
|
|
||||||
REPLY_CONTENT("合成回复内容"),
|
|
||||||
EXEC_COMMAND("执行指令"),
|
|
||||||
SUCCESS("执行成功");
|
|
||||||
|
|
||||||
private String desc;
|
|
||||||
|
|
||||||
Stage(String desc) {
|
|
||||||
this.desc = desc;
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,24 +11,13 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class VoiceDiscriminateResult {
|
public class VoiceDiscriminateResult {
|
||||||
/**
|
|
||||||
* 当前所属阶段
|
|
||||||
*/
|
|
||||||
private Stage stage;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态是否正常
|
* 状态是否正常
|
||||||
*/
|
*/
|
||||||
private boolean success;
|
private boolean success;
|
||||||
|
|
||||||
/**
|
|
||||||
* 响应提示语
|
|
||||||
*/
|
|
||||||
private String msg;
|
private String msg;
|
||||||
|
|
||||||
private MultipartFile file;
|
|
||||||
|
|
||||||
/************************* 最初语音识别的结果信息 start *************************/
|
|
||||||
/**
|
/**
|
||||||
* 语音原始内容
|
* 语音原始内容
|
||||||
*/
|
*/
|
||||||
@ -38,9 +27,7 @@ public class VoiceDiscriminateResult {
|
|||||||
* 原始语音拼音
|
* 原始语音拼音
|
||||||
*/
|
*/
|
||||||
private String originPinYin;
|
private String originPinYin;
|
||||||
/************************* 最初语音识别的结果信息 end **************************/
|
|
||||||
|
|
||||||
/************************* 根据语音识别的指令信息 start ************************/
|
|
||||||
/**
|
/**
|
||||||
* 匹配到的指令规则
|
* 匹配到的指令规则
|
||||||
*/
|
*/
|
||||||
@ -50,9 +37,7 @@ public class VoiceDiscriminateResult {
|
|||||||
* 匹配指令结果
|
* 匹配指令结果
|
||||||
*/
|
*/
|
||||||
private List<String> matchGroupList;
|
private List<String> matchGroupList;
|
||||||
/************************* 根据语音识别的指令信息 end *************************/
|
|
||||||
|
|
||||||
/************************* 参数提取结果 start *******************************/
|
|
||||||
/**
|
/**
|
||||||
* 参数提取集合
|
* 参数提取集合
|
||||||
*/
|
*/
|
||||||
@ -63,22 +48,6 @@ public class VoiceDiscriminateResult {
|
|||||||
*/
|
*/
|
||||||
private List<SimulationMember> simulationMemberList;
|
private List<SimulationMember> simulationMemberList;
|
||||||
|
|
||||||
/************************* 参数提取结果 end *********************************/
|
|
||||||
|
|
||||||
/************************* 合成指令 start **********************************/
|
|
||||||
/**
|
|
||||||
* 合成的指令结果
|
|
||||||
*/
|
|
||||||
private OperateResult operateResult;
|
|
||||||
/************************* 合成指令 end *************************************/
|
|
||||||
|
|
||||||
/************************* 合成回复信息 start *******************************/
|
|
||||||
/**
|
|
||||||
* 回复提取内容
|
|
||||||
*/
|
|
||||||
private ReplyResult replyContentResult;
|
|
||||||
/************************* 合成回复信息 end ********************************/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取匹配指令的语音内容
|
* 获取匹配指令的语音内容
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user