From f6f3cd0bc4ec7357420055bcb0c649394eed41c0 Mon Sep 17 00:00:00 2001 From: Shijia Huang Date: Wed, 15 Apr 2026 20:43:15 +1000 Subject: [PATCH] fix some bugs --- .claude/settings.local.json | 5 +- miniprogram/packageB/pages/chat-room/index.ts | 118 +++++++++--------- 2 files changed, 61 insertions(+), 62 deletions(-) diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 60a2e4a..8ea00bb 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -14,7 +14,10 @@ "Bash(findstr:*)", "Bash(npx prettier:*)", "Bash(cd:*)", - "Bash(npm install:*)" + "Bash(npm install:*)", + "Bash(cat)", + "Read(//tmp/**)", + "Bash(xargs grep:*)" ] } } diff --git a/miniprogram/packageB/pages/chat-room/index.ts b/miniprogram/packageB/pages/chat-room/index.ts index 1cd17e8..8ae28b0 100644 --- a/miniprogram/packageB/pages/chat-room/index.ts +++ b/miniprogram/packageB/pages/chat-room/index.ts @@ -865,76 +865,72 @@ Page({ // 强制停止语音识别,并在 ASR 完成后发送控制消息并显示切换提示(确保录音结果先到后端) if (this.asrManager && wasRecording) { - // 强制停止语音识别,并在 ASR 完成后发送控制消息并显示切换提示(确保录音结果先到后端) - if (this.asrManager && wasRecording) { - if (canSpeak) { - this.stopAsrAndDefer('sendTurnEndAndNotify'); - } else { - this.asrManager.stop(); - } - } else if (canSpeak) { - // 未在录音,直接发送 - this.sendSpeechTurnEnd(); + if (canSpeak) { + this.stopAsrAndDefer('sendTurnEndAndNotify'); + } else { + this.asrManager.stop(); } + } else if (canSpeak) { + // 未在录音,直接发送 + this.sendSpeechTurnEnd(); + } - const nextPhase: EPhase = PHASE_TRANSITION[phase]; - - if (nextPhase === EPhase.Done) { - // 清理定时器 - if (this.timerId) { - clearInterval(this.timerId); - this.timerId = null; - } + const nextPhase: EPhase = PHASE_TRANSITION[phase]; - this.stopListenerHintRotation(); + if (nextPhase === EPhase.Done) { + // 清理定时器 + if (this.timerId) { + clearInterval(this.timerId); + this.timerId = null; + } - this.setData({ - phase: EPhase.Done, - canSpeak: false, - remaining: 0, - isRecording: false, - [liveKey]: '', // 仅清 live,final 保留 - }); - // 等待 CHAT_COMPLETE 消息触发跳转 - } else { - const phaseApp = getApp(); - // 第二发言人是非第一发言人的那一方 - this.currentSpeakerUserId = this.isSelfFirstSpeaker - ? phaseApp.globalData.opponentUserId - : phaseApp.globalData.selfUserId; - const nextCanSpeak: boolean = - this.currentSpeakerUserId === - phaseApp.globalData.selfUserId; - - // 不再发言时停止倒计时(由新发言者自行启动) - if (!nextCanSpeak && this.timerId) { - clearInterval(this.timerId); - this.timerId = null; - } + this.stopListenerHintRotation(); - // 显示"下一位"切换提示(录音中则等 OnRecognitionComplete 确认最后一段文本已发出) - if (!(this.asrManager && wasRecording)) { - void this.showSwitchNotification(); - } + this.setData({ + phase: EPhase.Done, + canSpeak: false, + remaining: 0, + isRecording: false, + [liveKey]: '', // 仅清 live,final 保留 + }); + // 等待 CHAT_COMPLETE 消息触发跳转 + } else { + const phaseApp = getApp(); + // 第二发言人是非第一发言人的那一方 + this.currentSpeakerUserId = this.isSelfFirstSpeaker + ? phaseApp.globalData.opponentUserId + : phaseApp.globalData.selfUserId; + const nextCanSpeak: boolean = + this.currentSpeakerUserId === phaseApp.globalData.selfUserId; + + // 不再发言时停止倒计时(由新发言者自行启动) + if (!nextCanSpeak && this.timerId) { + clearInterval(this.timerId); + this.timerId = null; + } - this.setData({ - phase: nextPhase, - remaining: totalPerTurn, - canSpeak: nextCanSpeak, - countdownClass: this.getCountdownClass(totalPerTurn), - isRecording: false, - [liveKey]: '', // 仅清结束阶段的 live - listenerHint: nextCanSpeak ? '' : this.pickListenerHint(), - }); + // 显示"下一位"切换提示(录音中则等 OnRecognitionComplete 确认最后一段文本已发出) + if (!(this.asrManager && wasRecording)) { + void this.showSwitchNotification(); + } - if (nextCanSpeak) { - this.stopListenerHintRotation(); - } else { - this.startListenerHintRotation(); - } + this.setData({ + phase: nextPhase, + remaining: totalPerTurn, + canSpeak: nextCanSpeak, + countdownClass: this.getCountdownClass(totalPerTurn), + isRecording: false, + [liveKey]: '', // 仅清结束阶段的 live + listenerHint: nextCanSpeak ? '' : this.pickListenerHint(), + }); - asrService.resetSequence(); + if (nextCanSpeak) { + this.stopListenerHintRotation(); + } else { + this.startListenerHintRotation(); } + + asrService.resetSequence(); } },