From be9067ec8e81d5f58cd3f54c4b6a752e25057432 Mon Sep 17 00:00:00 2001 From: xhxu Date: Fri, 27 Oct 2023 10:48:46 +0800 Subject: [PATCH] //live --- .../src/main/resources/application-dev.yml | 1 + .../src/main/resources/application-prod.yml | 1 + .../controller/UserLiveController.java | 226 +++++++++++------- .../src/main/resources/application-dev.yml | 1 + .../src/main/resources/application-prod.yml | 1 + .../src/main/resources/application-dev.yml | 1 + .../src/main/resources/application-prod.yml | 1 + .../service/WxCUserAuthorityService.java | 2 + .../com/iformall/service/WxCVideoService.java | 2 +- .../com/iformall/service/WxCVoiceService.java | 6 +- .../impl/WxCUserAuthorityServiceImpl.java | 51 +--- .../service/impl/WxCVideoServiceImpl.java | 23 +- .../service/impl/WxCVoiceServiceImpl.java | 72 +++--- .../java/com/iformall/sm/AiTtsHelper.java | 75 ++++++ 14 files changed, 273 insertions(+), 190 deletions(-) create mode 100644 suimangService/src/main/java/com/iformall/sm/AiTtsHelper.java diff --git a/suimangAdmin/src/main/resources/application-dev.yml b/suimangAdmin/src/main/resources/application-dev.yml index 5eaf35c..51fd7ac 100644 --- a/suimangAdmin/src/main/resources/application-dev.yml +++ b/suimangAdmin/src/main/resources/application-dev.yml @@ -204,6 +204,7 @@ logging: suimang: oral_broadcasting: xxx + video_tts: photo_speak: xxx photo_speak_hy: xxx digital_avatar: xxx diff --git a/suimangAdmin/src/main/resources/application-prod.yml b/suimangAdmin/src/main/resources/application-prod.yml index a3241f1..a57e8c1 100644 --- a/suimangAdmin/src/main/resources/application-prod.yml +++ b/suimangAdmin/src/main/resources/application-prod.yml @@ -160,6 +160,7 @@ logging: suimang: oral_broadcasting: xxx + video_tts: photo_speak: xxx photo_speak_hy: xxx digital_avatar: xxx diff --git a/suimangCApi/src/main/java/com/iformall/controller/UserLiveController.java b/suimangCApi/src/main/java/com/iformall/controller/UserLiveController.java index 3b58187..91a228d 100644 --- a/suimangCApi/src/main/java/com/iformall/controller/UserLiveController.java +++ b/suimangCApi/src/main/java/com/iformall/controller/UserLiveController.java @@ -85,43 +85,44 @@ public class UserLiveController extends BaseController { @PostMapping("/login") @ApiOperation(value = "用户登录", notes = "{\"username\":\"string\",\"password\":\"string\",\"code\":\"string\",\"status\":\"int\"}") public Map login(@RequestBody Map map, HttpServletResponse response) { - Map wxCLiveLoginVos = new HashMap<>(); String ipAddr = getIpAddr(); logger.debug("[" + ipAddr + "] WxUserGrantController::login"); + + Map resultMap = new HashMap<>(); + HashMap status = new HashMap<>(); + + String code = map.get("code"); String phone = map.get("username"); String password = map.get("password"); + if (StringUtils.isBlank(phone) || StringUtils.isBlank(password)) { - HashMap status = new HashMap<>(); status.put("code", ErrorCode.SYS_PARAMETER_ERROR.getCode()); status.put("message", "手机号或密码为空"); - wxCLiveLoginVos.put("status", status); - return wxCLiveLoginVos; + resultMap.put("status", status); + return resultMap; } WxCUserBasicInfo basicInfo = wxCUserBasicInfoService.findInfoByPhone(getTenantInfo(), phone); if (basicInfo == null) { - HashMap status = new HashMap<>(); status.put("code", ErrorCode.USER_IS_EMPTY); status.put("message", "用户不存在"); - wxCLiveLoginVos.put("status", status); - return wxCLiveLoginVos; + resultMap.put("status", status); + return resultMap; } String encryptPassword = new PasswordHelper().encryptPassword(password); if (!encryptPassword.equals(basicInfo.getPassword())) { - HashMap status = new HashMap<>(); status.put("code", ErrorCode.USER_PASSWD_ERR.getCode()); status.put("message", "手机号或密码错误"); - wxCLiveLoginVos.put("status", status); - return wxCLiveLoginVos; + resultMap.put("status", status); + return resultMap; } int statu = Integer.parseInt(map.get("status")); if (statu == 0) { WxCUserBasicInfo basicLiveInfo = wxCLiveUserBasicInfoService.getById(basicInfo.getId()); - if (basicLiveInfo.getCode() != null && !map.get("code").equals(basicLiveInfo.getCode())) { - HashMap status = new HashMap<>(); + if (basicLiveInfo.getCode() != null && !basicLiveInfo.getCode().equals(code)) { status.put("code", ErrorCode.USER_ALREADY_LOGIN.getCode()); status.put("message", "用户已在其他设备登录"); - wxCLiveLoginVos.put("status", status); - return wxCLiveLoginVos; + resultMap.put("status", status); + return resultMap; } if (basicLiveInfo.getCode() == null) { wxCLiveUserBasicInfoService.updateCode(basicInfo.getId(), map.get("code")); @@ -130,37 +131,28 @@ public class UserLiveController extends BaseController { if (statu == -1) { wxCLiveUserBasicInfoService.updateCode(basicInfo.getId(), null); basicInfo.setStatus(-2); - HashMap status = new HashMap<>(); status.put("code", ErrorCode.USER_CANCEL_MCODE.getCode()); status.put("message", "设备已注销"); - wxCLiveLoginVos.put("status", status); - return wxCLiveLoginVos; + resultMap.put("status", status); + return resultMap; } wxCUserBasicInfoService.handleLoginUser(basicInfo); WxCUserBasicInfo basicLiveInfo = wxCLiveUserBasicInfoService.getById(basicInfo.getId()); - WxCLiveLoginVo wxCLiveLoginVo = new WxCLiveLoginVo(); - wxCLiveLoginVo.setCode(map.get("code")); - wxCLiveLoginVo.setUsername(map.get("username")); - Map info = new HashMap(); + Map data = new HashMap(); - Map status = new HashMap<>(); - status.put("code", 1000); - status.put("message", "success"); - data.put("token", basicInfo.getToken()); + data.put("username",basicInfo.getPhone()); data.put("status", 0); data.put("version", basicLiveInfo.getVersion()); data.put("current_time", new Date(System.currentTimeMillis() / 1000)); data.put("expire_time", basicLiveInfo.getExpireTime().getTime() / 1000); - info.put("log_id", basicInfo.getId()); - info.put("server_type", "user login"); - info.put("username", basicInfo.getPhone()); - wxCLiveLoginVos.put("data", data); - wxCLiveLoginVos.put("info", info); - wxCLiveLoginVo.setData(data); - wxCLiveLoginVo.setInfo(info); - wxCLiveLoginVos.put("status", status); - System.out.println("wxCLiveLoginVo.getToken() = " + wxCLiveLoginVo.getToken()); - return wxCLiveLoginVos; + data.put("token", basicInfo.getToken()); + resultMap.put("data", data); + + status.put("code", 1000); + status.put("message", "success"); + resultMap.put("status", status); + + return resultMap; } /** @@ -170,24 +162,30 @@ public class UserLiveController extends BaseController { @PostMapping("/avatarList") @ApiOperation(value = "视频模板列表", notes = "{\"username\",\"string\",\"code\",\"string\"}") public Map avatarList(@RequestBody Map params) throws Exception { - Map avatarVos = new HashMap<>(); String ipaddress = getIpAddr(); logger.debug("[" + ipaddress + "] WxUserGrantController::getAvatarList"); - Long id = getMemberId(); + + Map resultMap = new HashMap<>(); + HashMap status = new HashMap<>(); + + String code = params.get("code"); + Long userId = getMemberId(); //鉴权 - WxCUserBasicInfo basicLiveInfo = wxCLiveUserBasicInfoService.getById(id); - if (basicLiveInfo.getCode() != null && !params.get("code").equals(basicLiveInfo.getCode())) { - HashMap status = new HashMap<>(); + WxCUserBasicInfo basicLiveInfo = wxCLiveUserBasicInfoService.getById(userId); + if (basicLiveInfo.getCode() != null && !basicLiveInfo.getCode().equals(code)) { status.put("code", ErrorCode.USER_ALREADY_LOGIN.getCode()); status.put("message", "用户已在其他设备登录"); - avatarVos.put("status", status); - return avatarVos; + resultMap.put("status", status); + return resultMap; } - Map status = new HashMap<>(); + + Map data = wxCVideoService.getById(userId); + resultMap.put("data", data); + status.put("code", 1000); status.put("msg", "success"); - avatarVos.put("status", status); - return wxCVideoService.getById(id); + resultMap.put("status", status); + return resultMap; } @@ -198,77 +196,134 @@ public class UserLiveController extends BaseController { @PostMapping("/audioList") @ApiOperation(value = "音频模板列表", notes = "{\"username\",\"string\",\"code\",\"string\"}") public Map audioList(@RequestBody Map params) { - Map resultMap = new HashMap<>(); String ipaddress = getIpAddr(); logger.debug("[" + ipaddress + "] WxUserGrantController::getAudioList"); - Long id = getMemberId(); - WxCUserBasicInfo basicLiveInfo = wxCLiveUserBasicInfoService.getById(id); - if (basicLiveInfo.getCode() != null && !params.get("code").equals(basicLiveInfo.getCode())) { - HashMap status = new HashMap<>(); + + Map resultMap = new HashMap<>(); + HashMap status = new HashMap<>(); + + String code = params.get("code"); + + Long userId = getMemberId(); + WxCUserBasicInfo basicLiveInfo = wxCLiveUserBasicInfoService.getById(userId); + if (basicLiveInfo.getCode() != null && !basicLiveInfo.getCode().equals(code)) { status.put("code", ErrorCode.USER_ALREADY_LOGIN.getCode()); status.put("message", "用户已在其他设备登录"); resultMap.put("status", status); return resultMap; } - return wxCVoiceService.getById(id,null); + Map data = wxCVoiceService.getById(userId); + resultMap.put("data", data); + + status.put("code", 1000); + status.put("msg", "success"); + resultMap.put("status", status); + return resultMap; } /** * 资源权限查询 */ - - @ApiOperation(value = "资源权限查询", notes = "{\"username\",\"string\",\"code\",\"string\",\"type\",\"int\",\"resource_id\",\"long\"}") @PostMapping("/author") public Map getAuthor(@RequestBody Map params) { - Map resultMap = new HashMap<>(); String ipaddress = getIpAddr(); logger.debug("[" + ipaddress + "] WxUserGrantController::getAuthor"); - Long id = getMemberId(); - WxCUserBasicInfo basicLiveInfo = wxCLiveUserBasicInfoService.getById(id); - if (basicLiveInfo.getCode() != null && !params.get("code").equals(basicLiveInfo.getCode())) { - HashMap status = new HashMap<>(); + + Map resultMap = new HashMap<>(); + HashMap status = new HashMap<>(); + + String code = params.get("code"); + Integer type = Integer.parseInt(params.get("type")); + Long resourceId = Long.valueOf(params.get("resource_id")); + + if(type == null){ + status.put("code", ErrorCode.SYS_PARAMETER_NOT_NULL.getCode()); + status.put("message", "type 为空"); + resultMap.put("status", status); + return resultMap; + } + if(resourceId == null){ + status.put("code", ErrorCode.SYS_PARAMETER_NOT_NULL.getCode()); + status.put("message", "资源ID 为空"); + resultMap.put("status", status); + return resultMap; + } + + Long userId = getMemberId(); + WxCUserBasicInfo basicLiveInfo = wxCLiveUserBasicInfoService.getById(userId); + if (basicLiveInfo.getCode() != null && !basicLiveInfo.getCode().equals(code)) { status.put("code", ErrorCode.USER_ALREADY_LOGIN.getCode()); status.put("message", "用户已在其他设备登录"); resultMap.put("status", status); return resultMap; } - String code = params.get("code"); - Integer type = Integer.parseInt(params.get("type")); - Long resourceId = Long.valueOf(params.get("resource_id")); - return wxCUserAuthorityService.getAuthor(id, code, type, resourceId); + + Map data = wxCUserAuthorityService.getAuthor(userId, code, type, resourceId); + if(data != null){ + resultMap.put("data", data); + + status.put("code", 1000); + status.put("msg", "success"); + resultMap.put("status", status); + return resultMap; + } + + status.put("code", ErrorCode.SYS_NULLPOINTER_ERROR.getCode()); + status.put("msg", "未查询到资源权限"); + resultMap.put("status", status); + return resultMap; } @ApiOperation(value = "tts", notes = "{\"username\",\"string\",\"gen_txt\",\"string\",\"voice_id\",\"string\",\"voice_style\",\"string\",\"speed\",\"int\"}") @PostMapping("/audiotts") public Map voicePreview(@RequestBody Map params) { logger.debug("[" + getIpAddr() + "] UserLiveController::voicePreview"); - Long id = getMemberId(); - AiPreviewParam param = new AiPreviewParam(); - if (params.get("voice_id") == null) { - Map status = new HashMap<>(); - status.put("code", ErrorCode.SYS_SERVER_ERROR.getCode()); + Map resultMap = new HashMap<>(); + HashMap status = new HashMap<>(); + + String voice_id = params.get("voice_id"); + String voiceStyle = params.get("voice_style"); + if (StringUtils.isBlank(voice_id)) { + status.put("code", ErrorCode.SYS_PARAMETER_NOT_NULL.getCode()); status.put("msg", "音色ID不能为空"); - return status; + resultMap.put("status", status); + return resultMap; } - if (StringUtils.isBlank(params.get("gen_txt"))) { - Map status = new HashMap<>(); - status.put("code", ErrorCode.SYS_SERVER_ERROR.getCode()); - status.put("msg", "需要生成的文字不能为空"); - return status; + Long voiceId = null; + try{ + voiceId = Long.parseLong(voice_id); + }catch(Exception e){ + status.put("code", ErrorCode.SYS_PARAMETER_ERROR.getCode()); + status.put("msg", "音色ID参数异常"); + resultMap.put("status", status); + return resultMap; + } + + String text = params.get("gen_txt"); + if (StringUtils.isBlank(text)) { + resultMap.put("code", ErrorCode.SYS_PARAMETER_NOT_NULL.getCode()); + resultMap.put("msg", "需要生成的文字不能为空"); + return resultMap; } - if (Integer.parseInt(params.get("speed")) == -1) { - param.setSpeed(0); + String speedStr = params.get("speed"); + Integer speed = null; + try{ + speed = Integer.parseInt(speedStr); + }catch(Exception e){} + + Map data = wxCVoiceService.voicePreview(voiceId,voiceStyle,text,speed); + if(data != null){ + resultMap.put("data", data); + + status.put("code", 1000); + status.put("msg", "success"); + resultMap.put("status", status); + return resultMap; } - param.setSpeed(Integer.parseInt(params.get("speed"))); - param.setVoice_id(params.get("voice_id")); - param.setVoice_style(params.get("voice_style")); - param.setGen_txt(params.get("gen_txt")); - Map resultMap = wxCVoiceService.voicePreview(param); - Map info = new HashMap<>(); - info.put("log_id", id); - info.put("server_type", "audio tts"); - resultMap.put("info", info); + status.put("code", ErrorCode.SYS_PARAMETER_NOT_NULL.getCode()); + status.put("msg", "获取tts 异常"); + resultMap.put("status", status); return resultMap; } @@ -330,7 +385,6 @@ public class UserLiveController extends BaseController { public ResultData chooseType(Long id) { logger.debug("[" + getIpAddr() + "] MouldPatchController::chooseType"); List voiceInfos = wxCVoiceService.chooseType(id); - System.out.println("voiceInfos = " + voiceInfos); - return new ResultData(wxCVoiceService.chooseType(id)); + return new ResultData(voiceInfos); } } diff --git a/suimangCApi/src/main/resources/application-dev.yml b/suimangCApi/src/main/resources/application-dev.yml index 83ec583..34fe0f0 100644 --- a/suimangCApi/src/main/resources/application-dev.yml +++ b/suimangCApi/src/main/resources/application-dev.yml @@ -190,6 +190,7 @@ logging: suimang: oral_broadcasting: http://111.198.0.15:22266 + video_tts: http://111.198.0.15:22222 photo_speak: http://111.198.0.15:22299 photo_speak_hy: http://111.198.0.15:22288 digital_avatar: http://nas.pucao.cn:2005 diff --git a/suimangCApi/src/main/resources/application-prod.yml b/suimangCApi/src/main/resources/application-prod.yml index 8ba888b..11ebb74 100644 --- a/suimangCApi/src/main/resources/application-prod.yml +++ b/suimangCApi/src/main/resources/application-prod.yml @@ -145,6 +145,7 @@ logging: suimang: oral_broadcasting: http://111.198.0.15:22266 + video_tts: http://111.198.0.15:22222 photo_speak: http://111.198.0.15:22299 photo_speak_hy: http://111.198.0.15:22288 digital_avatar: http://111.198.0.15:22200 diff --git a/suimangSchedule/src/main/resources/application-dev.yml b/suimangSchedule/src/main/resources/application-dev.yml index d4669fc..09b46ef 100644 --- a/suimangSchedule/src/main/resources/application-dev.yml +++ b/suimangSchedule/src/main/resources/application-dev.yml @@ -193,6 +193,7 @@ logging: suimang: oral_broadcasting: http://nas.pucao.cn:2001 + video_tts: http://111.198.0.15:22222 photo_speak: http://111.198.0.15:22299 photo_speak_hy: http://111.198.0.15:22288 digital_avatar: http://nas.pucao.cn:2005 diff --git a/suimangSchedule/src/main/resources/application-prod.yml b/suimangSchedule/src/main/resources/application-prod.yml index 83e1c3f..149b481 100644 --- a/suimangSchedule/src/main/resources/application-prod.yml +++ b/suimangSchedule/src/main/resources/application-prod.yml @@ -149,6 +149,7 @@ logging: suimang: oral_broadcasting: http://111.198.0.15:22266 + video_tts: http://111.198.0.15:22222 photo_speak: http://111.198.0.15:22299 photo_speak_hy: http://111.198.0.15:22288 digital_avatar: http://111.198.0.15:22200 diff --git a/suimangService/src/main/java/com/iformall/service/WxCUserAuthorityService.java b/suimangService/src/main/java/com/iformall/service/WxCUserAuthorityService.java index 201a62e..1c2d76a 100644 --- a/suimangService/src/main/java/com/iformall/service/WxCUserAuthorityService.java +++ b/suimangService/src/main/java/com/iformall/service/WxCUserAuthorityService.java @@ -5,5 +5,7 @@ import com.iformall.common.ResultData; import java.util.Map; public interface WxCUserAuthorityService { + Map getAuthor(Long id, String code, Integer type, Long resourceId); + } diff --git a/suimangService/src/main/java/com/iformall/service/WxCVideoService.java b/suimangService/src/main/java/com/iformall/service/WxCVideoService.java index 0d96c1c..84674f8 100644 --- a/suimangService/src/main/java/com/iformall/service/WxCVideoService.java +++ b/suimangService/src/main/java/com/iformall/service/WxCVideoService.java @@ -8,7 +8,7 @@ import java.util.Map; public interface WxCVideoService { - Map getById(Long id) throws Exception; + Map getById(Long userId) throws Exception; WxCVideoTable selectOne(Long id, long resource_id); } diff --git a/suimangService/src/main/java/com/iformall/service/WxCVoiceService.java b/suimangService/src/main/java/com/iformall/service/WxCVoiceService.java index f1b86ed..4c11bc3 100644 --- a/suimangService/src/main/java/com/iformall/service/WxCVoiceService.java +++ b/suimangService/src/main/java/com/iformall/service/WxCVoiceService.java @@ -8,9 +8,11 @@ import java.util.List; import java.util.Map; public interface WxCVoiceService { - Map getById(Long id,String phone); + + Map getById(Long userId); List chooseType(Long id); - Map voicePreview(AiPreviewParam aiPreviewParam); + Map voicePreview(Long voiceId, String voiceStyle, String text, Integer speed); + } diff --git a/suimangService/src/main/java/com/iformall/service/impl/WxCUserAuthorityServiceImpl.java b/suimangService/src/main/java/com/iformall/service/impl/WxCUserAuthorityServiceImpl.java index 868a141..1c823fc 100644 --- a/suimangService/src/main/java/com/iformall/service/impl/WxCUserAuthorityServiceImpl.java +++ b/suimangService/src/main/java/com/iformall/service/impl/WxCUserAuthorityServiceImpl.java @@ -19,8 +19,9 @@ public class WxCUserAuthorityServiceImpl implements WxCUserAuthorityService { @Override public Map getAuthor(Long id, String code, Integer type, Long resourceId) { - List resultList = new ArrayList(); + HashMap authorVos = new HashMap<>(); + List resultList = new ArrayList(); if (type == 0) { //查询数字人相关权限 @@ -31,41 +32,9 @@ public class WxCUserAuthorityServiceImpl implements WxCUserAuthorityService { resultList = wxCUserAuthorityMapper.getAuthorVoice(id, 1, resourceId); } - if (resourceId == null || resourceId == -1) { - //若资源id没有传入那就展示所有当前类型资源权限 - HashMap info = new HashMap<>(); - HashMap status = new HashMap<>(); - List authorList = new ArrayList(); - for (WxCUserAuthority wxCUserAuthority : resultList) { - HashMap data = new HashMap<>(); - data.put("username", wxCUserAuthority.getUserName()); - data.put("type", wxCUserAuthority.getType()); - data.put("resource_id", wxCUserAuthority.getResourceId()); - data.put("class", wxCUserAuthority.getClassType()); - data.put("current_time", new Date(System.currentTimeMillis() / 1000)); - data.put("expire_time", wxCUserAuthority.getExpireTime().getTime() / 1000); - authorList.add(data); - } - authorVos.put("authorList", authorList); - info.put("log_id", id); - info.put("server_type", "author"); - authorVos.put("info", info); - status.put("code", 1000); - status.put("msg", "success"); - authorVos.put("status", status); - return authorVos; - } - HashMap data = new HashMap<>(); - HashMap info = new HashMap<>(); - HashMap status = new HashMap<>(); - if (resultList.size() == 0) { - status.put("code", 5001); - status.put("msg", "没有该资源的权限"); - authorVos.put("status", status); - return authorVos; - } - for (WxCUserAuthority wxCUserAuthority : resultList) { - data.put("username", wxCUserAuthority.getUserName()); + if (resultList.size() == 1) { + HashMap data = new HashMap<>(); + WxCUserAuthority wxCUserAuthority = resultList.get(0); data.put("type", wxCUserAuthority.getType()); data.put("resource_id", wxCUserAuthority.getResourceId()); @@ -75,14 +44,8 @@ public class WxCUserAuthorityServiceImpl implements WxCUserAuthorityService { data.put("class", EnumClassType.SHARE.getCode()); data.put("current_time", new Date(System.currentTimeMillis() / 1000)); data.put("expire_time", wxCUserAuthority.getExpireTime().getTime() / 1000); + return data; } - authorVos.put("data", data); - info.put("log_id", id); - info.put("server_type", "author"); - authorVos.put("info", info); - status.put("code", 1000); - status.put("msg", "success"); - authorVos.put("status", status); - return authorVos; + return null; } } diff --git a/suimangService/src/main/java/com/iformall/service/impl/WxCVideoServiceImpl.java b/suimangService/src/main/java/com/iformall/service/impl/WxCVideoServiceImpl.java index fc7b6e9..31ecae1 100644 --- a/suimangService/src/main/java/com/iformall/service/impl/WxCVideoServiceImpl.java +++ b/suimangService/src/main/java/com/iformall/service/impl/WxCVideoServiceImpl.java @@ -39,13 +39,12 @@ public class WxCVideoServiceImpl implements WxCVideoService, IExcelExportServer WxCVideoMapper wxCVideoMapper; @Override - public Map getById(Long id) { - List TemplateVideo = wxCVideoMapper.getById(id); - Map avatarVos = new HashMap(); + public Map getById(Long userId) { Map data = new HashMap(); + + List TemplateVideo = wxCVideoMapper.getById(userId); List authorlist = new ArrayList(); for (WxCVideoTable wxCVideoTable : TemplateVideo) { - data.put("username", wxCVideoTable.getUserName()); data.put("current_time", new Date(System.currentTimeMillis() / 1000)); Map avatar = new HashMap(); @@ -63,7 +62,6 @@ public class WxCVideoServiceImpl implements WxCVideoService, IExcelExportServer avatar.put("avatar_model_md5", wxCVideoTable.getModelMd5()); } - try { File preinfoFile = new File(wxCVideoTable.getPreInfoPath()); avatar.put("avatar_preinfo_md5", getFileMD5(preinfoFile)); @@ -75,19 +73,10 @@ public class WxCVideoServiceImpl implements WxCVideoService, IExcelExportServer avatar.put("expire_time", wxCVideoTable.getExpireTime().getTime() / 1000); avatar.put("class", wxCVideoTable.getClassType()); authorlist.add(avatar); - data.put("authorlist", authorlist); } - avatarVos.put("data", data); - Map info = new HashMap(); - Map status = new HashMap(); - info.put("log_id", id); - info.put("server_type", "avatar list"); - status.put("code", 1000); - status.put("msg", "success"); - avatarVos.put("info", info); - avatarVos.put("status", status); - - return avatarVos; + data.put("authorlist", authorlist); + + return data; } @Override diff --git a/suimangService/src/main/java/com/iformall/service/impl/WxCVoiceServiceImpl.java b/suimangService/src/main/java/com/iformall/service/impl/WxCVoiceServiceImpl.java index c3180a7..26ef18b 100644 --- a/suimangService/src/main/java/com/iformall/service/impl/WxCVoiceServiceImpl.java +++ b/suimangService/src/main/java/com/iformall/service/impl/WxCVoiceServiceImpl.java @@ -17,9 +17,12 @@ import com.iformall.mapper.WxCVoiceMapper; import com.iformall.service.WxCVoiceService; import com.iformall.sm.AiPreviewParam; import com.iformall.sm.AiPreviewResult; +import com.iformall.sm.AiTtsHelper; import com.iformall.sm.AiVideoHelper; import com.iformall.utils.Constant; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; @@ -28,6 +31,7 @@ import java.util.*; @Service public class WxCVoiceServiceImpl implements WxCVoiceService { + private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired WxCVoiceMapper wxCVoiceMapper; @@ -43,11 +47,10 @@ public class WxCVoiceServiceImpl implements WxCVoiceService { @Override - public Map getById(Long id,String phone) { - List resultList = wxCVoiceMapper.getById(id); - HashMap result = new HashMap<>(); + public Map getById(Long userId) { HashMap data = new HashMap<>(); - data.put("username", phone); + + List resultList = wxCVoiceMapper.getById(userId); data.put("current_time", new Date(System.currentTimeMillis() / 1000)); // List audioList = new ArrayList(); Map> audioList = new HashMap(); @@ -102,44 +105,10 @@ public class WxCVoiceServiceImpl implements WxCVoiceService { } data.put("audioList", new ArrayList<>(audioList.values())); - - result.put("data", data); - HashMap info = new HashMap<>(); - HashMap status = new HashMap<>(); - info.put("log_id", id); - info.put("server_type", "audio list"); - result.put("info", info); - status.put("code", 1000); - status.put("msg", "success"); - result.put("status", status); - return result; - } - @Override - public Map voicePreview(AiPreviewParam aiPreviewParam) { - VoiceInfo voiceInfo = voiceMapper.selectOne(new LambdaQueryWrapper().eq(VoiceInfo::getIsDel, 0).eq(VoiceInfo::getId, aiPreviewParam.getVoice_id())); - if (ObjectUtils.isEmpty(voiceInfo)) { - Map status = new HashMap<>(); - status.put("code", ErrorCode.SYS_SERVER_ERROR.getCode()); - status.put("msg", "声音信息不存在"); - return status; - } - AiPreviewParam param = new AiPreviewParam(); - param.setGen_txt(aiPreviewParam.getGen_txt().replaceAll(Constant.text_pause, "[*]")); - param.setVoice_id(voiceInfo.getMouldSmId()); - param.setVoice_style(StringUtils.isBlank(aiPreviewParam.getVoice_style()) ? EnumSpeakType.default_0.getMessage() : aiPreviewParam.getVoice_style()); - param.setGender(voiceInfo.getSex() == 1 ? "male" : "female"); - AiPreviewResult result = AiVideoHelper.voicePreview(param); - Map resultMap = new HashMap<>(); - Map data = new HashMap<>(); - data.put("ttsurl", result.getUrl()); - Map status = new HashMap<>(); - status.put("code", 1000); - status.put("msg", "success"); - resultMap.put("data", data); - resultMap.put("status", status); - return resultMap; + return data; } + @Override public List chooseType(Long id) { List voiceInfos = voiceMapper.selectList( @@ -173,4 +142,27 @@ public class WxCVoiceServiceImpl implements WxCVoiceService { }); return voiceInfos; } + + @Override + public Map voicePreview(Long voiceId, String voiceStyle, String text, Integer speed) { + VoiceInfo voiceInfo = voiceMapper.selectById(voiceId); + if(voiceInfo == null){ + logger.error("未查询到声音{}"+voiceId); + return null; + } + + AiPreviewParam param = new AiPreviewParam(); + param.setVoice_id(voiceInfo.getMouldSmId()); + param.setVoice_style(StringUtils.isBlank(voiceStyle) ? EnumSpeakType.default_0.getMessage() : voiceStyle); + param.setGen_txt(text.replaceAll(Constant.text_pause, "[*]")); + param.setSpeed(speed==null?100:speed); + AiPreviewResult aiTtsResult = AiTtsHelper.voicePreview(param); + if(!aiTtsResult.isSuccess()){ + logger.error("tts 预览失败{}"+aiTtsResult.getMsg()); + return null; + } + Map data = new HashMap<>(); + data.put("ttsurl", aiTtsResult.getUrl()); + return data; + } } diff --git a/suimangService/src/main/java/com/iformall/sm/AiTtsHelper.java b/suimangService/src/main/java/com/iformall/sm/AiTtsHelper.java new file mode 100644 index 0000000..e4b3fab --- /dev/null +++ b/suimangService/src/main/java/com/iformall/sm/AiTtsHelper.java @@ -0,0 +1,75 @@ +package com.iformall.sm; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.iformall.utils.Base64Util; +import com.iformall.utils.HttpUtil; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class AiTtsHelper { + + public static String video_tts; + @Value("${suimang.video_tts}") + public void setVideoTts(String video_tts){ + this.video_tts = video_tts; + } + + + public static String doPost(String url, String params) { + return HttpUtil.doAiVideoPost(url,params); + } + + + public static AiPreviewResult voicePreview(AiPreviewParam param) { + String response = doPost(video_tts + "/tts_wav", JSONObject.toJSONString(param)); + log.info("TTS音色预览 end response:" + response); + AiPreviewResult result = new AiPreviewResult(); + + if (StringUtils.isBlank(response)) { + result.setSuccess(false); + result.setMsg("(MetaService)TTS音色预览失败,请稍后重试"); + return result; + } + JSONObject jsonObject = JSON.parseObject(response); + JSONObject status = jsonObject.getJSONObject("status"); + + Integer code = status.getInteger("code"); + String msg = status.getString("msg"); + if (code == null) { + result.setSuccess(false); + result.setMsg("(MetaService)TTS音色预览异常,请稍后重试"); + return result; + } + if (code.intValue() == 3000) { + JSONObject data = jsonObject.getJSONObject("data"); + String strURL = data.getString("url"); + String time = data.getString("time"); + + result.setCode(200); + result.setSuccess(true); + result.setUrl(video_tts + strURL); + result.setTime(Double.valueOf(time)); + String resultMsg = result.getMsgInfo(code, msg); + result.setMsg(resultMsg); + } else { + result.setCode(code); + result.setSuccess(false); + String resultMsg = result.getMsgInfo(code, msg); + result.setMsg(resultMsg); + } + return result; + } + + + + public static void main(String[] args) { + + } + + +}