| @@ -13,6 +13,7 @@ import com.iformall.enums.*; | |||||
| import com.iformall.language.LanguageDetect; | import com.iformall.language.LanguageDetect; | ||||
| import com.iformall.mapper.VoiceLanguageMapper; | import com.iformall.mapper.VoiceLanguageMapper; | ||||
| import com.iformall.service.sm.*; | import com.iformall.service.sm.*; | ||||
| import com.iformall.sm.AiPreviewParam; | |||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| @@ -157,12 +158,9 @@ public class VoiceMouldController extends BaseController { | |||||
| @AuthIgnore | @AuthIgnore | ||||
| @ApiOperation("TTS音色预览") | @ApiOperation("TTS音色预览") | ||||
| @GetMapping("/preview") | @GetMapping("/preview") | ||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "genTxt", value = "需要生成的文字", dataType = "String", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "voiceId", value = "音色ID", dataType = "Long", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "voiceStyle", value = "语音风格", dataType = "String", paramType = "query", required = true)}) | |||||
| public ResultData voicePreview(String genTxt, Long voiceId, String voiceStyle) { | |||||
| @ApiImplicitParams({}) | |||||
| public ResultData voicePreview(@RequestBody AiPreviewParam aiPreviewParam) { | |||||
| logger.debug("[" + getIpAddr() + "] MouldPatchController::voicePreview"); | logger.debug("[" + getIpAddr() + "] MouldPatchController::voicePreview"); | ||||
| return new ResultData(voiceInfoService.voicePreview(genTxt, voiceId, voiceStyle)); | |||||
| return new ResultData(voiceInfoService.voicePreview(aiPreviewParam)); | |||||
| } | } | ||||
| } | } | ||||
| @@ -5,6 +5,7 @@ import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.sm.VoiceInfo; | import com.iformall.domain.po.sm.VoiceInfo; | ||||
| import com.iformall.domain.po.sm.VoiceLanguage; | import com.iformall.domain.po.sm.VoiceLanguage; | ||||
| import com.iformall.sm.AiPreviewParam; | |||||
| import java.util.List; | import java.util.List; | ||||
| @@ -14,5 +15,5 @@ public interface VoiceInfoService { | |||||
| VoiceInfo getById(Long voiceMouldId); | VoiceInfo getById(Long voiceMouldId); | ||||
| ResultData voicePreview(String genTxt, Long voiceId, String voiceStyle); | |||||
| ResultData voicePreview(AiPreviewParam aiPreviewParam); | |||||
| } | } | ||||
| @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; | |||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.sm.MaterialMould; | import com.iformall.domain.po.sm.MaterialMould; | ||||
| @@ -138,6 +139,9 @@ public class PersonPhotoServiceImpl implements PersonPhotoService { | |||||
| AiCheckPhotoParam param = new AiCheckPhotoParam(); | AiCheckPhotoParam param = new AiCheckPhotoParam(); | ||||
| param.setImg(Base64Util.imageUrlToBase64(material)); | param.setImg(Base64Util.imageUrlToBase64(material)); | ||||
| AiCheckPhotoResult result = AiVideoHelper.checkPhoto(param); | AiCheckPhotoResult result = AiVideoHelper.checkPhoto(param); | ||||
| return new ResultData(result.getCode(), result.getMsg()); | |||||
| if (result.isSuccess()){ | |||||
| return new ResultData(); | |||||
| } | |||||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(), result.getMsg()); | |||||
| } | } | ||||
| } | } | ||||
| @@ -5,14 +5,14 @@ import com.alibaba.fastjson.JSON; | |||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||||
| import com.google.common.collect.Lists; | import com.google.common.collect.Lists; | ||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.sm.VoiceInfo; | import com.iformall.domain.po.sm.VoiceInfo; | ||||
| import com.iformall.enums.EnumSex; | import com.iformall.enums.EnumSex; | ||||
| import com.iformall.enums.EnumSpeakType; | import com.iformall.enums.EnumSpeakType; | ||||
| import com.iformall.mapper.VoiceMapper; | import com.iformall.mapper.VoiceMapper; | ||||
| import com.iformall.service.sm.VoiceInfoService; | import com.iformall.service.sm.VoiceInfoService; | ||||
| import com.iformall.sm.AiPhotoSpeakResult; | |||||
| import com.iformall.sm.AiVideoHelper; | |||||
| import com.iformall.sm.*; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| @@ -51,27 +51,21 @@ public class VoiceInfoServiceImpl implements VoiceInfoService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public ResultData voicePreview(String genTxt, Long voiceId, String voiceStyle) { | |||||
| if (voiceId == null || StringUtils.isBlank(genTxt)) { | |||||
| public ResultData voicePreview(AiPreviewParam aiPreviewParam) { | |||||
| if (aiPreviewParam.getVoiceId() == null || StringUtils.isBlank(aiPreviewParam.getGenTxt())) { | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| VoiceInfo voiceInfo = voiceMapper.selectOne(new LambdaQueryWrapper<VoiceInfo>().eq(VoiceInfo::getIsDel, 0).eq(VoiceInfo::getId, voiceId)); | |||||
| JSONObject jsonObject = new JSONObject(); | |||||
| jsonObject.put("gen_txt", genTxt); | |||||
| jsonObject.put("voice_id", voiceInfo.getMouldSmId()); | |||||
| jsonObject.put("voice_style", StringUtils.isBlank(voiceStyle) ? "default" : voiceStyle); | |||||
| jsonObject.put("gender", voiceInfo.getSex() == 1 ? "male" : "female"); | |||||
| String response = AiVideoHelper.doPost("http://nas.pucao.cn:2002/tts_wav", jsonObject.toJSONString()); | |||||
| if (StringUtils.isNotBlank(response)) { | |||||
| String str = "http://nas.pucao.cn:2002"; | |||||
| JSONObject object = JSON.parseObject(response); | |||||
| JSONObject status = object.getJSONObject("status"); | |||||
| Integer code = status.getInteger("code"); | |||||
| if (code.intValue() == 3000) { | |||||
| JSONObject data = object.getJSONObject("data"); | |||||
| return new ResultData(str + data.getString("url")); | |||||
| } | |||||
| VoiceInfo voiceInfo = voiceMapper.selectOne(new LambdaQueryWrapper<VoiceInfo>().eq(VoiceInfo::getIsDel, 0).eq(VoiceInfo::getId, aiPreviewParam.getVoiceId())); | |||||
| AiPreviewParam param = new AiPreviewParam(); | |||||
| param.setGenTxt(aiPreviewParam.getGenTxt()); | |||||
| param.setVoiceId(voiceInfo.getMouldSmId()); | |||||
| param.setVoiceStyle(StringUtils.isBlank(aiPreviewParam.getVoiceStyle()) ? "default" : aiPreviewParam.getVoiceStyle()); | |||||
| param.setGender(voiceInfo.getSex() == 1 ? "male" : "female"); | |||||
| AiPreviewResult result = AiVideoHelper.voicePreview(param); | |||||
| if (result.isSuccess()){ | |||||
| return new ResultData(); | |||||
| } | } | ||||
| return new ResultData(); | |||||
| return new ResultData(ErrorCode.SYS_SERVER_ERROR.getCode(), result.getMsg()); | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,12 @@ | |||||
| package com.iformall.sm; | |||||
| import lombok.Data; | |||||
| @Data | |||||
| public class AiPreviewParam { | |||||
| private String genTxt; | |||||
| private String voiceId; | |||||
| private String voiceStyle; | |||||
| private String gender; | |||||
| } | |||||
| @@ -0,0 +1,14 @@ | |||||
| package com.iformall.sm; | |||||
| import io.swagger.models.auth.In; | |||||
| import lombok.Data; | |||||
| @Data | |||||
| public class AiPreviewResult { | |||||
| private boolean success; | |||||
| private Integer code; | |||||
| private String msg; | |||||
| private String url; | |||||
| } | |||||
| @@ -34,6 +34,7 @@ public class AiVideoHelper { | |||||
| public static String url = "http://nas.pucao.cn:2002"; | public static String url = "http://nas.pucao.cn:2002"; | ||||
| public static String photo_speak_suffix = "/img_talking"; | public static String photo_speak_suffix = "/img_talking"; | ||||
| public static String image_quality_suffix = "/image_qualit"; | public static String image_quality_suffix = "/image_qualit"; | ||||
| public static String voice_preview = "/tts_wav"; | |||||
| public static String doPost(String url, String params) { | public static String doPost(String url, String params) { | ||||
| return HttpUtil.doAiVideoPost(url,params); | return HttpUtil.doAiVideoPost(url,params); | ||||
| @@ -163,6 +164,39 @@ public class AiVideoHelper { | |||||
| return result; | return result; | ||||
| } | } | ||||
| public static AiPreviewResult voicePreview(AiPreviewParam param) { | |||||
| String response = doPost(url + voice_preview, JSONObject.toJSONString(param)); | |||||
| log.info("TTS音色预览 end response:" + response); | |||||
| AiPreviewResult result = new AiPreviewResult(); | |||||
| if (StringUtils.isBlank(response)) { | |||||
| result.setSuccess(false); | |||||
| result.setMsg("TTS音色预览失败,请稍后重试"); | |||||
| return result; | |||||
| } | |||||
| JSONObject jsonObject = JSON.parseObject(response); | |||||
| JSONObject status = jsonObject.getJSONObject("status"); | |||||
| JSONObject data = jsonObject.getJSONObject("data"); | |||||
| Integer code = status.getInteger("code"); | |||||
| String msg = status.getString("msg"); | |||||
| if (code == null) { | |||||
| result.setSuccess(false); | |||||
| result.setMsg("TTS音色预览异常,请稍后重试"); | |||||
| return result; | |||||
| } | |||||
| if (code.intValue() == 3000) { | |||||
| result.setCode(200); | |||||
| result.setSuccess(true); | |||||
| result.setUrl(url + data.getString("url")); | |||||
| result.setMsg(msg); | |||||
| } else { | |||||
| result.setCode(code); | |||||
| result.setSuccess(false); | |||||
| result.setMsg(msg); | |||||
| } | |||||
| return result; | |||||
| } | |||||
| public static void main(String[] args) { | public static void main(String[] args) { | ||||
| // AiVideoParam videoParam = new AiVideoParam(); | // AiVideoParam videoParam = new AiVideoParam(); | ||||
| // videoParam.setGen_txt("我写了一篇小说,你帮我看看。"); | // videoParam.setGen_txt("我写了一篇小说,你帮我看看。"); | ||||
| @@ -201,4 +235,5 @@ public class AiVideoHelper { | |||||
| } | } | ||||
| } | } | ||||