|
|
@@ -105,7 +105,7 @@ import { marked } from 'marked'
|
|
|
import {CreateDialogue, sendChatMessageStream} from "@/api/questions.js";
|
|
|
import {useAudioPlayer} from "@/api/tts/useAudioPlayer.js";
|
|
|
|
|
|
-const { playAudioChunk , stopPlayback } = useAudioPlayer();
|
|
|
+const { playAudioChunk , stopPlayback, setOnPlaybackComplete } = useAudioPlayer();
|
|
|
|
|
|
// 路由实例
|
|
|
const router = useRouter()
|
|
|
@@ -135,8 +135,6 @@ const currentSectionIndex = ref(0)
|
|
|
const currentDialogueIndex = ref(0)
|
|
|
// 是否正在播放
|
|
|
const isPlaying = ref(false)
|
|
|
-// 用户输入前是否正在播放(用于AI回答完成后继续播放)
|
|
|
-const wasPlayingBeforeUserInput = ref(false)
|
|
|
// 用户输入内容
|
|
|
const userInput = ref('')
|
|
|
// 语音录音状态
|
|
|
@@ -363,7 +361,6 @@ const playSequence = async () => {
|
|
|
|
|
|
// 如果当前是用户输入卡片,暂停播放等待用户输入
|
|
|
if (currentDialogue.value?.type === 'user') {
|
|
|
- wasPlayingBeforeUserInput.value = true
|
|
|
return
|
|
|
}
|
|
|
|
|
|
@@ -542,7 +539,6 @@ const recoverQuestDialogue = () => {
|
|
|
}
|
|
|
// 清空缓存
|
|
|
currentDialogueCache.value = null
|
|
|
- userInputCache.value = ''
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -571,7 +567,6 @@ const doSendMessageStream = async userMessage => {
|
|
|
const { code, data, msg } = JSON.parse(res.data)
|
|
|
if (code !== 0) {
|
|
|
console.log(`对话异常! ${msg}`)
|
|
|
- // recoverQuestDialogue();
|
|
|
stopStream();
|
|
|
return
|
|
|
}
|
|
|
@@ -611,7 +606,6 @@ const doSendMessageStream = async userMessage => {
|
|
|
)
|
|
|
} catch (error) {
|
|
|
console.error('发送消息失败:', error)
|
|
|
- // recoverQuestDialogue();
|
|
|
stopStream()
|
|
|
}
|
|
|
}
|
|
|
@@ -628,20 +622,19 @@ const stopStream = async () => {
|
|
|
conversationInProgress.value = false
|
|
|
|
|
|
console.log(`结束对话!更改状态: `,conversationInProgress.value)
|
|
|
+}
|
|
|
|
|
|
+// 处理音频播放完成
|
|
|
+const handleAudioPlaybackComplete = () => {
|
|
|
+ console.log('智能问答音频播放完成');
|
|
|
// AI回答完成后,如果之前是播放状态,继续播放
|
|
|
- if (wasPlayingBeforeUserInput.value) {
|
|
|
- wasPlayingBeforeUserInput.value = false
|
|
|
- // 跳到下一个对话并继续播放
|
|
|
- if (playNext()) {
|
|
|
- playSequence()
|
|
|
- } else {
|
|
|
- // 播放完毕
|
|
|
- isPlaying.value = false
|
|
|
- stopAllAudio()
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
+
|
|
|
+ stopAllAudio();
|
|
|
+ // // playNext()
|
|
|
+ // if (isPlaying.value) {
|
|
|
+ // playNext()
|
|
|
+ // }
|
|
|
+};
|
|
|
|
|
|
// 组件挂载时添加键盘事件监听
|
|
|
onMounted(() => {
|
|
|
@@ -650,6 +643,8 @@ onMounted(() => {
|
|
|
playBackgroundAudio()
|
|
|
// 播放当前对话语音
|
|
|
playDialogueAudio()
|
|
|
+ // 设置音频播放完成回调
|
|
|
+ setOnPlaybackComplete(handleAudioPlaybackComplete)
|
|
|
})
|
|
|
|
|
|
// 组件卸载时移除键盘事件监听和停止音频
|