You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
virtual-patient/virtual-patient-web/src/main/java/com/supervision/service/impl/AskServiceImpl.java

69 lines
2.1 KiB
Java

2 years ago
package com.supervision.service.impl;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.supervision.exception.BusinessException;
import com.supervision.paddlespeech.AsrUtil;
import com.supervision.paddlespeech.TtsUtil;
import com.supervision.rasa.RasaUtil;
import com.supervision.rasa.dto.RasaReqDTO;
import com.supervision.rasa.dto.RasaResDTO;
import com.supervision.pojo.vo.ReplyVoiceResVO;
2 years ago
import com.supervision.service.AskService;
import com.supervision.websocket.dto.SocketMessageDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
2 years ago
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
2 years ago
@Service
@RequiredArgsConstructor
2 years ago
public class AskServiceImpl implements AskService {
@Override
public void handlerMessageBySocket(SocketMessageDTO socketMessageDTO) {
// 首先获取消息的类型
String text;
if (0 == socketMessageDTO.getMessageType()) {
// 如果是语音消息
// 调用百度接口,语音转文字
text = AsrUtil.asrTransformByBytes(socketMessageDTO.getVoiceMessage());
} else {
text = socketMessageDTO.getTextMessage();
}
if (StrUtil.isBlank(text)) {
throw new BusinessException("语音消息不能为空");
}
// 进行rasa对话
}
2 years ago
@Override
public String receiveVoiceFile(MultipartFile file) throws IOException {
// 获取音频对应的文字
String askQuestion = AsrUtil.asrTransformByBytes(file.getBytes());
// 调用rasa获取文字内容
throw new BusinessException("暂未实现");
}
@Override
public ReplyVoiceResVO replyVoice() {
String text = "测试:这是文字转语音的测试,测试是否OK";
return TtsUtil.ttsTransform(text);
}
@Override
public List<String> conversation(String question, String sessionId) {
return RasaUtil.talkRasa(question,sessionId);
}
2 years ago
}