From d532a3fe28a00e19d71b609798e7a330e82e7eb5 Mon Sep 17 00:00:00 2001 From: Shijia Huang Date: Wed, 25 Mar 2026 21:02:43 +1100 Subject: [PATCH] fixed the bug --- backend/src/constants/prompts.ts | 2 +- miniprogram/packageB/pages/chat-room/index.ts | 52 +++++++++++++++---- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/backend/src/constants/prompts.ts b/backend/src/constants/prompts.ts index afcf7f3..8f59f12 100644 --- a/backend/src/constants/prompts.ts +++ b/backend/src/constants/prompts.ts @@ -39,7 +39,7 @@ export const JUDGMENT_SYSTEM_PROMPT = `你是"清汤大老爷",一位断案风 - 语气要像一个慈祥但毒舌的长辈 ### 4. 惩罚任务 (punishmentTask) -- 为责任占比较高的一方(败诉方)设计一个惩罚任务 +- 为责任占比较高的一方(败诉方)设计一个惩罚任务 Important:责任占比较高的一方为败诉方 - 任务要有趣但不过分,适合情侣/朋友之间互动 - 任务要具体可执行,10-20字左右 - 任务要结合双方争吵的内容,有针对性 diff --git a/miniprogram/packageB/pages/chat-room/index.ts b/miniprogram/packageB/pages/chat-room/index.ts index f181ed7..5a5f00c 100644 --- a/miniprogram/packageB/pages/chat-room/index.ts +++ b/miniprogram/packageB/pages/chat-room/index.ts @@ -117,7 +117,12 @@ interface IChatRoomCustomOption extends WechatMiniprogram.Page.CustomOption { currentSpeakerUserId: string; // UserId of current speaker isSelfFirstSpeaker: boolean; // Whether self is first speaker (SpeakerA) // ASR 完成后的待执行动作(用于确保录音结果先于控制消息发出) - pendingAfterAsrComplete: 'sendTurnEnd' | 'redirect' | null; + pendingAfterAsrComplete: + | 'sendTurnEnd' + | 'sendTurnEndAndNotify' + | 'showSwitchNotification' + | 'redirect' + | null; pendingAfterAsrCompleteTimerId: number | null; } @@ -677,6 +682,11 @@ Page({ this.pendingAfterAsrComplete = null; if (pending === 'sendTurnEnd') { this.sendSpeechTurnEnd(); + } else if (pending === 'sendTurnEndAndNotify') { + this.sendSpeechTurnEnd(); + void this.showSwitchNotification(); + } else if (pending === 'showSwitchNotification') { + void this.showSwitchNotification(); } else if (pending === 'redirect') { this.doRedirectToVerdictWaiting(); } @@ -857,17 +867,21 @@ Page({ // 根据当前阶段直接计算 liveKey(同步,无竞态问题) const liveKey: 'speakerALive' | 'speakerBLive' = phase === EPhase.SpeakerA ? 'speakerALive' : 'speakerBLive'; + const wasRecording: boolean = this.data.isRecording; - // 强制停止语音识别,并在 ASR 完成后发送控制消息(确保录音结果先到后端) - if (this.asrManager && this.data.isRecording) { + // 强制停止语音识别,并在 ASR 完成后发送控制消息并显示切换提示(确保录音结果先到后端) + if (this.asrManager && wasRecording) { if (canSpeak) { // 先设置 pending 再 stop,避免回调比赋值先到 - this.pendingAfterAsrComplete = 'sendTurnEnd'; - // 兜底:3 秒内 OnRecognitionComplete 未触发则直接发送 + this.pendingAfterAsrComplete = 'sendTurnEndAndNotify'; + // 兜底:3 秒内 OnRecognitionComplete 未触发则直接执行 this.pendingAfterAsrCompleteTimerId = setTimeout(() => { - if (this.pendingAfterAsrComplete === 'sendTurnEnd') { + if ( + this.pendingAfterAsrComplete === 'sendTurnEndAndNotify' + ) { this.pendingAfterAsrComplete = null; this.sendSpeechTurnEnd(); + void this.showSwitchNotification(); } this.pendingAfterAsrCompleteTimerId = null; }, 3000) as unknown as number; @@ -912,8 +926,12 @@ Page({ this.timerId = null; } - // 显示"下一位"切换提示 - this.showSwitchNotification(); + // 显示"下一位"切换提示(录音中则等 OnRecognitionComplete 确认最后一段文本已发出) + if (this.asrManager && wasRecording) { + // 已通过 pendingAfterAsrComplete = 'sendTurnEndAndNotify' 延迟触发 + } else { + void this.showSwitchNotification(); + } this.setData({ phase: nextPhase, @@ -980,8 +998,22 @@ Page({ const selfUserId: string = getApp().globalData.selfUserId; const nextCanSpeak: boolean = this.currentSpeakerUserId === selfUserId; - // 显示"下一位"切换提示 - this.showSwitchNotification(); + // 显示"下一位"切换提示(录音中则等 OnRecognitionComplete 确认最后一段文本已发出) + const wasRecording: boolean = this.data.isRecording; + if (this.asrManager && wasRecording) { + this.pendingAfterAsrComplete = 'showSwitchNotification'; + // 兜底:3 秒内 OnRecognitionComplete 未触发则直接显示 + this.pendingAfterAsrCompleteTimerId = setTimeout(() => { + if (this.pendingAfterAsrComplete === 'showSwitchNotification') { + this.pendingAfterAsrComplete = null; + void this.showSwitchNotification(); + } + this.pendingAfterAsrCompleteTimerId = null; + }, 3000) as unknown as number; + this.asrManager.stop(); + } else { + void this.showSwitchNotification(); + } this.setData({ phase: EPhase.SpeakerB,