mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
update:优化克隆失败显示
This commit is contained in:
+9
@@ -392,6 +392,15 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
((Map<String, Object>) model.getConfigJson()).put("ref_audio", referenceAudio);
|
||||
if (referenceText != null)
|
||||
((Map<String, Object>) model.getConfigJson()).put("ref_text", referenceText);
|
||||
|
||||
// 火山引擎声音克隆需要替换resource_id
|
||||
Map<String, Object> map = (Map<String, Object>) model.getConfigJson();
|
||||
if ("huoshan_double_stream".equals(map.get("type"))) {
|
||||
// 如果voice是”S_“开头的,使用seed-icl-1.0
|
||||
if (voice != null && voice.startsWith("S_")) {
|
||||
map.put("resource_id", "seed-icl-1.0");
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果是Intent类型,且type=intent_llm,则给他添加附加模型
|
||||
if ("Intent".equals(modelTypes[i])) {
|
||||
|
||||
+50
-48
@@ -84,7 +84,7 @@ public class VoiceCloneServiceImpl extends BaseServiceImpl<VoiceCloneDao, VoiceC
|
||||
throw new RenException(ErrorCode.VOICE_ID_ALREADY_EXISTS, "音色ID " + voiceId + " 已存在");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 遍历选择的音色ID,为每个音色ID创建一条记录
|
||||
int index = 0;
|
||||
String namePrefix = DateUtils.format(new java.util.Date(), "MMddHHmm");
|
||||
@@ -315,61 +315,63 @@ public class VoiceCloneServiceImpl extends BaseServiceImpl<VoiceCloneDao, VoiceC
|
||||
System.out.println(">>> HTTP status = " + response.statusCode());
|
||||
System.out.println(">>> response body = " + response.body());
|
||||
|
||||
if (response.statusCode() == 200) {
|
||||
Map<String, Object> rsp = objectMapper.readValue(response.body(),
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
Map<String, Object> rsp = objectMapper.readValue(response.body(),
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
// 获取BaseResp对象
|
||||
Map<String, Object> baseResp = objectMapper.convertValue(rsp.get("BaseResp"),
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
if (baseResp != null) {
|
||||
Integer statusCode = objectMapper.convertValue(baseResp.get("StatusCode"), Integer.class);
|
||||
String statusMessage = objectMapper.convertValue(baseResp.getOrDefault("StatusMessage", ""),
|
||||
String.class);
|
||||
// 获取BaseResp对象
|
||||
Map<String, Object> baseResp = objectMapper.convertValue(rsp.get("BaseResp"),
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
if (baseResp != null) {
|
||||
Integer statusCode = objectMapper.convertValue(baseResp.get("StatusCode"), Integer.class);
|
||||
String statusMessage = objectMapper.convertValue(baseResp.getOrDefault("StatusMessage", ""),
|
||||
String.class);
|
||||
|
||||
// 获取speaker_id
|
||||
String speakerId = objectMapper.convertValue(rsp.get("speaker_id"), String.class);
|
||||
// 获取speaker_id
|
||||
String speakerId = objectMapper.convertValue(rsp.get("speaker_id"), String.class);
|
||||
|
||||
// StatusCode == 0 表示成功
|
||||
if (statusCode != null && statusCode == 0 && StringUtils.isNotBlank(speakerId)) {
|
||||
entity.setTrainStatus(2);
|
||||
entity.setVoiceId(speakerId);
|
||||
entity.setTrainError("");
|
||||
baseDao.updateById(entity);
|
||||
|
||||
try {
|
||||
// 检查speaker_id是否已经被使用
|
||||
if (timbreService.existsByTtsVoice(speakerId)) {
|
||||
log.info("音色编码speaker_id[{}]已存在,不重复写入数据库", speakerId);
|
||||
} else {
|
||||
xiaozhi.modules.timbre.dto.TimbreDataDTO timbreDataDTO = new xiaozhi.modules.timbre.dto.TimbreDataDTO();
|
||||
timbreDataDTO.setTtsModelId(entity.getModelId());
|
||||
timbreDataDTO.setName(entity.getName());
|
||||
timbreDataDTO.setTtsVoice(speakerId);
|
||||
timbreDataDTO.setSort(1);
|
||||
timbreDataDTO.setLanguages("zh-CN");
|
||||
timbreDataDTO.setRemark("复刻音色");
|
||||
|
||||
// 保存到音色表
|
||||
timbreService.save(timbreDataDTO);
|
||||
log.info("成功将复刻音色添加到音色表,speaker_id: {}", speakerId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 记录错误但不影响主流程
|
||||
log.error("将复刻音色添加到音色表失败: " + e.getMessage(), e);
|
||||
// StatusCode == 0 表示成功
|
||||
if (statusCode != null && statusCode == 0 && StringUtils.isNotBlank(speakerId)) {
|
||||
entity.setTrainStatus(2);
|
||||
entity.setVoiceId(speakerId);
|
||||
entity.setTrainError("");
|
||||
baseDao.updateById(entity);
|
||||
|
||||
try {
|
||||
// 检查speaker_id是否已经被使用
|
||||
if (timbreService.existsByTtsVoice(speakerId)) {
|
||||
log.info("音色编码speaker_id[{}]已存在,不重复写入数据库", speakerId);
|
||||
} else {
|
||||
xiaozhi.modules.timbre.dto.TimbreDataDTO timbreDataDTO = new xiaozhi.modules.timbre.dto.TimbreDataDTO();
|
||||
timbreDataDTO.setTtsModelId(entity.getModelId());
|
||||
timbreDataDTO.setName(entity.getName());
|
||||
timbreDataDTO.setTtsVoice(speakerId);
|
||||
timbreDataDTO.setSort(1);
|
||||
timbreDataDTO.setLanguages("zh-CN");
|
||||
timbreDataDTO.setRemark("复刻音色");
|
||||
|
||||
// 保存到音色表
|
||||
timbreService.save(timbreDataDTO);
|
||||
log.info("成功将复刻音色添加到音色表,speaker_id: {}", speakerId);
|
||||
}
|
||||
} else {
|
||||
// 失败时使用StatusMessage作为错误信息
|
||||
String errorMsg = StringUtils.isNotBlank(statusMessage) ? statusMessage : "训练失败";
|
||||
throw new RenException(errorMsg);
|
||||
} catch (Exception e) {
|
||||
// 记录错误但不影响主流程
|
||||
log.error("将复刻音色添加到音色表失败: " + e.getMessage(), e);
|
||||
}
|
||||
} else {
|
||||
throw new RenException(ErrorCode.VOICE_CLONE_RESPONSE_FORMAT_ERROR);
|
||||
// 失败时使用StatusMessage作为错误信息
|
||||
String errorMsg = StringUtils.isNotBlank(statusMessage) ? statusMessage : "训练失败";
|
||||
throw new RenException(errorMsg);
|
||||
}
|
||||
} else {
|
||||
throw new RenException(ErrorCode.VOICE_CLONE_REQUEST_FAILED + ",状态码: " + response.statusCode());
|
||||
String errorMsg = objectMapper.convertValue(rsp.get("message"),
|
||||
new TypeReference<String>() {
|
||||
});
|
||||
if (StringUtils.isNotBlank(errorMsg)) {
|
||||
throw new RenException(errorMsg);
|
||||
}
|
||||
throw new RenException(ErrorCode.VOICE_CLONE_RESPONSE_FORMAT_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1021,7 +1021,7 @@ export default {
|
||||
'warning': 'Warning',
|
||||
'info': 'Info',
|
||||
'common.networkError': 'Network request failed',
|
||||
|
||||
|
||||
// SM2 Encryption
|
||||
'sm2.publicKeyNotConfigured': 'SM2 public key not configured, please contact administrator',
|
||||
'sm2.encryptionFailed': 'Password encryption failed',
|
||||
@@ -1112,5 +1112,5 @@ export default {
|
||||
'voiceClone.updateNameSuccess': 'Name updated successfully',
|
||||
'voiceClone.updateNameFailed': 'Failed to update name',
|
||||
'voiceClone.playFailed': 'Play failed',
|
||||
'voiceClone.Details': 'Details',
|
||||
'voiceClone.Details': 'Error Details',
|
||||
}
|
||||
@@ -466,7 +466,7 @@ export default {
|
||||
'chatHistory.downloadCurrentSession': '下载本会话聊天记录',
|
||||
'chatHistory.downloadCurrentWithPreviousSessions': '下载本会话及前20条会话聊天记录',
|
||||
'chatHistory.downloadLinkFailed': '获取下载链接失败',
|
||||
|
||||
|
||||
'cache.status': '缓存状态',
|
||||
'cache.cdnEnabled': 'CDN模式已启用',
|
||||
'cache.cdnDisabled': 'CDN模式已禁用',
|
||||
@@ -1021,7 +1021,7 @@ export default {
|
||||
'warning': '警告',
|
||||
'info': '提示',
|
||||
'common.networkError': '网络请求失败',
|
||||
|
||||
|
||||
// SM2加密相关错误消息
|
||||
'sm2.publicKeyNotConfigured': 'SM2公钥未配置,请联系管理员',
|
||||
'sm2.encryptionFailed': '密码加密失败',
|
||||
@@ -1112,5 +1112,5 @@ export default {
|
||||
'voiceClone.updateNameSuccess': '名称更新成功',
|
||||
'voiceClone.updateNameFailed': '名称更新失败',
|
||||
'voiceClone.playFailed': '播放失败',
|
||||
'voiceClone.Details': '详情',
|
||||
'voiceClone.Details': '错误详情',
|
||||
}
|
||||
@@ -16,7 +16,7 @@ export default {
|
||||
'header.paramDictionary': '參數字典',
|
||||
'header.paramManagement': '參數管理',
|
||||
'header.dictManagement': '字典管理',
|
||||
'header.agentTemplate': '預設角色模板',
|
||||
'header.agentTemplate': '預設角色模板',
|
||||
'header.searchHistory': '搜索歷史',
|
||||
'header.clearHistory': '清空歷史',
|
||||
'header.providerManagement': '字段管理',
|
||||
@@ -1112,5 +1112,5 @@ export default {
|
||||
'voiceClone.updateNameSuccess': '名稱更新成功',
|
||||
'voiceClone.updateNameFailed': '名稱更新失敗',
|
||||
'voiceClone.playFailed': '播放失敗',
|
||||
'voiceClone.Details': '詳情',
|
||||
'voiceClone.Details': '錯誤詳情',
|
||||
}
|
||||
@@ -41,17 +41,17 @@
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
|
||||
<el-table-column :label="$t('voiceClone.Details')" align="center" width="80">
|
||||
<template slot-scope="scope">
|
||||
<el-tooltip :content="getTooltipContent(scope.row)" placement="top">
|
||||
<el-button size="mini" type="text" icon="el-icon-info"
|
||||
<el-button size="mini" type="text" icon="el-icon-info"
|
||||
@click="handleViewDetails(scope.row)">
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
|
||||
<el-table-column :label="$t('voiceClone.action')" align="center" width="180">
|
||||
<template slot-scope="scope">
|
||||
<el-button v-if="scope.row.hasVoice" size="mini" type="text"
|
||||
@@ -189,73 +189,7 @@ export default {
|
||||
case 3:
|
||||
// 训练失败时,根据错误信息智能展示
|
||||
if (row.trainError) {
|
||||
const errorMsg = row.trainError;
|
||||
|
||||
// 火山引擎语音复刻业务错误码映射表
|
||||
const voiceCloneErrorMap = {
|
||||
'1001': '请求参数有误',
|
||||
'1101': '音频上传失败',
|
||||
'1102': 'ASR(语音识别成文字)转写失败',
|
||||
'1103': 'SID声纹检测失败',
|
||||
'1104': '声纹检测未通过,声纹跟名人相似度过高',
|
||||
'1105': '获取音频数据失败',
|
||||
'1106': 'SpeakerID重复',
|
||||
'1107': 'SpeakerID未找到',
|
||||
'1108': '音频转码失败',
|
||||
'1109': 'WER检测错误,上传音频与请求携带文本对比字错率过高',
|
||||
'1111': 'AED检测错误,通常由于音频不包含说话声',
|
||||
'1112': 'SNR检测错误,通常由于信噪比过高',
|
||||
'1113': '降噪处理失败',
|
||||
'1114': '音频质量低,降噪失败',
|
||||
'1122': '未检测到人声',
|
||||
'1123': '已达上传次数限制(同一个音色支持10次上传)'
|
||||
};
|
||||
|
||||
// HTTP 公共错误码映射表
|
||||
const httpErrorMap = {
|
||||
'400': '请求参数错误',
|
||||
'401': 'Access Key不合法或签名错误',
|
||||
'403': '权限不足',
|
||||
'404': '接口不存在',
|
||||
'429': '请求过于频繁',
|
||||
'500': '服务器内部错误',
|
||||
'502': '服务故障',
|
||||
'503': '服务暂时不可用',
|
||||
'504': '服务超时'
|
||||
};
|
||||
|
||||
// 匹配业务错误码
|
||||
const businessErrorMatch = errorMsg.match(/业务错误\s*(\d+):/);
|
||||
if (businessErrorMatch) {
|
||||
const code = businessErrorMatch[1];
|
||||
const desc = voiceCloneErrorMap[code] || errorMsg.split(':')[1]?.trim() || '未知错误';
|
||||
return `训练失败:${desc}\n(业务错误码 ${code})`;
|
||||
}
|
||||
|
||||
// 匹配旧格式的业务错误码
|
||||
for (const [code, desc] of Object.entries(voiceCloneErrorMap)) {
|
||||
if (errorMsg.includes(code)) {
|
||||
return `训练失败:${desc}\n(业务错误码 ${code})`;
|
||||
}
|
||||
}
|
||||
|
||||
// 匹配HTTP状态码
|
||||
const httpErrorMatch = errorMsg.match(/HTTP\s*(\d+)/);
|
||||
if (httpErrorMatch) {
|
||||
const code = httpErrorMatch[1];
|
||||
const desc = httpErrorMap[code] || '请求失败';
|
||||
// 提取完整的错误信息
|
||||
return `训练失败:${desc}\n(HTTP ${code})\n${errorMsg}`;
|
||||
}
|
||||
|
||||
// 匹配旧格式的HTTP状态码
|
||||
for (const [code, desc] of Object.entries(httpErrorMap)) {
|
||||
if (errorMsg.includes(`状态码: ${code}`) || errorMsg.includes(`状态码:${code}`)) {
|
||||
return `训练失败:${desc}\n(HTTP ${code})`;
|
||||
}
|
||||
}
|
||||
|
||||
return `训练失败:${errorMsg}`;
|
||||
return `训练失败:${row.trainError}`;
|
||||
}
|
||||
return '训练失败';
|
||||
default:
|
||||
@@ -354,7 +288,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
row._submitting = true;
|
||||
|
||||
|
||||
const params = {
|
||||
cloneId: row.id
|
||||
};
|
||||
@@ -384,7 +318,7 @@ export default {
|
||||
}, (error) => {
|
||||
// API调用失败,刷新列表以获取最新状态
|
||||
console.error('API调用失败:', error);
|
||||
this.$message.error('请求失败');
|
||||
this.$message.error('克隆失败,请将鼠标悬停在错误提示上,查看错误详情');
|
||||
this.fetchVoiceCloneList();
|
||||
row._submitting = false;
|
||||
});
|
||||
@@ -396,7 +330,7 @@ export default {
|
||||
row._submitting = false;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// 更新行状态并触发视图更新
|
||||
updateRowStatus(row, status, statusCode = null) {
|
||||
// 在Vue中直接修改数组中的对象属性可能不会触发视图更新
|
||||
@@ -404,12 +338,12 @@ export default {
|
||||
const updateData = {
|
||||
trainStatus: status
|
||||
};
|
||||
|
||||
|
||||
// 如果提供了状态码,也更新状态码信息
|
||||
if (statusCode !== null) {
|
||||
updateData.statusCode = statusCode;
|
||||
}
|
||||
|
||||
|
||||
if (index !== -1) {
|
||||
// 使用Vue.set来确保响应式更新
|
||||
this.$set(this.voiceCloneList, index, {
|
||||
|
||||
Reference in New Issue
Block a user