Skip to content

Commit 6773be4

Browse files
committed
fix: improve speech synthesis handling in ChatOperationButton
--bug=1058147 --user=刘瑞斌 【应用】简易应用-语音播放-浏览器播放-暂停播放后,再点击播放,无响应 https://www.tapd.cn/62980211/s/1727446
1 parent b2b144a commit 6773be4

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,15 @@ class AudioManage {
464464
if (window.speechSynthesis.paused) {
465465
window.speechSynthesis.resume()
466466
} else {
467-
if (window.speechSynthesis.pending) {
467+
// 如果不是暂停状态,取消当前播放并重新开始
468+
if (window.speechSynthesis.speaking) {
468469
window.speechSynthesis.cancel()
469470
}
470-
speechSynthesis.speak(audioElement)
471-
this.statusList[index] = AudioStatus.PLAY_INT
471+
// 等待取消完成后重新播放
472+
setTimeout(() => {
473+
speechSynthesis.speak(audioElement)
474+
this.statusList[index] = AudioStatus.PLAY_INT
475+
}, 100)
472476
}
473477
}
474478
}
@@ -489,11 +493,6 @@ class AudioManage {
489493
this.statusList[index] = AudioStatus.READY
490494
if (self) {
491495
window.speechSynthesis.pause()
492-
nextTick(() => {
493-
if (!window.speechSynthesis.paused) {
494-
window.speechSynthesis.cancel()
495-
}
496-
})
497496
} else {
498497
window.speechSynthesis.cancel()
499498
}

0 commit comments

Comments
 (0)