|
@@ -3,9 +3,12 @@ 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 cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.fdkankan.common.constant.CommonOperStatus;
|
|
|
import com.fdkankan.common.constant.CommonSuccessStatus;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
@@ -21,6 +24,7 @@ import com.fdkankan.scene.service.*;
|
|
|
import com.fdkankan.scene.util.AsrUtil;
|
|
|
import com.fdkankan.scene.util.TtsUtil;
|
|
|
import com.fdkankan.web.response.ResultData;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -32,6 +36,7 @@ import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class ScrbServiceImpl implements IScrbService {
|
|
|
|
|
@@ -62,7 +67,7 @@ public class ScrbServiceImpl implements IScrbService {
|
|
|
status = CommonSuccessStatus.FAIL.code();
|
|
|
}else{
|
|
|
status = CommonSuccessStatus.SUCCESS.code();
|
|
|
- String text = param.getText();
|
|
|
+ String text = param.getText().replaceAll("\\[.*?\\]", "").replaceAll("\\n", "");
|
|
|
task.setDocument(text);
|
|
|
}
|
|
|
task.setResCode(param.getCode());
|
|
@@ -73,6 +78,33 @@ public class ScrbServiceImpl implements IScrbService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void ttsCallback(String data) {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(data);
|
|
|
+ Integer status = jsonObject.getInteger("Status");
|
|
|
+ String taskId = jsonObject.getString("TaskId");
|
|
|
+ TextVoiceTransfer textVoiceTransfer = textVoiceTransferService.getByTaskId(taskId);
|
|
|
+ if(status == 2){
|
|
|
+ String url = jsonObject.getString("ResultUrl");
|
|
|
+ String localVoicePath = String.format(ConstantFilePath.SCENE_USER_PATH_V4, textVoiceTransfer.getNum()) + taskId + "." + "mp3";
|
|
|
+ FileUtil.mkParentDirs(localVoicePath);
|
|
|
+ HttpUtil.downloadFile(url, localVoicePath);
|
|
|
+ String obsPath = String.format(FileYunPath.SCRB_EDIT_PATH, textVoiceTransfer.getNum()) + FileUtil.getName(localVoicePath);
|
|
|
+ fYunFileService.uploadFile(localVoicePath, obsPath);
|
|
|
+ textVoiceTransfer.setVoicePath(obsPath);
|
|
|
+ textVoiceTransfer.setResCode(status);
|
|
|
+ textVoiceTransfer.setStatus(CommonOperStatus.SUCCESS.code());
|
|
|
+ textVoiceTransfer.setUpdateTime(new Date());
|
|
|
+ textVoiceTransferService.updateById(textVoiceTransfer);
|
|
|
+ }
|
|
|
+ if(status == 3){
|
|
|
+ textVoiceTransfer.setResCode(status);
|
|
|
+ textVoiceTransfer.setStatus(CommonOperStatus.FAILD.code());
|
|
|
+ textVoiceTransfer.setUpdateTime(new Date());
|
|
|
+ textVoiceTransferService.updateById(textVoiceTransfer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public List<TextVoiceTransfer> listTextVoiceTransfer(String num) {
|
|
|
return textVoiceTransferService.list(new LambdaQueryWrapper<TextVoiceTransfer>().eq(TextVoiceTransfer::getNum, num));
|
|
|
}
|
|
@@ -88,6 +120,30 @@ public class ScrbServiceImpl implements IScrbService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void ttsLongTextToVoice(TextVoiceTransferDTO dto) throws Exception {
|
|
|
+ TextVoiceTransfer textVoiceTransfer = null;
|
|
|
+ if(Objects.nonNull(dto.getId())){
|
|
|
+ textVoiceTransfer = textVoiceTransferService.getById(dto.getId());
|
|
|
+ if(Objects.isNull(textVoiceTransfer)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
|
|
|
+ }
|
|
|
+ if(!dto.getDocument().equals(textVoiceTransfer.getDocument())){
|
|
|
+ String taskId = ttsUtil.logTextToVoice(dto.getDocument(), dto.getVoiceType().longValue(), dto.getSpeed(), dto.getVolume());
|
|
|
+ textVoiceTransfer.setTaskId(taskId);
|
|
|
+ textVoiceTransferService.updateById(textVoiceTransfer);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ textVoiceTransfer = new TextVoiceTransfer();
|
|
|
+ textVoiceTransfer.setNum(dto.getNum());
|
|
|
+ textVoiceTransfer.setType("tts");
|
|
|
+ textVoiceTransfer.setDocument(dto.getDocument());
|
|
|
+ String taskId = ttsUtil.logTextToVoice(dto.getDocument(), dto.getVoiceType().longValue(), dto.getSpeed(), dto.getVolume());
|
|
|
+ textVoiceTransfer.setTaskId(taskId);
|
|
|
+ textVoiceTransferService.save(textVoiceTransfer);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public ResultData ttsSave(TextVoiceTransferDTO dto) throws Exception {
|
|
|
|
|
|
TextVoiceTransfer textVoiceTransfer = null;
|
|
@@ -124,16 +180,16 @@ public class ScrbServiceImpl implements IScrbService {
|
|
|
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 localFile = FileUtil.createTempFile(UUID.randomUUID().toString(), "." + FileUtil.extName(filename), new File(String.format(ConstantFilePath.SCENE_USER_PATH_V4, num)), true);
|
|
|
file.transferTo(localFile);
|
|
|
- String ossPath = String.format(FileYunPath.TEMP_PATH, num) + localFile.getName();
|
|
|
+ String ossPath = String.format(FileYunPath.SCRB_EDIT_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.setVoicePath(ossPath);
|
|
|
textVoiceTransfer.setStatus(CommonSuccessStatus.WAITING.code());
|
|
|
textVoiceTransferService.saveOrUpdate(textVoiceTransfer);
|
|
|
return ResultData.ok();
|