web : talkByVideo添加video-base64

dev_2.0.0
xueqingkun 1 year ago
parent b7a2236cef
commit 736cfc3291

@ -32,6 +32,9 @@ public class TalkResultResVO {
@ApiModelProperty("视频预览URL,本地视频的形式需要")
private String videoUrl;
@ApiModelProperty("视频base64位编码")
private String videoBase64;

@ -1,9 +1,12 @@
package com.supervision.service.impl;
import cn.hutool.core.codec.Base64Encoder;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.MD5;
import cn.hutool.setting.dialect.Props;
import com.supervision.exception.BusinessException;
import com.supervision.model.Process;
import com.supervision.model.*;
@ -20,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@ -42,9 +46,12 @@ public class AskServiceImpl implements AskService {
private final FileResourceService fileResourceService;
@Value("${defaultNoMatchId}")
@Value("${answer.defaultNoMatchId}")
private String defaultNoMatchId;
@Value("${answer.video.basePath}")
private String videoPath;
@Value("${video-url}")
private String videoUrl;
@ -206,6 +213,7 @@ public class AskServiceImpl implements AskService {
// 如果rasa没有识别出来,则返回默认值
if (StrUtil.isBlank(rasaResult)) {
talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId);
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId,null));
saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), null, "您好,我没有听懂您说什么");
}
@ -227,6 +235,7 @@ public class AskServiceImpl implements AskService {
if (ObjectUtil.isEmpty(library)) {
log.info("{}:未从问题库中找到,回答未识别语句", rasaResult);
talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId);
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId,null));
saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), null, "您好,我没有听懂您说什么");
} else {
AskPatientAnswer askPatientAnswer = askPatientAnswerService.lambdaQuery().eq(AskPatientAnswer::getMedicalId, process.getMedicalRecId())
@ -238,6 +247,7 @@ public class AskServiceImpl implements AskService {
if (StrUtil.isNotEmpty(library.getDefaultAnswer()) && StrUtil.isNotBlank(library.getDefaultAnswerResourceId())) {
String resText = library.getDefaultAnswer();
talkResultResVO.setVideoUrl(videoUrl + library.getDefaultAnswerResourceId());
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),null));
// 保存记录
saveQaRecord(talkReqVO.getProcessId(), "default", library.getId(), talkReqVO.getText(), library, resText);
log.info("{}:找到了默认答案:{}", rasaResult, talkReqVO.getText());
@ -245,6 +255,7 @@ public class AskServiceImpl implements AskService {
log.info("{}:没有从默认答案中找到找到默认内容,回复未识别语句", rasaResult);
talkResultResVO.setVideoUrl(videoUrl + (StrUtil.isEmpty(library.getDefaultAnswerResourceId()) ? defaultNoMatchId
:library.getDefaultAnswerResourceId()));
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),defaultNoMatchId));
saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), library, "您好,我没有听懂您说什么");
}
} else {
@ -255,11 +266,13 @@ public class AskServiceImpl implements AskService {
log.info("{}:病历配置的回答:{}:为空不为空不为空,但在获取的时候,答案为空,开始回复默认语句,默认语句内容:{}", rasaResult, askPatientAnswer.getId(), resText);
// 这里返回视频
talkResultResVO.setVideoUrl(videoUrl + library.getDefaultAnswerResourceId());
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(library.getDefaultAnswerResourceId(),defaultNoMatchId));
// 保存记录
saveQaRecord(talkReqVO.getProcessId(), "default", library.getId(), talkReqVO.getText(), library, resText);
} else {
log.info("{}:病历配置的回答:{}:为空不为空,但在获取的时候,答案为空,但是获取默认语句也为空,那么回复未识别语句", rasaResult, askPatientAnswer.getId());
talkResultResVO.setVideoUrl(videoUrl + defaultNoMatchId);
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(defaultNoMatchId,null));
saveQaRecord(talkReqVO.getProcessId(), "default", null, talkReqVO.getText(), library, "您好,我没有听懂您说什么");
}
@ -267,6 +280,7 @@ public class AskServiceImpl implements AskService {
String resText = askPatientAnswer.getAnswer();
log.info("{}:找到了病历配置的回答语句:{},回答内容:{}", rasaResult, askPatientAnswer.getId(), resText);
talkResultResVO.setVideoUrl(videoUrl + askPatientAnswer.getAnswerResourceId());
talkResultResVO.setVideoBase64(getAnswerVideoBase64OrDefault(askPatientAnswer.getAnswerResourceId(),defaultNoMatchId));
// 保存记录
saveQaRecord(talkReqVO.getProcessId(), "patient", askPatientAnswer.getId(), talkReqVO.getText(), library, resText);
}
@ -291,4 +305,24 @@ public class AskServiceImpl implements AskService {
throw new BusinessException("未找到回复视频");
}
}
/**
* base64
* @param answerId id
* @param defaultValue id
* @return base64
*/
private String getAnswerVideoBase64OrDefault(String answerId, String defaultValue) {
Props props = new Props(videoPath + File.separator + "index");
String fileName = "";
if (StrUtil.isNotEmpty(answerId) && StrUtil.isNotEmpty(props.getStr(answerId))){
fileName = props.getStr(answerId);
}else if (StrUtil.isNotEmpty(defaultValue)){
fileName = props.getStr(defaultValue);
}
if (StrUtil.isEmpty(fileName)){
return null;
}
return Base64Encoder.encode(FileUtil.readBytes(videoPath + File.separator + fileName));
}
}

