mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
修复播放按钮的显示错误
This commit is contained in:
@@ -22,12 +22,24 @@ public class VoiceDTO implements Serializable {
|
||||
|
||||
@Schema(description = "音频播放地址")
|
||||
private String voiceDemo;
|
||||
|
||||
@Schema(description = "是否为克隆音色")
|
||||
private Boolean isClone;
|
||||
|
||||
// 添加双参数构造函数,保持向后兼容
|
||||
public VoiceDTO(String id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.voiceDemo = null;
|
||||
this.isClone = false; // 默认不是克隆音色
|
||||
}
|
||||
|
||||
// 添加三参数构造函数,用于普通音色
|
||||
public VoiceDTO(String id, String name, String voiceDemo) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.voiceDemo = voiceDemo;
|
||||
this.isClone = false;
|
||||
}
|
||||
|
||||
}
|
||||
+3
@@ -136,6 +136,7 @@ public class TimbreServiceImpl extends BaseServiceImpl<TimbreDao, TimbreEntity>
|
||||
.map(entity -> {
|
||||
VoiceDTO dto = new VoiceDTO(entity.getId(), entity.getName());
|
||||
dto.setVoiceDemo(entity.getVoiceDemo());
|
||||
dto.setIsClone(false); // 设置为普通音色
|
||||
return dto;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
@@ -152,6 +153,7 @@ public class TimbreServiceImpl extends BaseServiceImpl<TimbreDao, TimbreEntity>
|
||||
voiceDTO.setName(MessageUtils.getMessage(ErrorCode.VOICE_CLONE_PREFIX) + entity.getName());
|
||||
// 保留从数据库查询到的voiceDemo字段
|
||||
voiceDTO.setVoiceDemo(entity.getVoiceDemo());
|
||||
voiceDTO.setIsClone(true); // 设置为克隆音色
|
||||
redisUtils.set(RedisKeys.getTimbreNameById(voiceDTO.getId()), voiceDTO.getName(),
|
||||
RedisUtils.NOT_EXPIRE);
|
||||
voiceDTOs.add(0, voiceDTO);
|
||||
@@ -214,6 +216,7 @@ public class TimbreServiceImpl extends BaseServiceImpl<TimbreDao, TimbreEntity>
|
||||
TimbreEntity entity = list.get(0);
|
||||
VoiceDTO dto = new VoiceDTO(entity.getId(), entity.getName());
|
||||
dto.setVoiceDemo(entity.getVoiceDemo());
|
||||
dto.setIsClone(false); // 设置为普通音色
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
@@ -746,32 +746,17 @@ export default {
|
||||
},
|
||||
// 检查是否有音频预览
|
||||
hasAudioPreview(item) {
|
||||
// 检查item中是否包含有效的音频URL字段或克隆音频字段
|
||||
// 克隆音频通过hasCloneAudio标志或ID格式判断(非TTS开头的ID)
|
||||
const isCloneAudio =
|
||||
item.hasCloneAudio || (item.value && !item.value.startsWith("TTS"));
|
||||
|
||||
const audioFields = [
|
||||
item.voiceDemo,
|
||||
item.demoUrl,
|
||||
item.audioUrl,
|
||||
item.voice_demo,
|
||||
item.sample_voice,
|
||||
item.referenceAudio,
|
||||
item.cloneAudioUrl, // 克隆音频的URL
|
||||
];
|
||||
|
||||
// 检查是否有任何音频字段是有效的URL
|
||||
const hasUrlAudio = audioFields.some(
|
||||
(field) =>
|
||||
field !== undefined &&
|
||||
field !== null &&
|
||||
typeof field === "string" &&
|
||||
field.trim() !== "" &&
|
||||
field.toLowerCase().startsWith("http")
|
||||
);
|
||||
|
||||
return hasUrlAudio || isCloneAudio;
|
||||
// 使用新增的isClone字段来判断是否为克隆音色
|
||||
const isCloneAudio = item.isClone === true;
|
||||
|
||||
// 普通音色的音频检查:同时检查voiceDemo和voice_demo两种命名格式
|
||||
const audioField = item.voice_demo || item.voiceDemo;
|
||||
const hasManualAudio = audioField &&
|
||||
typeof audioField === "string" &&
|
||||
audioField.trim() !== "" &&
|
||||
audioField.toLowerCase().startsWith("http");
|
||||
|
||||
return isCloneAudio || hasManualAudio;
|
||||
},
|
||||
|
||||
// 播放/暂停音频切换
|
||||
|
||||
Reference in New Issue
Block a user