Skip to content

Commit 5eec0f7

Browse files
committed
fix: Fix browser text to speech cannot resume and cancel
--bug=1052345 --user=刘瑞斌 【github#2352】【应用】使用浏览器内置TTS,切换历史记录内容播放会没有声音 https://www.tapd.cn/57709429/s/1657771
1 parent 76e6b6e commit 5eec0f7

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

ui/src/components/ai-chat/component/operation-button/ChatOperationButton.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ const playAnswerTextPart = () => {
200200
if (audioList.value[currentAudioIndex.value] !== utterance.value?.text) {
201201
window.speechSynthesis.cancel()
202202
}
203-
if (window.speechSynthesis.paused) {
203+
if (window.speechSynthesis.paused && audioList.value[currentAudioIndex.value] === utterance.value?.text) {
204204
window.speechSynthesis.resume()
205205
return
206206
}

ui/src/components/ai-chat/component/operation-button/LogOperationButton.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ const playAnswerTextPart = () => {
176176
if (audioList.value[currentAudioIndex.value] !== utterance.value?.text) {
177177
window.speechSynthesis.cancel()
178178
}
179-
if (window.speechSynthesis.paused) {
179+
if (window.speechSynthesis.paused && audioList.value[currentAudioIndex.value] === utterance.value?.text) {
180180
window.speechSynthesis.resume()
181181
return
182182
}

ui/src/views/chat/pc/index.vue

+8
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ const clickListHandle = (item: any) => {
321321
currentChatName.value = item.abstract
322322
if (currentChatId.value !== 'new') {
323323
getChatRecord()
324+
325+
// 切换对话后,取消暂停的浏览器播放
326+
if (window.speechSynthesis.paused && window.speechSynthesis.speaking) {
327+
window.speechSynthesis.resume()
328+
nextTick(() => {
329+
window.speechSynthesis.cancel()
330+
})
331+
}
324332
}
325333
}
326334
if (common.isMobile()) {

0 commit comments

Comments
 (0)