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