package com.iformall.controller; import com.github.pagehelper.PageInfo; import com.iformall.annotation.AuthIgnore; import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.po.base.BaseEntity; import com.iformall.domain.po.sm.PersonMould; import com.iformall.domain.po.sm.UserMouldVideo; import com.iformall.domain.po.sm.VoiceLanguage; import com.iformall.domain.po.sm.VoiceMould; import com.iformall.enums.*; import com.iformall.language.LanguageDetect; import com.iformall.service.WxCVoiceService; import com.iformall.service.sm.*; import com.iformall.sm.AiPreviewParam; import com.iformall.smsdk.SmPreviewVideoDTO; import com.iformall.smsdk.SmSdkUtils; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.List; @RestController @RequestMapping("/api/voiceMould") @Api(description = "模板接口") public class VoiceMouldController extends BaseController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private VoiceMouldService voiceMouldService; @Autowired private PersonMouldService personMouldService; @Autowired private MouldPatchSignService mouldPatchSignService; @Autowired private VoiceInfoService voiceInfoService; @Autowired private VoiceLanguageService voiceLanguageService; @Autowired private WxCVoiceService wxCVoiceService; @AuthIgnore @ApiOperation("获取语种") @GetMapping("getLanguages") @ApiImplicitParams({}) public ResultData getLanguages() { logger.debug("[" + getIpAddr() + "] VoiceMouldController::getLanguages"); List> allLanguages = EnumLanguages.getAllLanguages(); return new ResultData(allLanguages); } @AuthIgnore @ApiOperation("分页列表接口") @GetMapping("list") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) public ResultData list(@ModelAttribute VoiceMould record, Integer pageNum, Integer pageSize) { logger.debug("[" + getIpAddr() + "] MouldPatchController::list"); if (record == null) record = new VoiceMould(); // record.setSendType(EnumMouldSendType.auto.getCode()); record.setStatus(EnumaMouldPatchStatus.put_on.getCode()); record.setSortColumns(BaseEntity.SortField.UpdateDate_DESC); final PageInfo page = voiceMouldService.cListAsPage(record, pageNum, pageSize); return new ResultData(page); } @AuthIgnore @ApiOperation("根据id查询接口") @GetMapping("/findById") @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) public ResultData findById(Long id) { logger.debug("[" + getIpAddr() + "] MouldPatchController::findById"); VoiceMould voiceMould = voiceMouldService.getDetailById(id); if (voiceMould != null && voiceMould.getParentId() == 0l && voiceMould.getCountSub() > 0) { VoiceMould voiceQ = new VoiceMould(); voiceQ.setParentId(voiceMould.getId()); voiceQ.setVoiceType(EnumVoiceType.speak.getCode());//目前只查询说话风格 voiceQ.setStatus(EnumaMouldPatchStatus.put_on.getCode()); voiceQ.setSortColumns(BaseEntity.SortField.UpdateDate_DESC); List sublist = voiceMouldService.getClist(voiceQ); if (sublist != null && !sublist.isEmpty()) { voiceMould.setSubVoiceMould(sublist); } } return new ResultData(voiceMould); } @ApiOperation("根据输入文案获取音色") @PostMapping("voiceList") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) public ResultData voiceList(@RequestBody UserMouldVideo record, Integer pageNum, Integer pageSize) { logger.debug("[" + getIpAddr() + "] MouldPatchController::voiceList"); if (record == null || StringUtils.isBlank(record.getPaperwork())) { return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); } Integer sex = null; if (record.getPersonMouldId() != null) { PersonMould personMode = personMouldService.getDetailById(record.getPersonMouldId()); if (personMode == null) { return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "选择模板不存在"); } sex = personMode.getSex(); } String detect = LanguageDetect.detect(record.getPaperwork()); if (StringUtils.isBlank(detect)) { return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "语种识别失败"); } EnumLanguages anEnum = EnumLanguages.getEnum(detect); if (anEnum == null) { return new ResultData(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "暂不支持该语种"); } VoiceMould voiceMould = new VoiceMould(); voiceMould.setParentId(0l); voiceMould.setSex(sex); voiceMould.setSendType(EnumMouldSendType.auto.getCode()); voiceMould.setStatus(EnumaMouldPatchStatus.put_on.getCode()); voiceMould.setLanguages(anEnum.getCode().longValue()); voiceMould.setSortColumns(BaseEntity.SortField.UpdateDate_DESC); final PageInfo page = voiceMouldService.cListAsPage(voiceMould, pageNum, pageSize); return new ResultData(page); } @AuthIgnore @ApiOperation("语言选择下拉框") @GetMapping("/voiceTotal") @ApiImplicitParams({}) public ResultData voiceTotal() { return new ResultData(voiceLanguageService.voiceTotal(new VoiceLanguage())); } @ApiOperation("登录状态下语言选择下拉框") @GetMapping("/loginVoiceTotal") @ApiImplicitParams({}) public ResultData loginVoiceTotal() { VoiceLanguage vl = new VoiceLanguage(); vl.setCustomizedQuery(EnumYesOrNo.YES.getCode()); vl.setCustomizedUserId(getMemberId()); return new ResultData(voiceLanguageService.voiceTotal(vl)); } @AuthIgnore @ApiOperation("选择声音选择风格") @GetMapping("/chooseType") @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true) public ResultData chooseType(Long id) { logger.debug("[" + getIpAddr() + "] MouldPatchController::chooseType"); return new ResultData(voiceInfoService.chooseType(id)); } @AuthIgnore @ApiOperation("TTS音色预览") @PostMapping("/preview") @ApiImplicitParams({}) public ResultData voicePreview(@RequestBody AiPreviewParam aiPreviewParam) { logger.debug("[" + getIpAddr() + "] MouldPatchController::voicePreview"); return new ResultData(voiceInfoService.previewVoice(aiPreviewParam)); } }