From 6773be4fe3a408ee687b04c6efd1cd666c863420 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Thu, 10 Jul 2025 11:15:01 +0800 Subject: [PATCH] fix: improve speech synthesis handling in ChatOperationButton MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1058147 --user=刘瑞斌 【应用】简易应用-语音播放-浏览器播放-暂停播放后,再点击播放,无响应 https://www.tapd.cn/62980211/s/1727446 --- .../operation-button/ChatOperationButton.vue | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/ui/src/components/ai-chat/component/operation-button/ChatOperationButton.vue b/ui/src/components/ai-chat/component/operation-button/ChatOperationButton.vue index ed5f20efa..149b9cd93 100644 --- a/ui/src/components/ai-chat/component/operation-button/ChatOperationButton.vue +++ b/ui/src/components/ai-chat/component/operation-button/ChatOperationButton.vue @@ -464,11 +464,15 @@ class AudioManage { if (window.speechSynthesis.paused) { window.speechSynthesis.resume() } else { - if (window.speechSynthesis.pending) { + // 如果不是暂停状态,取消当前播放并重新开始 + if (window.speechSynthesis.speaking) { window.speechSynthesis.cancel() } - speechSynthesis.speak(audioElement) - this.statusList[index] = AudioStatus.PLAY_INT + // 等待取消完成后重新播放 + setTimeout(() => { + speechSynthesis.speak(audioElement) + this.statusList[index] = AudioStatus.PLAY_INT + }, 100) } } } @@ -489,11 +493,6 @@ class AudioManage { this.statusList[index] = AudioStatus.READY if (self) { window.speechSynthesis.pause() - nextTick(() => { - if (!window.speechSynthesis.paused) { - window.speechSynthesis.cancel() - } - }) } else { window.speechSynthesis.cancel() }