mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-29 18:23:59 +08:00
update:新增音色资源时判断声音id是否已经存在
This commit is contained in:
@@ -196,4 +196,5 @@ public interface ErrorCode {
|
|||||||
int VOICE_CLONE_RESPONSE_FORMAT_ERROR = 10156; // 响应格式错误
|
int VOICE_CLONE_RESPONSE_FORMAT_ERROR = 10156; // 响应格式错误
|
||||||
int VOICE_CLONE_REQUEST_FAILED = 10157; // 请求失败
|
int VOICE_CLONE_REQUEST_FAILED = 10157; // 请求失败
|
||||||
int VOICE_CLONE_PREFIX = 10158; // 复刻音色前缀
|
int VOICE_CLONE_PREFIX = 10158; // 复刻音色前缀
|
||||||
|
int VOICE_ID_ALREADY_EXISTS = 10159; // 音色ID已存在
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ import org.springframework.context.i18n.LocaleContextHolder;
|
|||||||
public class MessageUtils {
|
public class MessageUtils {
|
||||||
private static MessageSource messageSource;
|
private static MessageSource messageSource;
|
||||||
|
|
||||||
static {
|
|
||||||
messageSource = (MessageSource) SpringContextUtils.getBean("messageSource");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getMessage(int code) {
|
public static String getMessage(int code) {
|
||||||
return getMessage(code, new String[0]);
|
return getMessage(code, new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getMessage(int code, String... params) {
|
public static String getMessage(int code, String... params) {
|
||||||
|
if (messageSource == null) {
|
||||||
|
// 延迟初始化,确保Spring上下文已完全初始化
|
||||||
|
messageSource = (MessageSource) SpringContextUtils.getBean("messageSource");
|
||||||
|
}
|
||||||
return messageSource.getMessage(code + "", params, LocaleContextHolder.getLocale());
|
return messageSource.getMessage(code + "", params, LocaleContextHolder.getLocale());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -80,6 +80,8 @@ public class VoiceResourceController {
|
|||||||
try {
|
try {
|
||||||
voiceCloneService.save(dto);
|
voiceCloneService.save(dto);
|
||||||
return new Result<Void>();
|
return new Result<Void>();
|
||||||
|
} catch (xiaozhi.common.exception.RenException e) {
|
||||||
|
return new Result<Void>().error(e.getCode(), e.getMsg());
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
return new Result<Void>().error(ErrorCode.ADD_DATA_FAILED, e.getMessage());
|
return new Result<Void>().error(ErrorCode.ADD_DATA_FAILED, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
+11
@@ -74,6 +74,17 @@ public class VoiceCloneServiceImpl extends BaseServiceImpl<VoiceCloneDao, VoiceC
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void save(VoiceCloneDTO dto) {
|
public void save(VoiceCloneDTO dto) {
|
||||||
|
// 检查Voice ID是否已经被使用
|
||||||
|
for (String voiceId : dto.getVoiceIds()) {
|
||||||
|
QueryWrapper<VoiceCloneEntity> wrapper = new QueryWrapper<>();
|
||||||
|
wrapper.eq("voice_id", voiceId);
|
||||||
|
wrapper.eq("model_id", dto.getModelId());
|
||||||
|
Long count = baseDao.selectCount(wrapper);
|
||||||
|
if (count > 0) {
|
||||||
|
throw new RenException(ErrorCode.VOICE_ID_ALREADY_EXISTS, "音色ID " + voiceId + " 已存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 遍历选择的音色ID,为每个音色ID创建一条记录
|
// 遍历选择的音色ID,为每个音色ID创建一条记录
|
||||||
int index = 0;
|
int index = 0;
|
||||||
String namePrefix = DateUtils.format(new java.util.Date(), "MMddHHmm");
|
String namePrefix = DateUtils.format(new java.util.Date(), "MMddHHmm");
|
||||||
|
|||||||
@@ -164,4 +164,5 @@
|
|||||||
10155=Huoshan Engine configuration missing
|
10155=Huoshan Engine configuration missing
|
||||||
10156=Response format error, missing BaseResp field
|
10156=Response format error, missing BaseResp field
|
||||||
10157=Request failed
|
10157=Request failed
|
||||||
10158=Clone Voice:
|
10158=Clone Voice:
|
||||||
|
10159=Voice ID already exists
|
||||||
@@ -165,3 +165,4 @@
|
|||||||
10156=\u54CD\u5E94\u683C\u5F0F\u9519\u8BEF\uFF0C\u7F3A\u5C11BaseResp\u5B57\u6BB5
|
10156=\u54CD\u5E94\u683C\u5F0F\u9519\u8BEF\uFF0C\u7F3A\u5C11BaseResp\u5B57\u6BB5
|
||||||
10157=\u8BF7\u6C42\u5931\u8D25
|
10157=\u8BF7\u6C42\u5931\u8D25
|
||||||
10158=\u514b\u9686\u8272\u97f3:
|
10158=\u514b\u9686\u8272\u97f3:
|
||||||
|
10159=\u97F3\u8272ID\u5DF2\u5B58\u5728
|
||||||
|
|||||||
@@ -164,4 +164,5 @@
|
|||||||
10155=\u706B\u5C71\u5F15\u64CE\u7F3A\u5C11appid\u6216access_token
|
10155=\u706B\u5C71\u5F15\u64CE\u7F3A\u5C11appid\u6216access_token
|
||||||
10156=\u97FF\u61C9\u683C\u5F0F\u932F\u8AA4\uFF0C\u7F3A\u5C11BaseResp\u5B57\u6BB5
|
10156=\u97FF\u61C9\u683C\u5F0F\u932F\u8AA4\uFF0C\u7F3A\u5C11BaseResp\u5B57\u6BB5
|
||||||
10157=\u8ACB\u6C42\u5931\u6557
|
10157=\u8ACB\u6C42\u5931\u6557
|
||||||
10158=\u514b\u9686\u8a9e\u97f3:
|
10158=\u514b\u9686\u8a9e\u97f3:
|
||||||
|
10159=\u97F3\u8272ID\u5DF2\u5B58\u5728
|
||||||
Reference in New Issue
Block a user