【会话文件上传后增加返回结果】

This commit is contained in:
weizhihong 2022-08-12 13:53:33 +08:00
parent 2ba34056dc
commit 9cbfb97d98
2 changed files with 16 additions and 14 deletions

View File

@ -391,31 +391,33 @@ public class ConversationManagerService {
/**
* 文件BASE64编码
*/
public void conversationChat(Simulation simulation, SimulationMember member, String fileBase64Str) {
public ConversationMessageVO conversationChat(Simulation simulation, SimulationMember member, String fileBase64Str) {
VoiceRecognitionResult recognitionResult = iVoiceService.voiceRecognition(fileBase64Str);
String upperCaseResult = recognitionResult.getResult().toUpperCase();
String handledContent = simulationVoiceHandler.handle(upperCaseResult);
ConversationMessage conversationMessage = new ConversationMessage(simulation.getIdGenerator().nextConversationMessageId(),
member, simulation.getCorrectSystemTime(), handledContent, recognitionResult.getFilePath());
sendChatMessage(simulation.getId(), simulation.getSimulationUserIds(), conversationMessage);
return sendChatMessage(simulation.getId(), simulation.getSimulationUserIds(), conversationMessage);
}
/**
* 会话操作
*/
public void conversationChat(Simulation simulation, SimulationMember member, String content, String audioPath) {
public ConversationMessageVO conversationChat(Simulation simulation, SimulationMember member, String content, String audioPath) {
String path = audioPath;
if (StringUtils.isEmpty(audioPath)) {
path = iVoiceService.synthesis(content, "0");
}
ConversationMessage conversationMessage = new ConversationMessage(simulation.getIdGenerator().nextConversationMessageId(),
member, simulation.getCorrectSystemTime(), content, path);
sendChatMessage(simulation.getId(), simulation.getSimulationUserIds(), conversationMessage);
return sendChatMessage(simulation.getId(), simulation.getSimulationUserIds(), conversationMessage);
}
private void sendChatMessage(String simulationId, Set<String> userIds, ConversationMessage conversationMessage) {
private ConversationMessageVO sendChatMessage(String simulationId, Set<String> userIds, ConversationMessage conversationMessage) {
ConversationMessageVO conversationMessageVO = new ConversationMessageVO(conversationMessage);
SocketMessageVO<ConversationMessageVO> chatMessage =
SocketMessageFactory.build(WebSocketMessageType.Simulation_Conversation_Operation, simulationId, new ConversationMessageVO(conversationMessage));
SocketMessageFactory.build(WebSocketMessageType.Simulation_Conversation_Operation, simulationId, conversationMessageVO);
stompMessageService.sendToUser(userIds, chatMessage);
return conversationMessageVO;
}
}

View File

@ -4,6 +4,7 @@ import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation;
import club.joylink.rtss.simulation.cbtc.ATS.operation.annotation.OperateHandler;
import club.joylink.rtss.simulation.cbtc.ATS.operation.annotation.OperateHandlerMapping;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationMessageVO;
import club.joylink.rtss.simulation.cbtc.data.vo.ConversationVO;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import lombok.extern.slf4j.Slf4j;
@ -68,24 +69,23 @@ public class ConversationOperateHandler {
* 发送会话消息语音输入
*/
@OperateHandlerMapping(type = Operation.Type.Conversation_Chat_Audio)
public void audioChat(Simulation simulation, SimulationMember member, String audioPath, String content) {
conversationManagerService.conversationChat(simulation, member, content, audioPath);
public ConversationMessageVO audioChat(Simulation simulation, SimulationMember member, String audioPath, String content) {
return conversationManagerService.conversationChat(simulation, member, content, audioPath);
}
/**
* 发送会话消息文字输入
*/
@OperateHandlerMapping(type = Operation.Type.Conversation_Chat_Text)
public void textChat(Simulation simulation, SimulationMember member, String content) {
conversationManagerService.conversationChat(simulation, member, content, null);
public ConversationMessageVO textChat(Simulation simulation, SimulationMember member, String content) {
return conversationManagerService.conversationChat(simulation, member, content, null);
}
/**
* 发送会话消息语音输入Base64格式
*/
@OperateHandlerMapping(type = Operation.Type.Conversation_Chat_Audio_Base64)
public void audioBase64(Simulation simulation, SimulationMember member, String fileBase64Str) {
conversationManagerService.conversationChat(simulation, member, fileBase64Str);
public ConversationMessageVO audioBase64(Simulation simulation, SimulationMember member, String fileBase64Str) {
return conversationManagerService.conversationChat(simulation, member, fileBase64Str);
}
}