|
|
|
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;
|
|
|
|
import com.supervision.service.AskService;
|
|
|
|
import com.supervision.websocket.dto.SocketMessageDTO;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
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对话
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
|
|
|
}
|
|
|
|
}
|