Merge branch 'main' of https://github.com/xinnan-tech/xiaozhi-esp32-server into Knowledge-Base

This commit is contained in:
rainv123
2025-11-17 18:34:03 +08:00
5 changed files with 665 additions and 174 deletions
@@ -19,4 +19,15 @@ public class VoiceDTO implements Serializable {
@Schema(description = "音色名称")
private String name;
@Schema(description = "音频播放地址")
private String voiceDemo;
// 添加双参数构造函数,保持向后兼容
public VoiceDTO(String id, String name) {
this.id = id;
this.name = name;
this.voiceDemo = null;
}
}
@@ -133,7 +133,11 @@ public class TimbreServiceImpl extends BaseServiceImpl<TimbreDao, TimbreEntity>
timbreEntities = new ArrayList<>();
}
List<VoiceDTO> voiceDTOs = timbreEntities.stream()
.map(entity -> new VoiceDTO(entity.getId(), entity.getName()))
.map(entity -> {
VoiceDTO dto = new VoiceDTO(entity.getId(), entity.getName());
dto.setVoiceDemo(entity.getVoiceDemo());
return dto;
})
.collect(Collectors.toList());
// 获取当前登录用户ID
@@ -146,6 +150,8 @@ public class TimbreServiceImpl extends BaseServiceImpl<TimbreDao, TimbreEntity>
VoiceDTO voiceDTO = new VoiceDTO();
voiceDTO.setId(entity.getId());
voiceDTO.setName(MessageUtils.getMessage(ErrorCode.VOICE_CLONE_PREFIX) + entity.getName());
// 保留从数据库查询到的voiceDemo字段
voiceDTO.setVoiceDemo(entity.getVoiceDemo());
redisUtils.set(RedisKeys.getTimbreNameById(voiceDTO.getId()), voiceDTO.getName(),
RedisUtils.NOT_EXPIRE);
voiceDTOs.add(0, voiceDTO);
@@ -205,6 +211,9 @@ public class TimbreServiceImpl extends BaseServiceImpl<TimbreDao, TimbreEntity>
if (list.isEmpty()) {
return null;
}
return new VoiceDTO(list.get(0).getId(), list.get(0).getName());
TimbreEntity entity = list.get(0);
VoiceDTO dto = new VoiceDTO(entity.getId(), entity.getName());
dto.setVoiceDemo(entity.getVoiceDemo());
return dto;
}
}
@@ -164,6 +164,9 @@ public class VoiceCloneServiceImpl extends BaseServiceImpl<VoiceCloneDao, VoiceC
if (entity.getUserId() != null) {
dto.setUserName(sysUserService.getByUserId(entity.getUserId()).getUsername());
}
// 确保trainStatus字段被正确设置,前端需要这个字段来判断是否为克隆音频
dto.setTrainStatus(entity.getTrainStatus());
return dto;
}
@@ -197,6 +200,9 @@ public class VoiceCloneServiceImpl extends BaseServiceImpl<VoiceCloneDao, VoiceC
if (entity.getUserId() != null) {
dto.setUserName(sysUserService.getByUserId(entity.getUserId()).getUsername());
}
// 确保trainStatus字段被正确设置,前端需要这个字段来判断是否为克隆音频
dto.setTrainStatus(entity.getTrainStatus());
// 设置是否有音频数据
dto.setHasVoice(entity.getVoice() != null);
@@ -3,7 +3,7 @@
<mapper namespace="xiaozhi.modules.voiceclone.dao.VoiceCloneDao">
<select id="getTrainSuccess" resultType="xiaozhi.modules.model.dto.VoiceDTO">
select id, name
select id, name, voice_id as voiceDemo
from ai_voice_clone
where model_id = #{modelId} and user_id = #{userId} and train_status = 2
</select>
File diff suppressed because it is too large Load Diff