|
| 1 | +/** |
| 2 | + * RecognitionStatsBar — 识别统计条(P0-7) |
| 3 | + * |
| 4 | + * @ai-context: 识别过程可见性(UX-F 基础):会话中实时展示识别引擎徽标、 |
| 5 | + * 已捕捉关键帧数、已转写句数、VAD 语音状态。数据全部来自既有会话状态 |
| 6 | + * (smartBundle.keyframes / transcribedCount / vadStats),纯展示零逻辑, |
| 7 | + * 不引入新订阅。 |
| 8 | + * @ai-context EN: Live recognition status bar: engine badge (local streaming / |
| 9 | + * local segment / cloud), captured keyframes, transcribed segments, and VAD |
| 10 | + * voice state. Pure presentation over existing session state. |
| 11 | + */ |
| 12 | +import { Cpu, Camera, Mic, Activity } from 'lucide-react'; |
| 13 | +import type { SessionStatus } from '@/lib/capture'; |
| 14 | +import type { VADStats } from '@/lib/capture/vadMarker'; |
| 15 | + |
| 16 | +interface RecognitionStatsBarProps { |
| 17 | + status: SessionStatus; |
| 18 | + keyframeCount: number; |
| 19 | + transcribedCount: number; |
| 20 | + vadStats: VADStats | null; |
| 21 | + /** 真流式 ASR 激活(smart 路径 Zipformer 在线识别) */ |
| 22 | + streamingAsrActive: boolean; |
| 23 | + /** 本地 ASR 引擎就绪(否则转写走云端) */ |
| 24 | + localAsrReady: boolean; |
| 25 | +} |
| 26 | + |
| 27 | +/** 引擎徽标文案与配色(本地流式 > 本地按段 > 云端) */ |
| 28 | +function engineBadge(streamingAsrActive: boolean, localAsrReady: boolean): { label: string; cls: string } { |
| 29 | + if (streamingAsrActive) { |
| 30 | + return { label: '本地流式', cls: 'text-emerald-600 bg-emerald-500/10' }; |
| 31 | + } |
| 32 | + if (localAsrReady) { |
| 33 | + return { label: '本地按段', cls: 'text-emerald-600 bg-emerald-500/10' }; |
| 34 | + } |
| 35 | + return { label: '云端转写', cls: 'text-accent-600 bg-accent-500/10' }; |
| 36 | +} |
| 37 | + |
| 38 | +/** VAD 语音状态:最近 2s 内有语音活动视为「语音中」(vadStats 5s 粒度) */ |
| 39 | +function vadVoiceState(vadStats: VADStats | null): { label: string; speaking: boolean } { |
| 40 | + if (!vadStats) return { label: '—', speaking: false }; |
| 41 | + const recent = Date.now() - vadStats.lastVoiceTimestamp < 2000; |
| 42 | + return recent ? { label: '语音中', speaking: true } : { label: '静默', speaking: false }; |
| 43 | +} |
| 44 | + |
| 45 | +export function RecognitionStatsBar({ |
| 46 | + status, keyframeCount, transcribedCount, vadStats, streamingAsrActive, localAsrReady, |
| 47 | +}: RecognitionStatsBarProps) { |
| 48 | + const engine = engineBadge(streamingAsrActive, localAsrReady); |
| 49 | + const voice = vadVoiceState(vadStats); |
| 50 | + |
| 51 | + return ( |
| 52 | + <div className="mx-4 mt-2 flex items-center gap-3 px-3 py-1.5 rounded-kb-md bg-bg-elevated/40 border border-border/20 text-[11px] text-text-tertiary flex-wrap"> |
| 53 | + <span className="flex items-center gap-1"> |
| 54 | + <Cpu className="w-3 h-3" strokeWidth={1.5} /> |
| 55 | + 识别引擎 |
| 56 | + <span className={`px-1.5 py-0.5 rounded-kb-sm font-medium ${engine.cls}`}>{engine.label}</span> |
| 57 | + </span> |
| 58 | + <span className="flex items-center gap-1"> |
| 59 | + <Camera className="w-3 h-3" strokeWidth={1.5} /> |
| 60 | + 已捕捉 <strong className="text-text-secondary">{keyframeCount}</strong> 帧 |
| 61 | + </span> |
| 62 | + <span className="flex items-center gap-1"> |
| 63 | + <Mic className="w-3 h-3" strokeWidth={1.5} /> |
| 64 | + 已转写 <strong className="text-text-secondary">{transcribedCount}</strong> 句 |
| 65 | + </span> |
| 66 | + <span className="flex items-center gap-1"> |
| 67 | + <Activity className={`w-3 h-3 ${voice.speaking ? 'text-emerald-500' : ''}`} strokeWidth={1.5} /> |
| 68 | + {status === 'capturing' ? voice.label : '已停止'} |
| 69 | + </span> |
| 70 | + </div> |
| 71 | + ); |
| 72 | +} |
| 73 | + |
| 74 | +export default RecognitionStatsBar; |
0 commit comments