@ -83,7 +83,11 @@ ws:
# nginx的wss地址(如果是wss的,那么带不带s都可以访问)
nginx-ip: 192.168.10.138
nginx-port: 443
# 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID
defaultNoMatchId: 1739173836351885313
answer:
# 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID
defaultNoMatchId: 1739173836351885313
video:
basePath: /data/vp/video #最后一级不需要加分割符
# 视频预览,NGINX的地址,https的地址
video-url: https://124.220.94.55:8025/virtual-patient/ask/downloadTalkVideo?fileResourceId=
video-url: https://124.220.94.55:8025/virtual-patient/ask/downloadTalkVideo?fileResourceId=

@ -84,7 +84,10 @@ ws:
# nginx的wss地址(如果是wss的,那么带不带s都可以访问)
nginx-ip: 192.168.10.138
nginx-port: 443
# 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID
defaultNoMatchId: 1739173836351885313
answer:
# 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID
defaultNoMatchId: 1739173836351885313
video:
basePath: F:\supervision\doc\数字人视频\final_video\final_video
# 视频预览
video-url: http://192.168.10.138:8899/virtual-patient/ask/downloadTalkVideo?fileResourceId=

@ -71,4 +71,11 @@ human:
base-url: https://digital-human.jd.com
room-id: /getRoomId
text-driven: /text_driven
talk-status: /talkStatus
talk-status: /talkStatus
answer:
# 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID
defaultNoMatchId: 1739173836351885313
video:
basePath: /data/vp/video #最后一级不需要加分割符
# 视频预览,NGINX的地址,https的地址
video-url: https://124.220.94.55:8025/virtual-patient/ask/downloadTalkVideo?fileResourceId=

@ -75,4 +75,11 @@ human:
ws:
# nginx的wss地址(如果是wss的,那么带不带s都可以访问)
nginx-ip: 192.168.10.138
nginx-port: 443
nginx-port: 443
answer:
# 对于没有匹配上的缺省回答ID,关联的是vp_file_resource的ID
defaultNoMatchId: 1739173836351885313
video:
basePath: /data/vp/video #最后一级不需要加分割符
# 视频预览,NGINX的地址,https的地址
video-url: https://124.220.94.55:8025/virtual-patient/ask/downloadTalkVideo?fileResourceId=

@ -1,6 +1,8 @@
package com.supervision;
import cn.hutool.core.codec.Base64Encoder;
import cn.hutool.core.io.FileUtil;
import cn.hutool.setting.dialect.Props;
import com.supervision.config.MinioProperties;
import com.supervision.model.FileResource;
import com.supervision.service.FileResourceService;
@ -15,7 +17,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.UUID;
@ -109,16 +111,20 @@ public class VideoUpdateTest {
fileResourceService.save(fileResource);
fileResource.setId(null);
}
}
public static void main(String[] args) throws FileNotFoundException {
long l = System.currentTimeMillis();
byte[] bytes = FileUtil.readBytes("F:\\supervision\\doc\\数字人视频\\final_video\\final_video\\0.mp4");
String encode = Base64Encoder.encode(bytes);
long l1 = System.currentTimeMillis() - l;
System.out.println(l1);
Props props = new Props("F:\\supervision\\doc\\数字人视频\\final_video\\final_video\\index");
Object o = props.get("a");
System.out.println(o);
}
}

Loading…
Cancel
Save