mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 17:43:55 +08:00
补充
This commit is contained in:
+6
@@ -164,6 +164,9 @@ public class VoiceCloneServiceImpl extends BaseServiceImpl<VoiceCloneDao, VoiceC
|
|||||||
if (entity.getUserId() != null) {
|
if (entity.getUserId() != null) {
|
||||||
dto.setUserName(sysUserService.getByUserId(entity.getUserId()).getUsername());
|
dto.setUserName(sysUserService.getByUserId(entity.getUserId()).getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 确保trainStatus字段被正确设置,前端需要这个字段来判断是否为克隆音频
|
||||||
|
dto.setTrainStatus(entity.getTrainStatus());
|
||||||
|
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
@@ -197,6 +200,9 @@ public class VoiceCloneServiceImpl extends BaseServiceImpl<VoiceCloneDao, VoiceC
|
|||||||
if (entity.getUserId() != null) {
|
if (entity.getUserId() != null) {
|
||||||
dto.setUserName(sysUserService.getByUserId(entity.getUserId()).getUsername());
|
dto.setUserName(sysUserService.getByUserId(entity.getUserId()).getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 确保trainStatus字段被正确设置,前端需要这个字段来判断是否为克隆音频
|
||||||
|
dto.setTrainStatus(entity.getTrainStatus());
|
||||||
|
|
||||||
// 设置是否有音频数据
|
// 设置是否有音频数据
|
||||||
dto.setHasVoice(entity.getVoice() != null);
|
dto.setHasVoice(entity.getVoice() != null);
|
||||||
|
|||||||
@@ -580,7 +580,9 @@ export default {
|
|||||||
referenceAudio: voice.referenceAudio,
|
referenceAudio: voice.referenceAudio,
|
||||||
// 新增:添加克隆音频相关字段
|
// 新增:添加克隆音频相关字段
|
||||||
cloneAudioUrl: voice.cloneAudioUrl,
|
cloneAudioUrl: voice.cloneAudioUrl,
|
||||||
hasCloneAudio: voice.hasCloneAudio || false
|
hasCloneAudio: voice.hasCloneAudio || false,
|
||||||
|
// 保存训练状态字段,用于判断是否为克隆音频
|
||||||
|
train_status: voice.trainStatus,
|
||||||
}));
|
}));
|
||||||
// 保存完整的音色信息,添加调试信息
|
// 保存完整的音色信息,添加调试信息
|
||||||
console.log("获取到的音色数据:", data.data);
|
console.log("获取到的音色数据:", data.data);
|
||||||
@@ -702,31 +704,33 @@ export default {
|
|||||||
},
|
},
|
||||||
// 检查是否有音频预览
|
// 检查是否有音频预览
|
||||||
hasAudioPreview(item) {
|
hasAudioPreview(item) {
|
||||||
// 检查item中是否包含有效的音频URL字段或克隆音频字段
|
// 检查item中是否包含有效的音频URL字段或克隆音频字段
|
||||||
// 克隆音频通过hasCloneAudio标志或特定格式的ID来判断
|
// 克隆音频通过hasCloneAudio标志或特定格式的ID来判断
|
||||||
const isCloneAudio = item.hasCloneAudio ||
|
const isCloneAudio =
|
||||||
(item.id && item.id.startsWith('e') && item.id.length === 14);
|
item.hasCloneAudio ||
|
||||||
|
(item.id && item.id.startsWith("e") && item.id.length === 14);
|
||||||
const audioFields = [
|
|
||||||
item.voiceDemo,
|
const audioFields = [
|
||||||
item.demoUrl,
|
item.voiceDemo,
|
||||||
item.audioUrl,
|
item.demoUrl,
|
||||||
item.voice_demo,
|
item.audioUrl,
|
||||||
item.sample_voice,
|
item.voice_demo,
|
||||||
item.referenceAudio,
|
item.sample_voice,
|
||||||
item.cloneAudioUrl // 克隆音频的URL
|
item.referenceAudio,
|
||||||
];
|
item.cloneAudioUrl, // 克隆音频的URL
|
||||||
|
];
|
||||||
// 检查是否有任何音频字段是有效的URL
|
|
||||||
const hasUrlAudio = audioFields.some(field =>
|
// 检查是否有任何音频字段是有效的URL
|
||||||
field !== undefined &&
|
const hasUrlAudio = audioFields.some(
|
||||||
field !== null &&
|
(field) =>
|
||||||
typeof field === "string" &&
|
field !== undefined &&
|
||||||
|
field !== null &&
|
||||||
|
typeof field === "string" &&
|
||||||
field.trim() !== "" &&
|
field.trim() !== "" &&
|
||||||
field.toLowerCase().startsWith("http")
|
field.toLowerCase().startsWith("http")
|
||||||
);
|
);
|
||||||
|
|
||||||
return hasUrlAudio || isCloneAudio;
|
return hasUrlAudio || isCloneAudio;
|
||||||
},
|
},
|
||||||
|
|
||||||
// 播放/暂停音频切换
|
// 播放/暂停音频切换
|
||||||
@@ -783,12 +787,17 @@ export default {
|
|||||||
// 尝试多种可能的音频属性名
|
// 尝试多种可能的音频属性名
|
||||||
let audioUrl = null;
|
let audioUrl = null;
|
||||||
let isCloneAudio = false;
|
let isCloneAudio = false;
|
||||||
|
|
||||||
if (voiceDetail) {
|
if (voiceDetail) {
|
||||||
// 首先检查是否是克隆音频(通过ID格式或hasCloneAudio标志判断)
|
// 首先检查是否是克隆音频(通过train_status字段、hasCloneAudio标志或ID格式判断)
|
||||||
isCloneAudio = voiceDetail.hasCloneAudio ||
|
isCloneAudio =
|
||||||
(voiceDetail.id && voiceDetail.id.startsWith('e') && voiceDetail.id.length === 14);
|
(voiceDetail.train_status !== undefined && voiceDetail.train_status >= 0) ||
|
||||||
|
voiceDetail.hasCloneAudio ||
|
||||||
|
(voiceDetail.id &&
|
||||||
|
voiceDetail.id.startsWith("e") &&
|
||||||
|
voiceDetail.id.length === 14);
|
||||||
|
console.log("克隆音频判断结果:", isCloneAudio, "训练状态:", voiceDetail.train_status);
|
||||||
|
|
||||||
// 获取音频URL
|
// 获取音频URL
|
||||||
if (isCloneAudio && voiceDetail.id) {
|
if (isCloneAudio && voiceDetail.id) {
|
||||||
// 对于克隆音频,使用后端提供的正确接口
|
// 对于克隆音频,使用后端提供的正确接口
|
||||||
@@ -797,14 +806,14 @@ export default {
|
|||||||
// 2. 然后使用这个ID构建播放URL
|
// 2. 然后使用这个ID构建播放URL
|
||||||
// 由于异步操作,我们需要先请求getAudioId
|
// 由于异步操作,我们需要先请求getAudioId
|
||||||
console.log("检测到克隆音频,准备获取音频URL:", voiceDetail.id);
|
console.log("检测到克隆音频,准备获取音频URL:", voiceDetail.id);
|
||||||
|
|
||||||
// 创建一个Promise来处理异步获取音频URL的操作
|
// 创建一个Promise来处理异步获取音频URL的操作
|
||||||
const getCloneAudioUrl = () => {
|
const getCloneAudioUrl = () => {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
// 首先调用getAudioId接口获取临时UUID
|
// 首先调用getAudioId接口获取临时UUID
|
||||||
RequestService.sendRequest()
|
RequestService.sendRequest()
|
||||||
.url(`${getServiceUrl()}/voiceClone/audio/${voiceDetail.id}`)
|
.url(`${getServiceUrl()}/voiceClone/audio/${voiceDetail.id}`)
|
||||||
.method('POST')
|
.method("POST")
|
||||||
.success((res) => {
|
.success((res) => {
|
||||||
if (res.code === 0 && res.data) {
|
if (res.code === 0 && res.data) {
|
||||||
// 使用返回的UUID构建播放URL
|
// 使用返回的UUID构建播放URL
|
||||||
@@ -823,14 +832,14 @@ export default {
|
|||||||
.send();
|
.send();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 设置播放状态
|
// 设置播放状态
|
||||||
this.playingVoice = true;
|
this.playingVoice = true;
|
||||||
// 创建Audio实例
|
// 创建Audio实例
|
||||||
this.currentAudio = new Audio();
|
this.currentAudio = new Audio();
|
||||||
// 设置音量
|
// 设置音量
|
||||||
this.currentAudio.volume = 1.0;
|
this.currentAudio.volume = 1.0;
|
||||||
|
|
||||||
// 设置超时,防止加载过长时间
|
// 设置超时,防止加载过长时间
|
||||||
const timeoutId = setTimeout(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
if (this.currentAudio && this.playingVoice) {
|
if (this.currentAudio && this.playingVoice) {
|
||||||
@@ -838,7 +847,7 @@ export default {
|
|||||||
this.playingVoice = false;
|
this.playingVoice = false;
|
||||||
}
|
}
|
||||||
}, 10000); // 10秒超时
|
}, 10000); // 10秒超时
|
||||||
|
|
||||||
// 监听播放错误
|
// 监听播放错误
|
||||||
this.currentAudio.onerror = () => {
|
this.currentAudio.onerror = () => {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
@@ -846,17 +855,17 @@ export default {
|
|||||||
this.$message.warning("克隆音频播放失败");
|
this.$message.warning("克隆音频播放失败");
|
||||||
this.playingVoice = false;
|
this.playingVoice = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 监听播放开始,清除超时
|
// 监听播放开始,清除超时
|
||||||
this.currentAudio.onplay = () => {
|
this.currentAudio.onplay = () => {
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 监听播放结束
|
// 监听播放结束
|
||||||
this.currentAudio.onended = () => {
|
this.currentAudio.onended = () => {
|
||||||
this.playingVoice = false;
|
this.playingVoice = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 处理异步获取URL并播放
|
// 处理异步获取URL并播放
|
||||||
getCloneAudioUrl().then((url) => {
|
getCloneAudioUrl().then((url) => {
|
||||||
if (url) {
|
if (url) {
|
||||||
@@ -874,7 +883,7 @@ export default {
|
|||||||
this.playingVoice = false;
|
this.playingVoice = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 返回,避免继续执行下面的普通音频播放逻辑
|
// 返回,避免继续执行下面的普通音频播放逻辑
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@@ -922,7 +931,7 @@ export default {
|
|||||||
// 创建并播放音频
|
// 创建并播放音频
|
||||||
this.currentAudio = new Audio();
|
this.currentAudio = new Audio();
|
||||||
this.currentAudio.src = audioUrl;
|
this.currentAudio.src = audioUrl;
|
||||||
|
|
||||||
// 设置音量
|
// 设置音量
|
||||||
this.currentAudio.volume = 1.0;
|
this.currentAudio.volume = 1.0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user