Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/src/constants/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const JUDGMENT_SYSTEM_PROMPT = `你是"清汤大老爷",一位断案风
- 语气要像一个慈祥但毒舌的长辈

### 4. 惩罚任务 (punishmentTask)
- 为责任占比较高的一方(败诉方)设计一个惩罚任务
- 为责任占比较高的一方(败诉方)设计一个惩罚任务 Important:责任占比较高的一方为败诉方
- 任务要有趣但不过分,适合情侣/朋友之间互动
- 任务要具体可执行,10-20字左右
- 任务要结合双方争吵的内容,有针对性
Expand Down
52 changes: 42 additions & 10 deletions miniprogram/packageB/pages/chat-room/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -677,6 +682,11 @@ Page<IChatRoomPageData, IChatRoomCustomOption>({
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();
}
Expand Down Expand Up @@ -857,17 +867,21 @@ Page<IChatRoomPageData, IChatRoomCustomOption>({
// 根据当前阶段直接计算 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;
Expand Down Expand Up @@ -912,8 +926,12 @@ Page<IChatRoomPageData, IChatRoomCustomOption>({
this.timerId = null;
}

// 显示"下一位"切换提示
this.showSwitchNotification();
// 显示"下一位"切换提示(录音中则等 OnRecognitionComplete 确认最后一段文本已发出)
if (this.asrManager && wasRecording) {
// 已通过 pendingAfterAsrComplete = 'sendTurnEndAndNotify' 延迟触发
} else {
void this.showSwitchNotification();
}

this.setData({
phase: nextPhase,
Expand Down Expand Up @@ -980,8 +998,22 @@ Page<IChatRoomPageData, IChatRoomCustomOption>({
const selfUserId: string = getApp<IAppOption>().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,
Expand Down
Loading