From eb5e2cd4e112311bf52107b71477744190a81cb8 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Mon, 24 Feb 2025 17:35:28 +0800 Subject: [PATCH] fix: Fix browser text to speech cannot resume and cancel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1052345 --user=刘瑞斌 【github#2352】【应用】使用浏览器内置TTS,切换历史记录内容播放会没有声音 https://www.tapd.cn/57709429/s/1657771 --- .../component/operation-button/ChatOperationButton.vue | 2 +- .../component/operation-button/LogOperationButton.vue | 2 +- ui/src/views/chat/pc/index.vue | 8 ++++++++ 3 files changed, 10 insertions(+), 2 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 fe2d91a4943..e633c850a53 100644 --- a/ui/src/components/ai-chat/component/operation-button/ChatOperationButton.vue +++ b/ui/src/components/ai-chat/component/operation-button/ChatOperationButton.vue @@ -200,7 +200,7 @@ const playAnswerTextPart = () => { if (audioList.value[currentAudioIndex.value] !== utterance.value?.text) { window.speechSynthesis.cancel() } - if (window.speechSynthesis.paused) { + if (window.speechSynthesis.paused && audioList.value[currentAudioIndex.value] === utterance.value?.text) { window.speechSynthesis.resume() return } diff --git a/ui/src/components/ai-chat/component/operation-button/LogOperationButton.vue b/ui/src/components/ai-chat/component/operation-button/LogOperationButton.vue index 03772952b2d..71120c97484 100644 --- a/ui/src/components/ai-chat/component/operation-button/LogOperationButton.vue +++ b/ui/src/components/ai-chat/component/operation-button/LogOperationButton.vue @@ -176,7 +176,7 @@ const playAnswerTextPart = () => { if (audioList.value[currentAudioIndex.value] !== utterance.value?.text) { window.speechSynthesis.cancel() } - if (window.speechSynthesis.paused) { + if (window.speechSynthesis.paused && audioList.value[currentAudioIndex.value] === utterance.value?.text) { window.speechSynthesis.resume() return } diff --git a/ui/src/views/chat/pc/index.vue b/ui/src/views/chat/pc/index.vue index ba4338ed1ef..e201a0fbcc4 100644 --- a/ui/src/views/chat/pc/index.vue +++ b/ui/src/views/chat/pc/index.vue @@ -321,6 +321,14 @@ const clickListHandle = (item: any) => { currentChatName.value = item.abstract if (currentChatId.value !== 'new') { getChatRecord() + + // 切换对话后,取消暂停的浏览器播放 + if (window.speechSynthesis.paused && window.speechSynthesis.speaking) { + window.speechSynthesis.resume() + nextTick(() => { + window.speechSynthesis.cancel() + }) + } } } if (common.isMobile()) {