| @@ -0,0 +1,38 @@ | |||||
| package com.iformall.controller.ai; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.sm.UserMouldVideo; | |||||
| import com.iformall.dto.GenerateVideoDTO; | |||||
| import com.iformall.dto.PreviewVideoDTO; | |||||
| import com.iformall.service.AiVideoService; | |||||
| import com.iformall.sm.AiPreviewParam; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.PostMapping; | |||||
| import org.springframework.web.bind.annotation.RequestBody; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | |||||
| import org.springframework.web.bind.annotation.RestController; | |||||
| @Api(tags = "视频相关api") | |||||
| @RestController | |||||
| @RequestMapping("/ai/video") | |||||
| public class AiVideoController { | |||||
| @Autowired | |||||
| private AiVideoService aiVideoService; | |||||
| @ApiOperation("预览") | |||||
| @PostMapping("/preview") | |||||
| public ResultData previewVideo(@RequestBody PreviewVideoDTO dto) { | |||||
| return new ResultData(aiVideoService.previewVideo(dto)); | |||||
| } | |||||
| @ApiOperation("生成视频") | |||||
| @PostMapping("generateVideo") | |||||
| public ResultData generateVideo(@RequestBody GenerateVideoDTO dto) { | |||||
| aiVideoService.generateVideo(dto); | |||||
| return new ResultData(); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,12 @@ | |||||
| package com.iformall.dto; | |||||
| import io.swagger.annotations.ApiModel; | |||||
| import io.swagger.annotations.ApiModelProperty; | |||||
| import lombok.Data; | |||||
| @ApiModel(value = "生成视频请求参数") | |||||
| @Data | |||||
| public class GenerateVideoDTO { | |||||
| @ApiModelProperty(value = "视频唯一标识") | |||||
| private Long id; | |||||
| } | |||||
| @@ -0,0 +1,25 @@ | |||||
| package com.iformall.dto; | |||||
| import com.iformall.sm.AiPreviewParam; | |||||
| import io.swagger.annotations.ApiModel; | |||||
| import io.swagger.annotations.ApiModelProperty; | |||||
| import lombok.Data; | |||||
| @ApiModel(value = "预览视频请求参数") | |||||
| @Data | |||||
| public class PreviewVideoDTO { | |||||
| @ApiModelProperty("文案") | |||||
| private String paperwork; | |||||
| @ApiModelProperty("声音id") | |||||
| private String voiceId; | |||||
| @ApiModelProperty("声音风格名称") | |||||
| private String voiceStyle; | |||||
| public static AiPreviewParam mappingParam(PreviewVideoDTO dto) { | |||||
| AiPreviewParam aiPreviewParam = new AiPreviewParam(); | |||||
| aiPreviewParam.setGen_txt(dto.getPaperwork()); | |||||
| aiPreviewParam.setVoice_id(dto.getVoiceId()); | |||||
| aiPreviewParam.setVoice_style(dto.getVoiceStyle()); | |||||
| return aiPreviewParam; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,22 @@ | |||||
| package com.iformall.service; | |||||
| import com.iformall.dto.GenerateVideoDTO; | |||||
| import com.iformall.dto.PreviewVideoDTO; | |||||
| import com.iformall.sm.AiPreviewParam; | |||||
| /** | |||||
| * ai视频服务 | |||||
| * | |||||
| * @author xmzhao71 | |||||
| * @date 2023-10-18 | |||||
| */ | |||||
| public interface AiVideoService { | |||||
| Double previewVideo(PreviewVideoDTO dto); | |||||
| /** | |||||
| * 生成视频 | |||||
| * | |||||
| * @param dto | |||||
| */ | |||||
| void generateVideo(GenerateVideoDTO dto); | |||||
| } | |||||
| @@ -0,0 +1,68 @@ | |||||
| package com.iformall.service.impl; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.domain.po.sm.UserMouldVideo; | |||||
| import com.iformall.dto.GenerateVideoDTO; | |||||
| import com.iformall.dto.PreviewVideoDTO; | |||||
| import com.iformall.enums.EnumVideoStatus; | |||||
| import com.iformall.exception.BizException; | |||||
| import com.iformall.service.AiVideoService; | |||||
| import com.iformall.service.sm.UserMouldVideoService; | |||||
| import com.iformall.service.sm.VoiceInfoService; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.Date; | |||||
| import java.util.Optional; | |||||
| /** | |||||
| * ai视频服务 | |||||
| * | |||||
| * @author xmzhao71 | |||||
| * @date 2023-10-18 | |||||
| */ | |||||
| @Service | |||||
| public class AiVideoServiceImpl implements AiVideoService { | |||||
| @Autowired | |||||
| private VoiceInfoService voiceInfoService; | |||||
| @Autowired | |||||
| private UserMouldVideoService userMouldVideoService; | |||||
| @Override | |||||
| public Double previewVideo(PreviewVideoDTO dto) { | |||||
| return voiceInfoService.previewVoice(PreviewVideoDTO.mappingParam(dto)); | |||||
| } | |||||
| @Override | |||||
| public void generateVideo(GenerateVideoDTO dto) { | |||||
| // 参数校验 | |||||
| UserMouldVideo userMouldVideo = Optional.ofNullable(userMouldVideoService.getById(dto.getId())).orElseThrow(() -> new BizException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "未找到用户数据")); | |||||
| if (StringUtils.isBlank(userMouldVideo.getPaperwork())) { | |||||
| throw new BizException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "未填写视频文案"); | |||||
| } | |||||
| if (EnumVideoStatus.ing.getCode().equals(userMouldVideo.getVideoStatus()) | |||||
| || EnumVideoStatus.success.getCode().equals(userMouldVideo.getVideoStatus()) | |||||
| || EnumVideoStatus.upload_ing.getCode().equals(userMouldVideo.getVideoStatus()) | |||||
| || EnumVideoStatus.upload_fail.getCode().equals(userMouldVideo.getVideoStatus())) { | |||||
| throw new BizException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "视频生成中"); | |||||
| } | |||||
| if (EnumVideoStatus.upload_success.getCode().equals(userMouldVideo.getVideoStatus())) { | |||||
| throw new BizException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "视频已生成完成"); | |||||
| } | |||||
| // 更新视频信息 | |||||
| updateUserMouldVideo(userMouldVideo); | |||||
| userMouldVideoService.createVideo(userMouldVideo); | |||||
| } | |||||
| private void updateUserMouldVideo(UserMouldVideo userMouldVideo) { | |||||
| UserMouldVideo video = new UserMouldVideo(); | |||||
| video.setId(userMouldVideo.getId()); | |||||
| video.setVideoStatus(EnumVideoStatus.ing.getCode()); | |||||
| video.setVideoMsg(""); | |||||
| video.setCreateVideoDate(new Date()); | |||||
| userMouldVideoService.updateById(video); | |||||
| } | |||||
| } | |||||
| @@ -1,14 +1,9 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.alibaba.fastjson.JSONArray; | |||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.fasterxml.jackson.databind.ObjectMapper; | |||||
| import com.google.gson.JsonObject; | |||||
| import com.iformall.annotation.AuthIgnore; | import com.iformall.annotation.AuthIgnore; | ||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxCVoiceTable; | |||||
| import com.iformall.domain.po.sm.PhotoSpeakVideo; | import com.iformall.domain.po.sm.PhotoSpeakVideo; | ||||
| import com.iformall.domain.po.sm.PreviewParam; | import com.iformall.domain.po.sm.PreviewParam; | ||||
| import com.iformall.enums.EnumVideoStatus; | import com.iformall.enums.EnumVideoStatus; | ||||
| @@ -82,7 +77,7 @@ public class SDKController extends BaseController { | |||||
| param.setVoice_style(previewParam.getVoiceStyle()); | param.setVoice_style(previewParam.getVoiceStyle()); | ||||
| param.setGen_txt(previewParam.getGenTxt()); | param.setGen_txt(previewParam.getGenTxt()); | ||||
| param.setGender(previewParam.getGender()); | param.setGender(previewParam.getGender()); | ||||
| return new ResultData(voiceInfoService.voicePreview(param)); | |||||
| return new ResultData(voiceInfoService.previewVoice(param)); | |||||
| } | } | ||||
| @ApiOperation("生成视频") | @ApiOperation("生成视频") | ||||
| @@ -5,13 +5,11 @@ import com.iformall.annotation.AuthIgnore; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.base.BaseEntity; | import com.iformall.domain.po.base.BaseEntity; | ||||
| import com.iformall.domain.po.sm.MouldPatch; | |||||
| import com.iformall.domain.po.sm.PersonMould; | import com.iformall.domain.po.sm.PersonMould; | ||||
| import com.iformall.domain.po.sm.UserMouldVideo; | import com.iformall.domain.po.sm.UserMouldVideo; | ||||
| import com.iformall.domain.po.sm.VoiceMould; | import com.iformall.domain.po.sm.VoiceMould; | ||||
| import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
| import com.iformall.language.LanguageDetect; | import com.iformall.language.LanguageDetect; | ||||
| import com.iformall.mapper.VoiceLanguageMapper; | |||||
| import com.iformall.service.WxCVoiceService; | import com.iformall.service.WxCVoiceService; | ||||
| import com.iformall.service.sm.*; | import com.iformall.service.sm.*; | ||||
| import com.iformall.sm.AiPreviewParam; | import com.iformall.sm.AiPreviewParam; | ||||
| @@ -20,7 +18,6 @@ import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.checkerframework.checker.units.qual.A; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -28,7 +25,6 @@ import org.springframework.web.bind.annotation.*; | |||||
| import java.util.HashMap; | import java.util.HashMap; | ||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | |||||
| @RestController | @RestController | ||||
| @@ -166,7 +162,7 @@ public class VoiceMouldController extends BaseController { | |||||
| @ApiImplicitParams({}) | @ApiImplicitParams({}) | ||||
| public ResultData voicePreview(@RequestBody AiPreviewParam aiPreviewParam) { | public ResultData voicePreview(@RequestBody AiPreviewParam aiPreviewParam) { | ||||
| logger.debug("[" + getIpAddr() + "] MouldPatchController::voicePreview"); | logger.debug("[" + getIpAddr() + "] MouldPatchController::voicePreview"); | ||||
| return new ResultData(voiceInfoService.voicePreview(aiPreviewParam)); | |||||
| return new ResultData(voiceInfoService.previewVoice(aiPreviewParam)); | |||||
| } | } | ||||
| @@ -15,5 +15,5 @@ public interface VoiceInfoService { | |||||
| VoiceInfo getById(Long voiceMouldId); | VoiceInfo getById(Long voiceMouldId); | ||||
| ResultData voicePreview(AiPreviewParam aiPreviewParam); | |||||
| Double previewVoice(AiPreviewParam aiPreviewParam); | |||||
| } | } | ||||
| @@ -11,6 +11,7 @@ import com.iformall.domain.po.sm.VoiceInfo; | |||||
| import com.iformall.domain.vo.VoiceInfoVo; | import com.iformall.domain.vo.VoiceInfoVo; | ||||
| import com.iformall.enums.EnumSex; | import com.iformall.enums.EnumSex; | ||||
| import com.iformall.enums.EnumSpeakType; | import com.iformall.enums.EnumSpeakType; | ||||
| import com.iformall.exception.BizException; | |||||
| import com.iformall.file.aliyun.bean.AliyunOSSConfig; | import com.iformall.file.aliyun.bean.AliyunOSSConfig; | ||||
| import com.iformall.mapper.VoiceMapper; | import com.iformall.mapper.VoiceMapper; | ||||
| import com.iformall.service.sm.VoiceInfoService; | import com.iformall.service.sm.VoiceInfoService; | ||||
| @@ -23,6 +24,7 @@ import org.springframework.util.ObjectUtils; | |||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Optional; | |||||
| @Service | @Service | ||||
| public class VoiceInfoServiceImpl implements VoiceInfoService { | public class VoiceInfoServiceImpl implements VoiceInfoService { | ||||
| @@ -77,11 +79,12 @@ public class VoiceInfoServiceImpl implements VoiceInfoService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public ResultData voicePreview(AiPreviewParam aiPreviewParam) { | |||||
| VoiceInfo voiceInfo = voiceMapper.selectOne(new LambdaQueryWrapper<VoiceInfo>().eq(VoiceInfo::getIsDel, 0).eq(VoiceInfo::getId, aiPreviewParam.getVoice_id())); | |||||
| if (ObjectUtils.isEmpty(voiceInfo)){ | |||||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(), "声音信息不存在"); | |||||
| } | |||||
| public Double previewVoice(AiPreviewParam aiPreviewParam) { | |||||
| VoiceInfo voiceInfo = voiceMapper.selectOne(new LambdaQueryWrapper<VoiceInfo>() | |||||
| .eq(VoiceInfo::getIsDel, 0) | |||||
| .eq(VoiceInfo::getId, aiPreviewParam.getVoice_id())); | |||||
| voiceInfo = Optional.ofNullable(voiceInfo).orElseThrow(() -> new BizException(ErrorCode.SYS_SERVER_ERROR.getCode(), "声音信息不存在")); | |||||
| AiPreviewParam param = new AiPreviewParam(); | AiPreviewParam param = new AiPreviewParam(); | ||||
| param.setGen_txt(aiPreviewParam.getGen_txt().replaceAll(Constant.text_pause,"[*]")); | param.setGen_txt(aiPreviewParam.getGen_txt().replaceAll(Constant.text_pause,"[*]")); | ||||
| param.setVoice_id(voiceInfo.getMouldSmId()); | param.setVoice_id(voiceInfo.getMouldSmId()); | ||||
| @@ -89,9 +92,9 @@ public class VoiceInfoServiceImpl implements VoiceInfoService { | |||||
| param.setGender(voiceInfo.getSex() == 1 ? "male" : "female"); | param.setGender(voiceInfo.getSex() == 1 ? "male" : "female"); | ||||
| AiPreviewResult result = AiVideoHelper.voicePreview(param); | AiPreviewResult result = AiVideoHelper.voicePreview(param); | ||||
| if (result.isSuccess()){ | if (result.isSuccess()){ | ||||
| return new ResultData(result.getTime()); | |||||
| return result.getTime(); | |||||
| } | } | ||||
| return new ResultData(result.getCode(), result.getMsgInfo(result.getCode(),result.getMsg())); | |||||
| throw new BizException(result.getCode(), result.getMsgInfo(result.getCode(),result.getMsg())); | |||||
| } | } | ||||
| } | } | ||||