|
|
@@ -5,14 +5,14 @@ import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.google.common.collect.Lists; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.sm.VoiceInfo; |
|
|
|
import com.iformall.enums.EnumSex; |
|
|
|
import com.iformall.enums.EnumSpeakType; |
|
|
|
import com.iformall.mapper.VoiceMapper; |
|
|
|
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.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@@ -51,27 +51,21 @@ public class VoiceInfoServiceImpl implements VoiceInfoService { |
|
|
|
} |
|
|
|
|
|
|
|
@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(); |
|
|
|
} |
|
|
|
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()); |
|
|
|
} |
|
|
|
} |