|
|
@ -144,6 +144,69 @@ const pauseAudio = () => { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
// 音频轮流播放方法 |
|
|
|
const playAudioSequence = (audioUrls) => { |
|
|
|
if (!audioUrls || audioUrls.length === 0) { |
|
|
|
console.warn("音频URL列表为空,跳过播放"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
let currentIndex = 0; |
|
|
|
|
|
|
|
const playNext = () => { |
|
|
|
if (currentIndex >= audioUrls.length) { |
|
|
|
console.log("所有音频播放完成"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const currentUrl = audioUrls[currentIndex]; |
|
|
|
console.log(`正在播放第${currentIndex + 1}个音频:`, currentUrl); |
|
|
|
|
|
|
|
// 停止当前播放的音频 |
|
|
|
if (audioStore.nowSound) { |
|
|
|
audioStore.nowSound.stop(); |
|
|
|
} |
|
|
|
|
|
|
|
const sound = new Howl({ |
|
|
|
src: [currentUrl], |
|
|
|
html5: true, |
|
|
|
format: ["mp3", "acc"], |
|
|
|
rate: 1.2, |
|
|
|
onplay: () => { |
|
|
|
audioStore.isPlaying = true; |
|
|
|
console.log(`开始播放音频 ${currentIndex + 1}`); |
|
|
|
}, |
|
|
|
onend: () => { |
|
|
|
audioStore.isPlaying = false; |
|
|
|
console.log(`音频 ${currentIndex + 1} 播放完成`); |
|
|
|
currentIndex++; |
|
|
|
// 播放下一个音频 |
|
|
|
setTimeout(() => { |
|
|
|
playNext(); |
|
|
|
}, 500); // 间隔500ms播放下一个 |
|
|
|
}, |
|
|
|
onstop: () => { |
|
|
|
audioStore.isPlaying = false; |
|
|
|
}, |
|
|
|
onloaderror: (id, err) => { |
|
|
|
console.error(`音频 ${currentIndex + 1} 加载失败:`, err); |
|
|
|
currentIndex++; |
|
|
|
// 跳过失败的音频,播放下一个 |
|
|
|
setTimeout(() => { |
|
|
|
playNext(); |
|
|
|
}, 100); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
audioStore.nowSound = sound; |
|
|
|
audioStore.setAudioInstance(sound); |
|
|
|
sound.play(); |
|
|
|
}; |
|
|
|
|
|
|
|
// 开始播放第一个音频 |
|
|
|
playNext(); |
|
|
|
}; |
|
|
|
|
|
|
|
// 获取消息 |
|
|
|
const chatMsg = computed(() => chatStore.messages); |
|
|
|
const props = defineProps({ |
|
|
@ -492,6 +555,18 @@ watch( |
|
|
|
const result23 = await dbqbSecondThreeAPI(params2); |
|
|
|
const result24 = await dbqbSecondFourAPI(params2); |
|
|
|
|
|
|
|
// 收集所有音频URL |
|
|
|
const audioUrls = []; |
|
|
|
if (result21.data.url) audioUrls.push(result21.data.url.trim()); |
|
|
|
if (result22.data.url) audioUrls.push(result22.data.url.trim()); |
|
|
|
if (result23.data.url) audioUrls.push(result23.data.url.trim()); |
|
|
|
if (result24.data.url) audioUrls.push(result24.data.url.trim()); |
|
|
|
|
|
|
|
// 开始轮流播放音频 |
|
|
|
if (audioUrls.length > 0 && audioStore.isVoiceEnabled) { |
|
|
|
playAudioSequence(audioUrls); |
|
|
|
} |
|
|
|
|
|
|
|
const katexRegex = /\$\$(.*?)\$\$/g; |
|
|
|
// 删除正在为您生成信息 |
|
|
|
chatStore.messages.pop(); |
|
|
|