|
|
@@ -0,0 +1,191 @@
|
|
|
+package com.fdkankan.scene.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.fdkankan.common.constant.CommonSuccessStatus;
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
+import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
+import com.fdkankan.scene.constant.FileYunPath;
|
|
|
+import com.fdkankan.scene.dto.AsrCallbackDTO;
|
|
|
+import com.fdkankan.scene.dto.ScrbSaveDTO;
|
|
|
+import com.fdkankan.scene.dto.TextVoiceTransferDTO;
|
|
|
+import com.fdkankan.scene.entity.SceneEditInfoScrb;
|
|
|
+import com.fdkankan.scene.entity.TextVoiceTransfer;
|
|
|
+import com.fdkankan.scene.service.*;
|
|
|
+import com.fdkankan.scene.util.AsrUtil;
|
|
|
+import com.fdkankan.scene.util.TtsUtil;
|
|
|
+import com.fdkankan.web.response.ResultData;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ScrbServiceImpl implements IScrbService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ITextVoiceTransferService textVoiceTransferService;
|
|
|
+ @Resource
|
|
|
+ private TtsUtil ttsUtil;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AsrUtil asrUtil;
|
|
|
+ @Resource
|
|
|
+ private FYunFileServiceInterface fYunFileService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditInfoScrbService sceneEditInfoScrbService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditInfoService sceneEditInfoService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void asrCallback(AsrCallbackDTO param) {
|
|
|
+
|
|
|
+ String taskId = param.getRequestId();
|
|
|
+ TextVoiceTransfer task = textVoiceTransferService.getByTaskId(taskId);
|
|
|
+ Integer status = task.getStatus();
|
|
|
+ if(param.getCode() != 0){
|
|
|
+ status = CommonSuccessStatus.FAIL.code();
|
|
|
+ }else{
|
|
|
+ status = CommonSuccessStatus.SUCCESS.code();
|
|
|
+ String text = param.getText();
|
|
|
+ task.setDocument(text);
|
|
|
+ }
|
|
|
+ task.setResCode(param.getCode());
|
|
|
+ task.setStatus(status);
|
|
|
+ task.setUpdateTime(new Date());
|
|
|
+ textVoiceTransferService.updateById(task);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TextVoiceTransfer> listTextVoiceTransfer(String num) {
|
|
|
+ return textVoiceTransferService.list(new LambdaQueryWrapper<TextVoiceTransfer>().eq(TextVoiceTransfer::getNum, num));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String ttsCompose(TextVoiceTransferDTO dto) throws Exception {
|
|
|
+ String localVoicePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, dto.getNum()) + UUID.randomUUID() + ".mp3";
|
|
|
+ ttsUtil.textToVoice(dto.getDocument(), localVoicePath, dto.getVoiceType(), dto.getSpeed(), dto.getVolume());
|
|
|
+ String obsPath = String.format(FileYunPath.TEMP_PATH, dto.getNum()) + FileUtil.getName(localVoicePath);
|
|
|
+ fYunFileService.uploadFile(localVoicePath, obsPath);
|
|
|
+ FileUtil.del(localVoicePath);
|
|
|
+ return obsPath;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData ttsSave(TextVoiceTransferDTO dto) throws Exception {
|
|
|
+
|
|
|
+ TextVoiceTransfer textVoiceTransfer = null;
|
|
|
+ if(Objects.nonNull(dto.getId())){
|
|
|
+ textVoiceTransfer = textVoiceTransferService.getById(dto.getId());
|
|
|
+ textVoiceTransfer.setUpdateTime(new Date());
|
|
|
+ }else{
|
|
|
+ textVoiceTransfer = new TextVoiceTransfer();
|
|
|
+ textVoiceTransfer.setNum(dto.getNum());
|
|
|
+ }
|
|
|
+
|
|
|
+ textVoiceTransfer.setDocument(dto.getDocument());
|
|
|
+ textVoiceTransfer.setType("tts");
|
|
|
+ if(StrUtil.isEmpty(dto.getVoicePath())){
|
|
|
+ textVoiceTransfer.setStatus(CommonSuccessStatus.WAITING.code());
|
|
|
+ }else{
|
|
|
+ textVoiceTransfer.setStatus(CommonSuccessStatus.SUCCESS.code());
|
|
|
+ textVoiceTransfer.setVoicePath(dto.getVoicePath());
|
|
|
+ }
|
|
|
+
|
|
|
+ textVoiceTransferService.saveOrUpdate(textVoiceTransfer);
|
|
|
+
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData asrSave(String num, Long id, MultipartFile file) throws Exception {
|
|
|
+
|
|
|
+ TextVoiceTransfer textVoiceTransfer = null;
|
|
|
+ if(Objects.nonNull(id)) {
|
|
|
+ textVoiceTransfer = textVoiceTransferService.getById(id);
|
|
|
+ textVoiceTransfer.setUpdateTime(new Date());
|
|
|
+ }else{
|
|
|
+ textVoiceTransfer = new TextVoiceTransfer();
|
|
|
+ textVoiceTransfer.setNum(num);
|
|
|
+ }
|
|
|
+
|
|
|
+ String filename = file.getOriginalFilename();
|
|
|
+ File localFile = FileUtil.file(String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + UUID.randomUUID() + "/." + FileUtil.extName(filename));
|
|
|
+ file.transferTo(localFile);
|
|
|
+ String ossPath = String.format(FileYunPath.TEMP_PATH, num) + localFile.getName();
|
|
|
+ String url = fYunFileService.uploadFile(localFile.getAbsolutePath(), ossPath);
|
|
|
+ String taskId = asrUtil.voiceToText(url);
|
|
|
+ textVoiceTransfer.setTaskId(taskId);
|
|
|
+ textVoiceTransfer.setVoiceName(filename);
|
|
|
+ textVoiceTransfer.setType("asr");
|
|
|
+ textVoiceTransfer.setStatus(CommonSuccessStatus.WAITING.code());
|
|
|
+ textVoiceTransferService.saveOrUpdate(textVoiceTransfer);
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteTextVoiceTransfer(TextVoiceTransferDTO dto) {
|
|
|
+ if(Objects.isNull(dto.getId())){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
|
|
|
+ }
|
|
|
+ TextVoiceTransfer transfer = textVoiceTransferService.getById(dto.getId());
|
|
|
+ if(Objects.isNull(transfer)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(!dto.getNum().equals(transfer.getNum())){
|
|
|
+ throw new BusinessException(ErrorCode.NOT_RECORD);
|
|
|
+ }
|
|
|
+ textVoiceTransferService.removeById(dto.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void save(ScrbSaveDTO param) {
|
|
|
+ if(CollUtil.isNotEmpty(param.getBaseSetting())){
|
|
|
+ sceneEditInfoScrbService.update(
|
|
|
+ new LambdaUpdateWrapper<SceneEditInfoScrb>()
|
|
|
+ .eq(SceneEditInfoScrb::getNum, param.getNum())
|
|
|
+ .set(SceneEditInfoScrb::getBaseSetting, JSON.toJSONString(param.getBaseSetting())));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(CollUtil.isNotEmpty(param.getAiSetting())){
|
|
|
+ sceneEditInfoScrbService.update(
|
|
|
+ new LambdaUpdateWrapper<SceneEditInfoScrb>()
|
|
|
+ .eq(SceneEditInfoScrb::getNum, param.getNum())
|
|
|
+ .set(SceneEditInfoScrb::getAiSetting, JSON.toJSONString(param.getAiSetting())));
|
|
|
+ }else{
|
|
|
+ sceneEditInfoScrbService.update(
|
|
|
+ new LambdaUpdateWrapper<SceneEditInfoScrb>()
|
|
|
+ .eq(SceneEditInfoScrb::getNum, param.getNum())
|
|
|
+ .set(SceneEditInfoScrb::getAiSetting, null));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(CollUtil.isNotEmpty(param.getNavigation())){
|
|
|
+ sceneEditInfoScrbService.update(
|
|
|
+ new LambdaUpdateWrapper<SceneEditInfoScrb>()
|
|
|
+ .eq(SceneEditInfoScrb::getNum, param.getNum())
|
|
|
+ .set(SceneEditInfoScrb::getAiSetting, JSON.toJSONString(param.getNavigation())));
|
|
|
+ }else{
|
|
|
+ sceneEditInfoScrbService.update(
|
|
|
+ new LambdaUpdateWrapper<SceneEditInfoScrb>()
|
|
|
+ .eq(SceneEditInfoScrb::getNum, param.getNum())
|
|
|
+ .set(SceneEditInfoScrb::getNavigation, null));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|