Skip to content

Commit 3710028

Browse files
committed
fix: improve speech synthesis handling in ChatOperationButton
--bug=1059740 --user=刘瑞斌 【github#3769】应用开启浏览器语音播放,在问答界面,暂停播放后,无法再次开启播放 https://www.tapd.cn/57709429/s/1744903
1 parent 2ff63d9 commit 3710028

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,22 @@ class AudioManage {
454454
this.statusList[index] = AudioStatus.ERROR
455455
}
456456
} else {
457-
if (window.speechSynthesis.paused) {
457+
if (window.speechSynthesis.paused && self) {
458458
window.speechSynthesis.resume()
459+
this.statusList[index] = AudioStatus.PLAY_INT
459460
} else {
460-
if (window.speechSynthesis.pending) {
461+
// 如果不是暂停状态,取消当前播放并重新开始
462+
if (window.speechSynthesis.speaking) {
461463
window.speechSynthesis.cancel()
462464
}
463-
speechSynthesis.speak(audioElement)
464-
this.statusList[index] = AudioStatus.PLAY_INT
465+
// 等待取消完成后重新播放
466+
setTimeout(() => {
467+
if (speechSynthesis.speaking) {
468+
return
469+
}
470+
speechSynthesis.speak(audioElement)
471+
this.statusList[index] = AudioStatus.PLAY_INT
472+
}, 500)
465473
}
466474
}
467475
}
@@ -482,11 +490,6 @@ class AudioManage {
482490
this.statusList[index] = AudioStatus.READY
483491
if (self) {
484492
window.speechSynthesis.pause()
485-
nextTick(() => {
486-
if (!window.speechSynthesis.paused) {
487-
window.speechSynthesis.cancel()
488-
}
489-
})
490493
} else {
491494
window.speechSynthesis.cancel()
492495
}

0 commit comments

Comments
 (0)