From 5e105f1f566dff1c29635270ec50a977a09460f5 Mon Sep 17 00:00:00 2001 From: xhxu Date: Fri, 28 Jul 2023 16:24:21 +0800 Subject: [PATCH] //subtile --- .../db/migration/V2023071800001_subtitle.sql | 7 +- .../controller/UserMouldVideoController.java | 9 ++ .../iformall/domain/po/sm/UserMouldVideo.java | 31 ++++- .../sm/impl/PhotoSpeakVideoServiceImpl.java | 6 +- .../sm/impl/UserMouldVideoServiceImpl.java | 119 ++++++++++++------ .../java/com/iformall/sm/AiVideoParam.java | 5 + 6 files changed, 132 insertions(+), 45 deletions(-) diff --git a/suimangAdmin/src/main/resources/db/migration/V2023071800001_subtitle.sql b/suimangAdmin/src/main/resources/db/migration/V2023071800001_subtitle.sql index d816e28..30943ea 100644 --- a/suimangAdmin/src/main/resources/db/migration/V2023071800001_subtitle.sql +++ b/suimangAdmin/src/main/resources/db/migration/V2023071800001_subtitle.sql @@ -1,3 +1,8 @@ -ALTER TABLE `mallink_suimang_test`.`photo_speak_video` +ALTER TABLE `mallink_suimang`.`photo_speak_video` ADD COLUMN `subtitle_enabled` smallint(1) COMMENT '字幕开关' AFTER `person_photo_url`, ADD COLUMN `subtitle_params` json COMMENT '字幕参数' AFTER `subtitle_enabled`; + + +ALTER TABLE `mallink_suimang`.`user_mould_video` +ADD COLUMN `subtitle_enabled` smallint(1) COMMENT '字幕开关' AFTER `person_json`, +ADD COLUMN `subtitle_params` json COMMENT '字幕参数' AFTER `subtitle_enabled`; diff --git a/suimangCApi/src/main/java/com/iformall/controller/UserMouldVideoController.java b/suimangCApi/src/main/java/com/iformall/controller/UserMouldVideoController.java index 7dceb30..8598513 100644 --- a/suimangCApi/src/main/java/com/iformall/controller/UserMouldVideoController.java +++ b/suimangCApi/src/main/java/com/iformall/controller/UserMouldVideoController.java @@ -9,6 +9,7 @@ import com.iformall.domain.po.base.BaseEntity; import com.iformall.domain.po.sm.MouldPatch; import com.iformall.domain.po.sm.MouldPatchSign; import com.iformall.domain.po.sm.UserMouldVideo; +import com.iformall.domain.po.sm.VoiceInfo; import com.iformall.domain.vo.WxCouponOrderBVo; import com.iformall.enums.EnumMouldSendType; import com.iformall.enums.EnumVideoStatus; @@ -17,6 +18,7 @@ import com.iformall.exception.MallinkException; import com.iformall.service.sm.MouldPatchService; import com.iformall.service.sm.MouldPatchSignService; import com.iformall.service.sm.UserMouldVideoService; +import com.iformall.service.sm.VoiceInfoService; import com.iformall.video.VideoFactory; import com.iformall.video.entity.VideUploadResult; import io.swagger.annotations.Api; @@ -56,6 +58,9 @@ public class UserMouldVideoController extends BaseController { @Autowired private MouldPatchService mouldPatchService; + @Autowired + private VoiceInfoService voiceInfoService; + @Autowired private VideoFactory videoFactory; @@ -91,6 +96,10 @@ public class UserMouldVideoController extends BaseController { if(mouldVideo == null || !mouldVideo.getUserId().equals(getMemberId())){ return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"未找到用户数据"); } + if(mouldVideo.getVoiceMouldId() != null){ + VoiceInfo voiceInfo = voiceInfoService.getById(mouldVideo.getVoiceMouldId()); + mouldVideo.setVoiceInfo(voiceInfo); + } return new ResultData(mouldVideo); } diff --git a/suimangService/src/main/java/com/iformall/domain/po/sm/UserMouldVideo.java b/suimangService/src/main/java/com/iformall/domain/po/sm/UserMouldVideo.java index c6fded9..5dc9320 100644 --- a/suimangService/src/main/java/com/iformall/domain/po/sm/UserMouldVideo.java +++ b/suimangService/src/main/java/com/iformall/domain/po/sm/UserMouldVideo.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.iformall.common.SortColumn; import com.iformall.domain.po.base.TenantEntity; +import com.iformall.enums.EnumSpeakType; import com.iformall.enums.EnumVideoStatus; import com.iformall.sm.AiVideoHelper; import lombok.Data; @@ -77,8 +78,14 @@ public class UserMouldVideo extends TenantEntity { @TableField(exist = false) private PersonMould personMould; - @TableField(exist = false) - private List voiceMouldIds; + @io.swagger.annotations.ApiModelProperty(value="字幕开关",name="subtitleEnabled") + private Integer subtitleEnabled; + + @io.swagger.annotations.ApiModelProperty(value="字幕参数",name="subtitleParams") + private String subtitleParams; + +// @TableField(exist = false) +// private List voiceMouldIds; @io.swagger.annotations.ApiModelProperty(value="声音模板ID",name="voiceMouldId") private Long voiceMouldId; /** @@ -96,8 +103,26 @@ public class UserMouldVideo extends TenantEntity { */ @io.swagger.annotations.ApiModelProperty(value="声音模板",name="voiceMouldSm") private String voiceMouldSm; + + @TableField(exist = false) + private String speakTypeStr; + +// @TableField(exist = false) +// private VoiceMould voiceMould; + @TableField(exist = false) - private VoiceMould voiceMould; + private VoiceInfo voiceInfo; + + public String getSpeakTypeStr(){ + if(StringUtils.isBlank(this.speakTypeStr) && StringUtils.isNotBlank(this.voiceMouldSm)){ + try{ + JSONObject personMouldObject = JSONObject.parseObject(this.voiceMouldSm); + Integer speakType = personMouldObject.getInteger("speakType"); + this.speakTypeStr = EnumSpeakType.getEnum(speakType).getMessage(); + }catch(Exception e){} + } + return speakTypeStr; + } @io.swagger.annotations.ApiModelProperty(value="文案",name="paperwork") private String paperwork; diff --git a/suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java b/suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java index ea1c0eb..2472242 100644 --- a/suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java +++ b/suimangService/src/main/java/com/iformall/service/sm/impl/PhotoSpeakVideoServiceImpl.java @@ -205,7 +205,11 @@ public class PhotoSpeakVideoServiceImpl implements PhotoSpeakVideoService { param.setCallback_url(callbackUrl + "/callback/photo/speak"); param.setImg(Base64Util.imageUrlToBase64(photoSpeakVideo.getPersonPhotoUrl())); Map subtitleMap = new HashMap<>(); - subtitleMap.put("enabled",photoSpeakVideo.getSubtitleEnabled()); + if(photoSpeakVideo.getSubtitleEnabled() == null){ + subtitleMap.put("enabled",EnumYesOrNo.NO.getCode()); + }else{ + subtitleMap.put("enabled",photoSpeakVideo.getSubtitleEnabled()); + } if(EnumYesOrNo.YES.getCode().equals(photoSpeakVideo.getSubtitleEnabled())){ Map titleParams = JSON.parseObject(photoSpeakVideo.getSubtitleParams(),Map.class); if(titleParams == null || titleParams.isEmpty()){ diff --git a/suimangService/src/main/java/com/iformall/service/sm/impl/UserMouldVideoServiceImpl.java b/suimangService/src/main/java/com/iformall/service/sm/impl/UserMouldVideoServiceImpl.java index f5deca5..b4521a1 100644 --- a/suimangService/src/main/java/com/iformall/service/sm/impl/UserMouldVideoServiceImpl.java +++ b/suimangService/src/main/java/com/iformall/service/sm/impl/UserMouldVideoServiceImpl.java @@ -1,5 +1,6 @@ package com.iformall.service.sm.impl; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageHelper; @@ -7,16 +8,10 @@ import com.github.pagehelper.PageInfo; import com.iformall.common.ErrorCode; import com.iformall.common.IdWorker; import com.iformall.common.ResultData; -import com.iformall.domain.po.sm.MaterialMould; -import com.iformall.domain.po.sm.PersonMould; -import com.iformall.domain.po.sm.UserMouldVideo; -import com.iformall.domain.po.sm.VoiceMould; +import com.iformall.domain.po.sm.*; import com.iformall.enums.*; import com.iformall.mapper.UserMouldVideoMapper; -import com.iformall.service.sm.MaterialMouldService; -import com.iformall.service.sm.PersonMouldService; -import com.iformall.service.sm.UserMouldVideoService; -import com.iformall.service.sm.VoiceMouldService; +import com.iformall.service.sm.*; import com.iformall.sm.AiVideoHelper; import com.iformall.sm.AiVideoParam; import com.iformall.sm.AiVideoResult; @@ -33,9 +28,7 @@ import org.springframework.scheduling.annotation.AsyncResult; import org.springframework.stereotype.Service; import java.net.URL; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; import java.util.concurrent.Future; @@ -52,6 +45,9 @@ public class UserMouldVideoServiceImpl implements UserMouldVideoService { @Autowired VoiceMouldService voiceMouldService; + @Autowired + VoiceInfoService voiceInfoService; + @Autowired MaterialMouldService materialMouldService; @@ -148,39 +144,65 @@ public class UserMouldVideoServiceImpl implements UserMouldVideoService { record.setBackgroundId(personMould.getBackgroundId()); } } - if(record.getVoiceMouldIds() != null && !record.getVoiceMouldIds().isEmpty()){ - if(record.getVoiceMouldIds().size() > 1){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"暂不支持声音模板交叉选择"); + + if(record.getVoiceMouldId() != null){ + VoiceInfo voiceMould = voiceInfoService.getById(record.getVoiceMouldId()); + if(voiceMould == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到声音模板信息"); } - Long voiceMouldId = record.getVoiceMouldIds().get(0); - if(voiceMouldId != null){ - VoiceMould voiceMould = voiceMouldService.getById(voiceMouldId); - if(voiceMould == null){ - return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到声音模板信息"); + JSONObject voiceMouldObject = new JSONObject(); + voiceMouldObject.put("title",voiceMould.getLocalName()); + voiceMouldObject.put("mouldSmId",voiceMould.getMouldSmId()); + voiceMouldObject.put("sex",voiceMould.getSex()); + voiceMouldObject.put("personType",0); + voiceMouldObject.put("personTypeStr","默认"); + voiceMouldObject.put("speakType",0); + voiceMouldObject.put("speakTypeStr","默认"); + EnumSpeakType speakType = null; + if(StringUtils.isNotBlank(record.getSpeakTypeStr())){ + speakType = EnumSpeakType.getEnumByMsg(record.getSpeakTypeStr()); + if(speakType == null){ + return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"声音类型信息错误"); } - record.setLanguages(voiceMould.getLanguages()); - if(voiceMould.getParentId().equals(0L)){ - record.setVoiceMouldId(voiceMould.getId()); - }else{ - record.setVoiceMouldId(voiceMould.getParentId()); - } - JSONObject voiceMouldObject = new JSONObject(); - voiceMouldObject.put("title",voiceMould.getTitle()); - voiceMouldObject.put("mouldSmId",voiceMould.getMouldSmId()); - voiceMouldObject.put("personType",0); - voiceMouldObject.put("personTypeStr","默认"); - voiceMouldObject.put("speakType",0); - voiceMouldObject.put("speakTypeStr","默认"); - if(EnumVoiceType.person.getCode().equals(voiceMould.getVoiceType())){ - voiceMouldObject.put("personType",voiceMould.getPersonType()); - voiceMouldObject.put("personTypeStr",voiceMould.getPersonTypeStr()); - }else if(EnumVoiceType.speak.getCode().equals(voiceMould.getVoiceType())){ - voiceMouldObject.put("speakType",voiceMould.getSpeakType()); - voiceMouldObject.put("speakTypeStr",voiceMould.getSpeakTypeStr()); - } - record.setVoiceMouldSm(voiceMouldObject.toJSONString()); + voiceMouldObject.put("speakType",speakType.getCode()); + voiceMouldObject.put("speakTypeStr",speakType.getMessage()); } + record.setVoiceMouldSm(voiceMouldObject.toJSONString()); + } +// if(record.getVoiceMouldIds() != null && !record.getVoiceMouldIds().isEmpty()){ +// if(record.getVoiceMouldIds().size() > 1){ +// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"暂不支持声音模板交叉选择"); +// } +// Long voiceMouldId = record.getVoiceMouldIds().get(0); +// if(voiceMouldId != null){ +// VoiceMould voiceMould = voiceMouldService.getById(voiceMouldId); +// if(voiceMould == null){ +// return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"未查询到声音模板信息"); +// } +// record.setLanguages(voiceMould.getLanguages()); +// if(voiceMould.getParentId().equals(0L)){ +// record.setVoiceMouldId(voiceMould.getId()); +// }else{ +// record.setVoiceMouldId(voiceMould.getParentId()); +// } +// JSONObject voiceMouldObject = new JSONObject(); +// voiceMouldObject.put("title",voiceMould.getTitle()); +// voiceMouldObject.put("mouldSmId",voiceMould.getMouldSmId()); +// voiceMouldObject.put("personType",0); +// voiceMouldObject.put("personTypeStr","默认"); +// voiceMouldObject.put("speakType",0); +// voiceMouldObject.put("speakTypeStr","默认"); +// if(EnumVoiceType.person.getCode().equals(voiceMould.getVoiceType())){ +// voiceMouldObject.put("personType",voiceMould.getPersonType()); +// voiceMouldObject.put("personTypeStr",voiceMould.getPersonTypeStr()); +// }else if(EnumVoiceType.speak.getCode().equals(voiceMould.getVoiceType())){ +// voiceMouldObject.put("speakType",voiceMould.getSpeakType()); +// voiceMouldObject.put("speakTypeStr",voiceMould.getSpeakTypeStr()); +// } +// record.setVoiceMouldSm(voiceMouldObject.toJSONString()); +// } +// } if(record.getBackgroundId() != null){ MaterialMould background = materialMouldService.getById(record.getBackgroundId()); if(background == null){ @@ -266,6 +288,22 @@ public class UserMouldVideoServiceImpl implements UserMouldVideoService { return new AsyncResult<>(0); } + Map subtitleMap = new HashMap<>(); + if(mouldVideo.getSubtitleEnabled() == null){ + subtitleMap.put("enabled",EnumYesOrNo.NO.getCode()); + }else{ + subtitleMap.put("enabled",mouldVideo.getSubtitleEnabled()); + } + if(EnumYesOrNo.YES.getCode().equals(mouldVideo.getSubtitleEnabled())){ + Map titleParams = JSON.parseObject(mouldVideo.getSubtitleParams(),Map.class); + if(titleParams == null || titleParams.isEmpty()){ + subtitleMap.put("enabled",EnumYesOrNo.NO.getCode()); + }else{ + subtitleMap.put("params",titleParams); + } + } + + String voiceMouldSmId = null; String voiceType = "default";//默认 if(mouldVideo.getVoiceMouldId() == null){ @@ -314,6 +352,7 @@ public class UserMouldVideoServiceImpl implements UserMouldVideoService { AiVideoParam videoParam = new AiVideoParam(); videoParam.setGen_txt(paperwork); videoParam.setVideo_template_id(personMouldSmId); + videoParam.setSubtitle(subtitleMap); videoParam.setVoice_id(voiceMouldSmId); videoParam.setVoice_style(voiceType); AiVideoParam.VideoFiles videoFiles = new AiVideoParam.VideoFiles(); diff --git a/suimangService/src/main/java/com/iformall/sm/AiVideoParam.java b/suimangService/src/main/java/com/iformall/sm/AiVideoParam.java index 5a4d4d6..226073d 100644 --- a/suimangService/src/main/java/com/iformall/sm/AiVideoParam.java +++ b/suimangService/src/main/java/com/iformall/sm/AiVideoParam.java @@ -1,9 +1,11 @@ package com.iformall.sm; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import lombok.Data; import java.util.List; +import java.util.Map; @Data public class AiVideoParam { @@ -36,6 +38,8 @@ public class AiVideoParam { private String voice_style; private VideoFiles video_files; + private Map subtitle; + public String neglectImgString(){ StringBuffer str = new StringBuffer(); str.append("{"); @@ -76,6 +80,7 @@ public class AiVideoParam { str.append("},"); } str.deleteCharAt(str.length()-1); + str.append("\"subtitle\":").append(JSON.toJSONString(subtitle)); str.append("}"); return str.toString();