-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchitecture.drawio
More file actions
915 lines (915 loc) · 96.6 KB
/
architecture.drawio
File metadata and controls
915 lines (915 loc) · 96.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
<mxfile host="65bd71144e">
<diagram id="overall" name="1-整体系统架构">
<mxGraphModel dx="466" dy="899" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1600" pageHeight="1200" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="title" value="家庭情绪交互系统 - 整体架构" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=24;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="600" y="20" width="400" height="40" as="geometry"/>
</mxCell>
<mxCell id="device_layer" value="设备层" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=16;fontStyle=1;verticalAlign=top;" parent="1" vertex="1">
<mxGeometry x="80" y="100" width="280" height="400" as="geometry"/>
</mxCell>
<mxCell id="esp32" value="ESP32-S3 手环

✓ 音频采集 (16kHz PCM)
✓ WebSocket 客户端
✓ 振动反馈 (5级强度)
✓ LED 指示" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=12;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="110" y="150" width="220" height="120" as="geometry"/>
</mxCell>
<mxCell id="device_flow" value="设备工作流程:
1. 连接 WiFi
2. WebSocket 握手
3. 发送 start_session
4. 实时发送音频流
5. 接收振动指令
6. 发送 end_session" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="110" y="300" width="220" height="140" as="geometry"/>
</mxCell>
<mxCell id="backend_layer" value="后端服务层 (FastAPI)" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=16;fontStyle=1;verticalAlign=top;" parent="1" vertex="1">
<mxGeometry x="400" y="100" width="520" height="900" as="geometry"/>
</mxCell>
<mxCell id="ws_module" value="WebSocket 服务
/ws" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=13;fontStyle=1;" parent="1" vertex="1">
<mxGeometry x="430" y="150" width="200" height="50" as="geometry"/>
</mxCell>
<mxCell id="realtime_box" value="实时处理模块" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;fontStyle=1;verticalAlign=top;dashed=1;" parent="1" vertex="1">
<mxGeometry x="430" y="220" width="220" height="240" as="geometry"/>
</mxCell>
<mxCell id="tencent_asr" value="腾讯云实时 ASR

✓ 实时语音识别
✓ 连接池管理
✓ 错误重连" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="450" y="250" width="180" height="80" as="geometry"/>
</mxCell>
<mxCell id="keyword_detect" value="关键词检测

14个有害词汇
快速匹配" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="450" y="345" width="180" height="50" as="geometry"/>
</mxCell>
<mxCell id="llm_detect" value="LLM 语义检测

Gemma 2 27B
深度语义理解
严重程度评级 (1-5)" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="450" y="405" width="180" height="85" as="geometry"/>
</mxCell>
<mxCell id="session_mgr" value="会话管理器

✓ 创建/结束会话
✓ 计数有害语句
✓ 数据库操作" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="430" y="490" width="220" height="90" as="geometry"/>
</mxCell>
<mxCell id="audio_writer" value="音频写入器

✓ 实时写入 WAV 文件
✓ PCM 格式转换
✓ 文件管理" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="430" y="600" width="220" height="90" as="geometry"/>
</mxCell>
<mxCell id="offline_box" value="离线处理模块" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;fontStyle=1;verticalAlign=top;dashed=1;" parent="1" vertex="1">
<mxGeometry x="430" y="710" width="220" height="200" as="geometry"/>
</mxCell>
<mxCell id="cos_uploader" value="COS 上传器

✓ 腾讯云对象存储
✓ 预签名 URL
✓ 私有读写" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="450" y="740" width="180" height="70" as="geometry"/>
</mxCell>
<mxCell id="offline_asr" value="离线 ASR 处理

✓ 录音文件识别
✓ 说话人分离 (A/B)
✓ LLM 批量检测" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="450" y="825" width="180" height="75" as="geometry"/>
</mxCell>
<mxCell id="api_box" value="REST API" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;fontStyle=1;verticalAlign=top;dashed=1;" parent="1" vertex="1">
<mxGeometry x="680" y="150" width="220" height="300" as="geometry"/>
</mxCell>
<mxCell id="auth_api" value="认证 API
/api/auth/*

✓ 用户注册/登录
✓ JWT 令牌生成
✓ 密码加密 (bcrypt)" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="700" y="180" width="180" height="90" as="geometry"/>
</mxCell>
<mxCell id="session_api" value="会话 API
/api/sessions/*

✓ 获取会话列表
✓ 获取会话详情
✓ 查询 utterances" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="700" y="285" width="180" height="80" as="geometry"/>
</mxCell>
<mxCell id="upload_api" value="上传 API
/api/audio/*

✓ 音频文件上传
✓ 处理状态查询
✓ 异步处理" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="700" y="380" width="180" height="80" as="geometry"/>
</mxCell>
<mxCell id="frontend_layer" value="前端界面层 (React + Vite)" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=16;fontStyle=1;verticalAlign=top;" parent="1" vertex="1">
<mxGeometry x="960" y="100" width="560" height="550" as="geometry"/>
</mxCell>
<mxCell id="login_page" value="登录页面

✓ 用户认证
✓ Token 存储
✓ 路由保护" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=12;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="990" y="150" width="240" height="100" as="geometry"/>
</mxCell>
<mxCell id="sessions_page" value="会话列表页

✓ 显示所有会话
✓ 有害语句计数
✓ 时间/设备筛选
✓ 导航到详情" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=12;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="1260" y="150" width="240" height="110" as="geometry"/>
</mxCell>
<mxCell id="detail_page" value="会话详情页

✓ 完整对话记录
✓ 说话人区分 (A/B)
✓ 有害语句高亮
✓ 时间轴显示" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=12;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="990" y="280" width="240" height="110" as="geometry"/>
</mxCell>
<mxCell id="upload_page" value="音频上传页

✓ 文件选择/拖拽
✓ 上传进度显示
✓ 处理状态轮询
✓ 结果展示" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=12;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="1260" y="280" width="240" height="110" as="geometry"/>
</mxCell>
<mxCell id="router" value="React Router

路由管理:
• /login - 登录
• /sessions - 列表
• /sessions/:id - 详情
• /upload - 上传" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="990" y="420" width="510" height="100" as="geometry"/>
</mxCell>
<mxCell id="api_client" value="API 客户端 (fetch)

✓ 统一请求封装
✓ Bearer Token 注入
✓ 错误处理
✓ 自动重试" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="990" y="540" width="510" height="90" as="geometry"/>
</mxCell>
<mxCell id="db_layer" value="数据库层 (SQLite + SQLModel)" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=16;fontStyle=1;verticalAlign=top;" parent="1" vertex="1">
<mxGeometry x="960" y="690" width="560" height="310" as="geometry"/>
</mxCell>
<mxCell id="users_table" value="users 表

• id (主键)
• username (唯一)
• email (唯一)
• hashed_password
• full_name
• is_active / is_admin
• created_at" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="990" y="730" width="230" height="140" as="geometry"/>
</mxCell>
<mxCell id="sessions_table" value="sessions 表

• session_id (主键)
• device_id
• start_time / end_time
• audio_path
• harmful_count" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="1260" y="730" width="240" height="110" as="geometry"/>
</mxCell>
<mxCell id="utterances_table" value="utterances 表

• id (主键)
• session_id (外键)
• start / end (时间戳)
• speaker (A/B)
• text
• harmful_flag" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="990" y="890" width="510" height="90" as="geometry"/>
</mxCell>
<mxCell id="cloud_layer" value="云服务层" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=16;fontStyle=1;verticalAlign=top;" parent="1" vertex="1">
<mxGeometry x="80" y="550" width="280" height="450" as="geometry"/>
</mxCell>
<mxCell id="tencent_cloud" value="腾讯云服务" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14;fontStyle=1;" parent="1" vertex="1">
<mxGeometry x="110" y="600" width="220" height="40" as="geometry"/>
</mxCell>
<mxCell id="tencent_realtime" value="实时语音识别 (ASR)

✓ WebSocket 接口
✓ 16kHz PCM 输入
✓ 实时文本输出" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="110" y="655" width="220" height="80" as="geometry"/>
</mxCell>
<mxCell id="tencent_offline" value="录音文件识别

✓ 支持多种格式
✓ 说话人分离
✓ 高精度识别" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="110" y="750" width="220" height="75" as="geometry"/>
</mxCell>
<mxCell id="tencent_cos" value="对象存储 (COS)

✓ 音频文件存储
✓ 预签名 URL
✓ 私有读写权限" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="110" y="840" width="220" height="75" as="geometry"/>
</mxCell>
<mxCell id="openrouter" value="OpenRouter LLM

Model: Gemma 2 27B

✓ 语义理解
✓ 有害语检测
✓ 严重程度评级" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="110" y="930" width="220" height="90" as="geometry"/>
</mxCell>
<mxCell id="arrow1" value="WebSocket
音频流" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.25;entryX=0;entryY=0.25;strokeWidth=2;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" source="esp32" target="ws_module" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="arrow2" value="振动指令" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.75;entryX=1;entryY=0.75;strokeWidth=2;fillColor=#f8cecc;strokeColor=#b85450;dashed=1;" parent="1" source="ws_module" target="esp32" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="arrow3" value="HTTP
请求" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.5;entryX=1;entryY=0.5;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" source="api_client" target="api_box" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="940" y="585" as="sourcePoint"/>
<mxPoint x="920" y="300" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="arrow4" value="ASR 调用" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.5;entryX=1;entryY=0.25;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;dashed=1;" parent="1" source="tencent_asr" target="tencent_realtime" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="arrow5" value="LLM 调用" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.5;entryX=1;entryY=0.5;strokeWidth=2;fillColor=#ffe6cc;strokeColor=#d79b00;dashed=1;" parent="1" source="llm_detect" target="openrouter" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="380" y="448"/>
<mxPoint x="380" y="975"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="arrow6" value="COS 上传" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.5;entryX=1;entryY=0.5;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;dashed=1;" parent="1" source="cos_uploader" target="tencent_cos" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="arrow7" value="离线 ASR" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=0;exitY=0.5;entryX=1;entryY=0.75;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;dashed=1;" parent="1" source="offline_asr" target="tencent_offline" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="arrow8" value="数据库操作" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=1;entryX=0;entryY=0.5;strokeWidth=2;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" source="session_mgr" target="sessions_table" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="660" y="580"/>
<mxPoint x="660" y="640"/>
<mxPoint x="940" y="640"/>
<mxPoint x="940" y="785"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="note1" value="说明:
• 实线箭头:数据流向
• 虚线箭头:API 调用
• 颜色区分:不同功能模块" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=10;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="1320" y="20" width="200" height="80" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
<diagram id="realtime_flow" name="2-实时检测流程">
<mxGraphModel dx="1434" dy="843" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1600" pageHeight="1200" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="title2" value="实时音频处理与有害语检测流程" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=24;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="500" y="20" width="600" height="40" as="geometry"/>
</mxCell>
<!-- Flow Steps -->
<mxCell id="step1" value="1. 设备连接" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="100" y="100" width="200" height="50" as="geometry"/>
</mxCell>
<mxCell id="step1_detail" value="ESP32-S3 建立 WebSocket 连接
ws://backend:8000/ws" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;align=left;spacingLeft=10;" vertex="1" parent="1">
<mxGeometry x="350" y="100" width="300" height="50" as="geometry"/>
</mxCell>
<mxCell id="step2" value="2. 开始会话" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="100" y="180" width="200" height="50" as="geometry"/>
</mxCell>
<mxCell id="step2_detail" value="发送消息:
{ "type": "start_session", "device_id": "band001" }

后端响应:
• 创建 session 记录 (数据库)
• 初始化 AudioWriter (准备写入 WAV)
• 连接腾讯云实时 ASR
• 返回 session_id" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;align=left;spacingLeft=10;" vertex="1" parent="1">
<mxGeometry x="350" y="170" width="450" height="110" as="geometry"/>
</mxCell>
<mxCell id="step3" value="3. 音频流传输" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="100" y="310" width="200" height="50" as="geometry"/>
</mxCell>
<mxCell id="step3_detail" value="设备持续发送音频二进制数据:
• 格式:PCM, 16kHz, 16-bit, 单声道
• 分块大小:约 3200 字节 (0.1秒)

后端处理:
• AudioWriter: 写入本地 WAV 文件
• TencentASR: 发送到腾讯云实时识别" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;align=left;spacingLeft=10;" vertex="1" parent="1">
<mxGeometry x="350" y="295" width="450" height="120" as="geometry"/>
</mxCell>
<mxCell id="step4" value="4. ASR 识别" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="100" y="450" width="200" height="50" as="geometry"/>
</mxCell>
<mxCell id="step4_detail" value="腾讯云实时 ASR 返回结果:
{
 "text": "你怎么这么笨",
 "is_final": true
}

后端处理:
• 只处理 is_final=true 的结果
• 进入有害语检测流程" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;align=left;spacingLeft=10;fontFamily=Courier New;" vertex="1" parent="1">
<mxGeometry x="350" y="430" width="450" height="140" as="geometry"/>
</mxCell>
<mxCell id="step5" value="5. 双层检测" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=14;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="100" y="600" width="200" height="50" as="geometry"/>
</mxCell>
<mxCell id="step5_box" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=none;strokeColor=#b85450;fontSize=11;dashed=1;strokeWidth=2;" vertex="1" parent="1">
<mxGeometry x="350" y="585" width="1150" height="240" as="geometry"/>
</mxCell>
<!-- Layer 1: Keyword Detection -->
<mxCell id="layer1_title" value="第一层:关键词快速检测" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=13;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="370" y="600" width="250" height="30" as="geometry"/>
</mxCell>
<mxCell id="layer1_keywords" value="14个有害关键词:
没用、废物、滚出去、闭嘴、讨厌你、
后悔生你、打死你、蠢、笨蛋、白痴、
傻子、去死、滚、混蛋" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=11;align=left;spacingLeft=10;" vertex="1" parent="1">
<mxGeometry x="370" y="635" width="300" height="70" as="geometry"/>
</mxCell>
<mxCell id="layer1_code" value="def is_harmful(text):
 for keyword in HARMFUL_KEYWORDS:
 if keyword in text:
 return True
 return False" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=10;align=left;spacingLeft=10;fontFamily=Courier New;" vertex="1" parent="1">
<mxGeometry x="370" y="720" width="300" height="80" as="geometry"/>
</mxCell>
<!-- Layer 2: LLM Detection -->
<mxCell id="layer2_title" value="第二层:LLM 深度语义检测" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=13;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="710" y="600" width="250" height="30" as="geometry"/>
</mxCell>
<mxCell id="layer2_llm" value="使用 OpenRouter API
Model: google/gemma-2-27b-it

Prompt: 分析以下家长对孩子说的话
是否有害...

返回 JSON:
{
 "is_harmful": true,
 "severity": 4,
 "category": "贬低",
 "explanation": "..."
}" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=10;align=left;spacingLeft=10;fontFamily=Courier New;" vertex="1" parent="1">
<mxGeometry x="710" y="635" width="270" height="165" as="geometry"/>
</mxCell>
<!-- Detection Result -->
<mxCell id="result_box" value="检测结果汇总" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=12;fontStyle=1;verticalAlign=top;" vertex="1" parent="1">
<mxGeometry x="1020" y="620" width="460" height="180" as="geometry"/>
</mxCell>
<mxCell id="result_logic" value="if keyword_harmful OR llm_harmful:
 harmful_count += 1
 
 # 确定振动强度
 vibration_pattern = min(llm_severity, 5)
 
 # 发送振动指令
 websocket.send_json({
 "type": "vibrate",
 "pattern": vibration_pattern,
 "text": text,
 "severity": llm_severity,
 "category": llm_category
 })" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=10;align=left;spacingLeft=10;fontFamily=Courier New;" vertex="1" parent="1">
<mxGeometry x="1040" y="650" width="420" height="140" as="geometry"/>
</mxCell>
<mxCell id="step6" value="6. 振动反馈" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=14;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="100" y="860" width="200" height="50" as="geometry"/>
</mxCell>
<mxCell id="step6_detail" value="设备接收振动指令:
{
 "type": "vibrate",
 "pattern": 4,
 "text": "你怎么这么笨",
 "severity": 4,
 "category": "贬低"
}

设备执行:
• 根据 pattern (1-5) 决定振动强度和时长
• LED 指示灯闪烁
• 可选:震动模式差异化 (单次/连续/长短组合)" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;align=left;spacingLeft=10;fontFamily=Courier New;" vertex="1" parent="1">
<mxGeometry x="350" y="835" width="500" height="200" as="geometry"/>
</mxCell>
<mxCell id="vibration_levels" value="振动强度说明:

Level 1: 轻微提醒 (100ms)
Level 2: 中等提醒 (200ms)
Level 3: 明显提醒 (300ms, 2次)
Level 4: 强烈提醒 (400ms, 3次)
Level 5: 最强提醒 (500ms, 连续)" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=11;align=left;spacingLeft=10;" vertex="1" parent="1">
<mxGeometry x="900" y="865" width="300" height="140" as="geometry"/>
</mxCell>
<mxCell id="step7" value="7. 结束会话" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="100" y="1070" width="200" height="50" as="geometry"/>
</mxCell>
<mxCell id="step7_detail" value="设备发送结束消息:
{ "type": "end_session" }

后端处理:
• AudioWriter: 关闭并保存 WAV 文件
• SessionManager: 更新 session 记录
 - end_time = 当前时间
 - audio_path = 本地文件路径
 - harmful_count = 统计结果
• 断开腾讯云 ASR 连接
• 触发离线处理任务 (异步)" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;align=left;spacingLeft=10;fontFamily=Courier New;" vertex="1" parent="1">
<mxGeometry x="350" y="1045" width="500" height="180" as="geometry"/>
</mxCell>
<!-- Flow Arrows -->
<mxCell id="flow1" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=3;fillColor=#dae8fc;strokeColor=#6c8ebf;" edge="1" parent="1" source="step1" target="step2">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="flow2" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=3;fillColor=#dae8fc;strokeColor=#6c8ebf;" edge="1" parent="1" source="step2" target="step3">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="flow3" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=3;fillColor=#d5e8d4;strokeColor=#82b366;" edge="1" parent="1" source="step3" target="step4">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="flow4" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=3;fillColor=#f8cecc;strokeColor=#b85450;" edge="1" parent="1" source="step4" target="step5">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="flow5" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=3;fillColor=#f8cecc;strokeColor=#b85450;" edge="1" parent="1" source="step5" target="step6">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="flow6" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=3;fillColor=#dae8fc;strokeColor=#6c8ebf;" edge="1" parent="1" source="step6" target="step7">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="loop_arrow" value="循环处理" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;dashed=1;" edge="1" parent="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="50" y="335" as="sourcePoint"/>
<mxPoint x="50" y="925" as="targetPoint"/>
<Array as="points">
<mxPoint x="50" y="335"/>
<mxPoint x="50" y="925"/>
</Array>
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
</diagram>
<diagram id="offline_flow" name="3-离线处理流程">
<mxGraphModel dx="466" dy="899" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1600" pageHeight="1200" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="title3" value="离线音频处理与分析流程" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=24;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="550" y="20" width="500" height="40" as="geometry"/>
</mxCell>
<mxCell id="trigger_box" value="触发方式" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=14;fontStyle=1;verticalAlign=top;" parent="1" vertex="1">
<mxGeometry x="100" y="100" width="600" height="120" as="geometry"/>
</mxCell>
<mxCell id="trigger1" value="方式 1: 会话结束触发
WebSocket 会话结束时自动触发" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="130" y="140" width="250" height="60" as="geometry"/>
</mxCell>
<mxCell id="trigger2" value="方式 2: 手动上传音频
用户通过 Web 界面上传文件" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="420" y="140" width="250" height="60" as="geometry"/>
</mxCell>
<mxCell id="offline_step1" value="步骤 1: 文件准备" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=14;fontStyle=1;" parent="1" vertex="1">
<mxGeometry x="100" y="260" width="250" height="50" as="geometry"/>
</mxCell>
<mxCell id="offline_step1_detail" value="本地音频文件:
• 路径:./data/audio/uploads/{uuid}_{timestamp}.wav
• 格式:WAV, PCM, 16kHz, 单声道

检查文件:
• 验证文件存在性
• 检查文件大小 (< 100MB)
• 验证音频格式" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="400" y="250" width="400" height="130" as="geometry"/>
</mxCell>
<mxCell id="offline_step2" value="步骤 2: 上传到 COS" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1;" parent="1" vertex="1">
<mxGeometry x="100" y="420" width="250" height="50" as="geometry"/>
</mxCell>
<mxCell id="offline_step2_detail" value="腾讯云对象存储 (COS):

配置:
• Region: ap-guangzhou
• Bucket: info-tech-test-1314143047
• 权限:私有读写

上传过程:
cos_client = CosS3Client(config)
cos_client.put_object(
 Bucket=bucket,
 Key=f'audio/{session_id}.wav',
 Body=audio_file
)

生成访问 URL:
• 使用预签名 URL (有效期 1小时)
• 私密访问,安全性高" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=10;align=left;spacingLeft=10;fontFamily=Courier New;" parent="1" vertex="1">
<mxGeometry x="400" y="405" width="500" height="260" as="geometry"/>
</mxCell>
<mxCell id="offline_step3" value="步骤 3: 录音文件识别" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1;" parent="1" vertex="1">
<mxGeometry x="100" y="710" width="250" height="50" as="geometry"/>
</mxCell>
<mxCell id="offline_step3_detail" value="腾讯云录音文件识别 API:

请求参数:
{
 "EngineModelType": "16k_zh",
 "ChannelNum": 1,
 "ResTextFormat": 0,
 "SourceType": 0,
 "Url": cos_url,
 "SpeakerDiarization": 1, // 开启说话人分离
 "SpeakerNumber": 2 // 2个说话人 (家长+孩子)
}

处理流程:
1. 提交任务 → 获取 TaskId
2. 轮询状态 (每5秒查询一次)
3. 等待识别完成 (通常 1-5分钟)
4. 获取完整结果" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=10;align=left;spacingLeft=10;fontFamily=Courier New;" parent="1" vertex="1">
<mxGeometry x="400" y="690" width="550" height="250" as="geometry"/>
</mxCell>
<mxCell id="offline_step4" value="步骤 4: 解析结果" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=14;fontStyle=1;" parent="1" vertex="1">
<mxGeometry x="100" y="980" width="250" height="50" as="geometry"/>
</mxCell>
<mxCell id="offline_step4_detail" value="ASR 返回结果示例:
{
 "Result": [
 {
 "speaker_id": "0",
 "start": 0.0,
 "end": 2.5,
 "text": "你今天作业做完了吗"
 },
 {
 "speaker_id": "1",
 "start": 2.5,
 "end": 3.8,
 "text": "还没有"
 },
 {
 "speaker_id": "0",
 "start": 3.8,
 "end": 5.5,
 "text": "你怎么这么笨"
 }
 ]
}" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=10;align=left;spacingLeft=10;fontFamily=Courier New;" parent="1" vertex="1">
<mxGeometry x="400" y="970" width="400" height="280" as="geometry"/>
</mxCell>
<mxCell id="speaker_mapping" value="说话人映射:

speaker_id "0" → Speaker A (家长)
speaker_id "1" → Speaker B (孩子)

说明:
• 实际应用中可能需要更多上下文
 判断哪个是家长
• 可通过声纹识别进一步优化
• 或者让用户手动标注" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="850" y="1000" width="350" height="160" as="geometry"/>
</mxCell>
<mxCell id="offline_step5" value="步骤 5: 批量有害语检测" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=14;fontStyle=1;" parent="1" vertex="1">
<mxGeometry x="1250" y="690" width="280" height="50" as="geometry"/>
</mxCell>
<mxCell id="offline_step5_detail" value="对每条 utterance 进行检测:

for utterance in results:
 text = utterance['text']
 
 # 关键词检测
 keyword_harmful = is_harmful(text)
 
 # LLM 检测 (批量处理优化)
 llm_result = await llm_detector.detect(text)
 
 # 记录结果
 if keyword_harmful or llm_result['is_harmful']:
 utterance['harmful_flag'] = True
 harmful_count += 1
 else:
 utterance['harmful_flag'] = False

优化策略:
• 批量调用 LLM (减少 API 调用次数)
• 并发处理 (asyncio.gather)
• 缓存相似结果" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=10;align=left;spacingLeft=10;fontFamily=Courier New;" parent="1" vertex="1">
<mxGeometry x="1030" y="420" width="500" height="320" as="geometry"/>
</mxCell>
<mxCell id="offline_step6" value="步骤 6: 保存到数据库" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=14;fontStyle=1;" parent="1" vertex="1">
<mxGeometry x="1250" y="800" width="280" height="50" as="geometry"/>
</mxCell>
<mxCell id="offline_step6_detail" value="数据库操作:

1. 更新 sessions 表:
 UPDATE sessions
 SET harmful_count = ?,
 audio_path = ?,
 end_time = ?
 WHERE session_id = ?

2. 插入 utterances 表:
 for utterance in results:
 INSERT INTO utterances
 (session_id, start, end, speaker, 
 text, harmful_flag)
 VALUES (?, ?, ?, ?, ?, ?)

事务处理:
• 使用数据库事务保证原子性
• 失败时回滚,保证数据一致性" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=10;align=left;spacingLeft=10;fontFamily=Courier New;" parent="1" vertex="1">
<mxGeometry x="1250" y="880" width="450" height="270" as="geometry"/>
</mxCell>
<mxCell id="offline_step7" value="步骤 7: 前端展示" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=14;fontStyle=1;" parent="1" vertex="1">
<mxGeometry x="100" y="1300" width="250" height="50" as="geometry"/>
</mxCell>
<mxCell id="offline_step7_detail" value="用户在 Web 界面查看结果:

1. 会话列表页:
 • 显示所有会话
 • 有害语句数量标记
 • 时间排序

2. 会话详情页:
 • 完整对话时间轴
 • 说话人标识 (A/B)
 • 有害语句红色高亮
 • 每句话的时间戳
 • 可播放原始音频 (如果有)" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="400" y="1275" width="450" height="180" as="geometry"/>
</mxCell>
<mxCell id="example_ui" value="前端显示示例:

┌─────────────────────────────┐
│ 会话详情 - Session ABC123 │
├─────────────────────────────┤
│ 00:00 [A] 你今天作业做完了吗? │
│ 00:03 [B] 还没有... │
│ 00:05 [A] 你怎么这么笨 ⚠️ │
│ 00:08 [B] 对不起... │
└─────────────────────────────┘

⚠️ = 有害语句标记" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=10;align=left;spacingLeft=10;fontFamily=Courier New;" parent="1" vertex="1">
<mxGeometry x="900" y="1290" width="350" height="200" as="geometry"/>
</mxCell>
<mxCell id="offline_flow1" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=3;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" source="trigger_box" target="offline_step1" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="offline_flow2" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=3;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" source="offline_step1" target="offline_step2" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="offline_flow3" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=3;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" source="offline_step2" target="offline_step3" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="offline_flow4" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=3;fillColor=#ffe6cc;strokeColor=#d79b00;" parent="1" source="offline_step3" target="offline_step4" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="offline_flow5" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=3;fillColor=#f8cecc;strokeColor=#b85450;" parent="1" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="800" y="805" as="sourcePoint"/>
<mxPoint x="1250" y="715" as="targetPoint"/>
<Array as="points">
<mxPoint x="1000" y="805"/>
<mxPoint x="1000" y="715"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="offline_flow6" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=3;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" source="offline_step5" target="offline_step6" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="offline_flow7" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=3;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" edge="1">
<mxGeometry relative="1" as="geometry">
<mxPoint x="800" y="1120" as="sourcePoint"/>
<mxPoint x="225" y="1300" as="targetPoint"/>
<Array as="points">
<mxPoint x="900" y="1120"/>
<mxPoint x="900" y="1220"/>
<mxPoint x="225" y="1220"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="time_note" value="⏱️ 处理时间估算:

• 文件上传到 COS: ~5-30秒
• 录音文件识别: ~1-5分钟
• 有害语检测: ~10-30秒
• 数据库保存: <1秒

总计: 约 2-6 分钟" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;align=left;spacingLeft=10;fontStyle=1;" parent="1" vertex="1">
<mxGeometry x="100" y="1090" width="250" height="150" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
<diagram id="data_flow" name="4-数据流图">
<mxGraphModel dx="466" dy="899" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1600" pageHeight="900" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="title4" value="系统数据流与交互关系图" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=24;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="550" y="20" width="500" height="40" as="geometry"/>
</mxCell>
<mxCell id="data_sources_title" value="数据来源" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=16;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="80" y="80" width="150" height="30" as="geometry"/>
</mxCell>
<mxCell id="data_source1" value="ESP32-S3 设备
实时音频流" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="80" y="120" width="180" height="60" as="geometry"/>
</mxCell>
<mxCell id="data_source2" value="用户上传
音频文件" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="80" y="200" width="180" height="60" as="geometry"/>
</mxCell>
<mxCell id="data_source3" value="用户注册/登录
认证信息" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="80" y="280" width="180" height="60" as="geometry"/>
</mxCell>
<mxCell id="processing_title" value="数据处理" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=16;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="350" y="80" width="150" height="30" as="geometry"/>
</mxCell>
<mxCell id="process1" value="实时 ASR
腾讯云" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="320" y="120" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="process2" value="关键词检测
本地" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="460" y="120" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="process3" value="LLM 检测
Gemma 2" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="600" y="120" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="process4" value="离线 ASR
腾讯云" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="320" y="200" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="process5" value="说话人分离
腾讯云" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="460" y="200" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="process6" value="批量检测
LLM" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="600" y="200" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="process7" value="JWT 认证
本地" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="390" y="280" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="storage_title" value="数据存储" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=16;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="800" y="80" width="150" height="30" as="geometry"/>
</mxCell>
<mxCell id="storage1" value="本地 WAV 文件
./data/audio/" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="800" y="120" width="180" height="60" as="geometry"/>
</mxCell>
<mxCell id="storage2" value="COS 对象存储
腾讯云" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="1010" y="120" width="180" height="60" as="geometry"/>
</mxCell>
<mxCell id="storage3" value="sessions 表
SQLite" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="800" y="200" width="180" height="60" as="geometry"/>
</mxCell>
<mxCell id="storage4" value="utterances 表
SQLite" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="1010" y="200" width="180" height="60" as="geometry"/>
</mxCell>
<mxCell id="storage5" value="users 表
SQLite" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="800" y="280" width="180" height="60" as="geometry"/>
</mxCell>
<mxCell id="output_title" value="数据输出" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=16;fontStyle=1" parent="1" vertex="1">
<mxGeometry x="1250" y="80" width="150" height="30" as="geometry"/>
</mxCell>
<mxCell id="output1" value="设备振动指令
WebSocket" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="1250" y="120" width="180" height="60" as="geometry"/>
</mxCell>
<mxCell id="output2" value="Web 会话列表
REST API" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="1250" y="200" width="180" height="60" as="geometry"/>
</mxCell>
<mxCell id="output3" value="Web 会话详情
REST API" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=12;" parent="1" vertex="1">
<mxGeometry x="1250" y="280" width="180" height="60" as="geometry"/>
</mxCell>
<mxCell id="df1" value="音频流" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" source="data_source1" target="process1" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="df2" value="文本" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" source="process1" target="process2" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="df3" value="文本" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" source="process2" target="process3" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="df4" value="检测结果" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#f8cecc;strokeColor=#b85450;" parent="1" source="process3" target="output1" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="740" y="150"/>
<mxPoint x="740" y="150"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="df5" value="保存" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" source="data_source1" target="storage1" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="170" y="100"/>
<mxPoint x="890" y="100"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="df6" value="上传" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" source="storage1" target="storage2" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="df7" value="音频文件" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#dae8fc;strokeColor=#6c8ebf;" parent="1" source="data_source2" target="process4" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="df8" value="文本+说话人" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" source="process4" target="process5" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="df9" value="utterances" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" source="process5" target="process6" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="df10" value="保存" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" source="process6" target="storage4" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="740" y="230"/>
<mxPoint x="740" y="230"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="df11" value="会话信息" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" source="process1" target="storage3" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="380" y="100"/>
<mxPoint x="890" y="100"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="df12" value="查询" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" source="storage3" target="output2" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="1220" y="230"/>
<mxPoint x="1220" y="230"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="df13" value="查询" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" source="storage4" target="output3" edge="1">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="1220" y="310"/>
<mxPoint x="1220" y="310"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="df14" value="认证信息" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#e1d5e7;strokeColor=#9673a6;" parent="1" source="data_source3" target="process7" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="df15" value="保存" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#fff2cc;strokeColor=#d6b656;" parent="1" source="process7" target="storage5" edge="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="stats_box" value="数据流统计" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=14;fontStyle=1;verticalAlign=top;" parent="1" vertex="1">
<mxGeometry x="80" y="400" width="1350" height="450" as="geometry"/>
</mxCell>
<mxCell id="stats1" value="实时处理性能

• 音频采样率: 16kHz
• 每帧大小: 3200 字节 (0.1秒)
• ASR 延迟: < 500ms
• 关键词检测: < 10ms
• LLM 检测: 1-3 秒
• 总延迟: ~1.5-3.5 秒" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="110" y="440" width="350" height="150" as="geometry"/>
</mxCell>
<mxCell id="stats2" value="离线处理性能

• 文件上传: 5-30 秒
• ASR 识别: 1-5 分钟
• 说话人分离: 包含在 ASR 中
• 批量检测: 10-30 秒
• 数据库保存: < 1 秒
• 总时长: 2-6 分钟" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="490" y="440" width="350" height="150" as="geometry"/>
</mxCell>
<mxCell id="stats3" value="数据容量估算

• 音频文件 (10分钟): ~10MB
• Session 记录: ~500 字节
• Utterance 记录: ~200 字节/条
• 平均对话: 50-100 条/会话
• 数据库大小: ~50KB/会话
• 每天 100 会话: ~1GB 音频 + 5MB 数据库" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="870" y="440" width="530" height="150" as="geometry"/>
</mxCell>
<mxCell id="stats4" value="API 调用统计 (单个会话)

实时处理:
• 腾讯云实时 ASR: 持续连接,按时长计费
• LLM 检测: 10-30 次 (取决于对话数量)

离线处理:
• 腾讯云 COS 上传: 1 次
• 腾讯云录音识别: 1 次
• LLM 批量检测: 50-100 次 (可优化为批量调用)

前端查询:
• 登录: 1 次
• 会话列表: 每次访问 1 次
• 会话详情: 每次访问 1 次" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=11;align=left;spacingLeft=10;" parent="1" vertex="1">
<mxGeometry x="110" y="620" width="1290" height="200" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
<diagram id="state_machine" name="5-状态机设计">
<mxGraphModel dx="1434" dy="843" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1600" pageHeight="1400" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="title5" value="系统状态机设计" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=24;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="650" y="20" width="300" height="40" as="geometry"/>
</mxCell>
<!-- Session State Machine -->
<mxCell id="session_sm_title" value="1. 会话生命周期状态机" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=18;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="80" y="80" width="300" height="30" as="geometry"/>
</mxCell>
<mxCell id="session_sm_box" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=none;strokeColor=#d79b00;fontSize=11;dashed=1;strokeWidth=2;" vertex="1" parent="1">
<mxGeometry x="80" y="120" width="700" height="350" as="geometry"/>
</mxCell>
<!-- Session States -->
<mxCell id="s_idle" value="IDLE
空闲" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#f5f5f5;strokeColor=#666666;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="120" y="160" width="100" height="100" as="geometry"/>
</mxCell>
<mxCell id="s_connecting" value="CONNECTING
连接中" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="280" y="160" width="100" height="100" as="geometry"/>
</mxCell>
<mxCell id="s_active" value="ACTIVE
会话进行中" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="480" y="160" width="100" height="100" as="geometry"/>
</mxCell>
<mxCell id="s_processing" value="PROCESSING
处理中" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="640" y="160" width="100" height="100" as="geometry"/>
</mxCell>
<mxCell id="s_completed" value="COMPLETED
已完成" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="480" y="340" width="100" height="100" as="geometry"/>
</mxCell>
<mxCell id="s_error" value="ERROR
错误" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#f8cecc;strokeColor=#b85450;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="280" y="340" width="100" height="100" as="geometry"/>
</mxCell>
<!-- Session Transitions -->
<mxCell id="st1" value="WebSocket 连接" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=10;" edge="1" parent="1" source="s_idle" target="s_connecting">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="st2" value="start_session" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=10;" edge="1" parent="1" source="s_connecting" target="s_active">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="st3" value="end_session" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=10;" edge="1" parent="1" source="s_active" target="s_processing">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="st4" value="离线处理完成" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=10;" edge="1" parent="1" source="s_processing" target="s_completed">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="690" y="300"/>
<mxPoint x="530" y="300"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="st5" value="连接失败" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#f8cecc;strokeColor=#b85450;fontSize=10;dashed=1;" edge="1" parent="1" source="s_connecting" target="s_error">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="st6" value="异常断开" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#f8cecc;strokeColor=#b85450;fontSize=10;dashed=1;" edge="1" parent="1" source="s_active" target="s_error">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="530" y="300"/>
<mxPoint x="330" y="300"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="st7" value="重试/重新连接" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#666666;strokeColor=#666666;fontSize=10;dashed=1;" edge="1" parent="1" source="s_error" target="s_idle">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="240" y="390"/>
<mxPoint x="240" y="280"/>
<mxPoint x="170" y="280"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="st8" value="循环:接收音频
+ ASR + 检测" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=10;" edge="1" parent="1" source="s_active" target="s_active">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="530" y="130"/>
<mxPoint x="620" y="130"/>
<mxPoint x="620" y="210"/>
</Array>
</mxGeometry>
</mxCell>
<!-- WebSocket State Machine -->
<mxCell id="ws_sm_title" value="2. WebSocket 连接状态机" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=18;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="820" y="80" width="300" height="30" as="geometry"/>
</mxCell>
<mxCell id="ws_sm_box" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=none;strokeColor=#6c8ebf;fontSize=11;dashed=1;strokeWidth=2;" vertex="1" parent="1">
<mxGeometry x="820" y="120" width="700" height="350" as="geometry"/>
</mxCell>
<!-- WebSocket States -->
<mxCell id="ws_disconnected" value="DISCONNECTED
未连接" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#f5f5f5;strokeColor=#666666;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="860" y="160" width="100" height="100" as="geometry"/>
</mxCell>
<mxCell id="ws_connecting" value="CONNECTING
握手中" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="1020" y="160" width="100" height="100" as="geometry"/>
</mxCell>
<mxCell id="ws_connected" value="CONNECTED
已连接" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="1180" y="160" width="100" height="100" as="geometry"/>
</mxCell>
<mxCell id="ws_authenticated" value="AUTHENTICATED
已认证" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="1380" y="160" width="100" height="100" as="geometry"/>
</mxCell>
<mxCell id="ws_error" value="ERROR
错误" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#f8cecc;strokeColor=#b85450;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="1180" y="340" width="100" height="100" as="geometry"/>
</mxCell>
<!-- WebSocket Transitions -->
<mxCell id="wst1" value="websocket.connect()" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=10;" edge="1" parent="1" source="ws_disconnected" target="ws_connecting">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="wst2" value="握手成功" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=10;" edge="1" parent="1" source="ws_connecting" target="ws_connected">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="wst3" value="start_session 成功" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=10;" edge="1" parent="1" source="ws_connected" target="ws_authenticated">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="wst4" value="数据传输" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=10;" edge="1" parent="1" source="ws_authenticated" target="ws_authenticated">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="1430" y="130"/>
<mxPoint x="1500" y="130"/>
<mxPoint x="1500" y="210"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="wst5" value="超时/错误" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#f8cecc;strokeColor=#b85450;fontSize=10;dashed=1;" edge="1" parent="1" source="ws_connecting" target="ws_error">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="1070" y="300"/>
<mxPoint x="1230" y="300"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="wst6" value="断开连接" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#f8cecc;strokeColor=#b85450;fontSize=10;dashed=1;" edge="1" parent="1" source="ws_authenticated" target="ws_error">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="1430" y="300"/>
<mxPoint x="1230" y="300"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="wst7" value="关闭/重连" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;fillColor=#666666;strokeColor=#666666;fontSize=10;dashed=1;" edge="1" parent="1" source="ws_error" target="ws_disconnected">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="1230" y="470"/>
<mxPoint x="910" y="470"/>
<mxPoint x="910" y="280"/>
</Array>
</mxGeometry>
</mxCell>
<!-- Audio Upload State Machine -->
<mxCell id="upload_sm_title" value="3. 音频上传处理状态机" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=18;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="80" y="510" width="350" height="30" as="geometry"/>
</mxCell>
<mxCell id="upload_sm_box" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=none;strokeColor=#82b366;fontSize=11;dashed=1;strokeWidth=2;" vertex="1" parent="1">
<mxGeometry x="80" y="550" width="1440" height="280" as="geometry"/>
</mxCell>
<!-- Upload States -->
<mxCell id="u_idle" value="IDLE
空闲" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="120" y="590" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="u_uploading" value="UPLOADING
上传中" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=11;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="240" y="590" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="u_uploaded" value="UPLOADED
已上传" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=11;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="360" y="590" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="u_cos_upload" value="COS_UPLOAD
上传COS" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=11;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="480" y="590" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="u_asr_submit" value="ASR_SUBMIT
提交识别" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=11;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="600" y="590" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="u_asr_polling" value="ASR_POLLING
轮询中" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=11;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="720" y="590" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="u_asr_done" value="ASR_DONE
识别完成" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=11;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="840" y="590" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="u_llm_detect" value="LLM_DETECT
检测中" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=11;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="960" y="590" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="u_saving" value="SAVING
保存中" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=11;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="1080" y="590" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="u_completed" value="COMPLETED
完成" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=11;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="1200" y="590" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="u_error" value="ERROR
失败" style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;fillColor=#f8cecc;strokeColor=#b85450;fontSize=11;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="660" y="720" width="80" height="80" as="geometry"/>
</mxCell>
<!-- Upload Transitions -->
<mxCell id="ut1" value="选择文件" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=1.5;strokeColor=#6c8ebf;fontSize=9;" edge="1" parent="1" source="u_idle" target="u_uploading">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="ut2" value="上传完成" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=1.5;strokeColor=#82b366;fontSize=9;" edge="1" parent="1" source="u_uploading" target="u_uploaded">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="ut3" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=1.5;strokeColor=#d6b656;fontSize=9;" edge="1" parent="1" source="u_uploaded" target="u_cos_upload">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="ut4" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=1.5;strokeColor=#d79b00;fontSize=9;" edge="1" parent="1" source="u_cos_upload" target="u_asr_submit">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="ut5" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=1.5;strokeColor=#d79b00;fontSize=9;" edge="1" parent="1" source="u_asr_submit" target="u_asr_polling">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="ut6" value="每5秒查询" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=1.5;strokeColor=#d79b00;fontSize=9;" edge="1" parent="1" source="u_asr_polling" target="u_asr_polling">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="760" y="560"/>
<mxPoint x="810" y="560"/>
<mxPoint x="810" y="630"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="ut7" value="识别完成" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=1.5;strokeColor=#82b366;fontSize=9;" edge="1" parent="1" source="u_asr_polling" target="u_asr_done">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="ut8" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=1.5;strokeColor=#9673a6;fontSize=9;" edge="1" parent="1" source="u_asr_done" target="u_llm_detect">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="ut9" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=1.5;strokeColor=#d6b656;fontSize=9;" edge="1" parent="1" source="u_llm_detect" target="u_saving">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="ut10" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=1.5;strokeColor=#82b366;fontSize=9;" edge="1" parent="1" source="u_saving" target="u_completed">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="ut11" value="上传失败" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=1.5;strokeColor=#b85450;fontSize=9;dashed=1;" edge="1" parent="1" source="u_uploading" target="u_error">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="280" y="760"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="ut12" value="COS失败" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=1.5;strokeColor=#b85450;fontSize=9;dashed=1;" edge="1" parent="1" source="u_cos_upload" target="u_error">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="520" y="760"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="ut13" value="ASR超时" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=1.5;strokeColor=#b85450;fontSize=9;dashed=1;" edge="1" parent="1" source="u_asr_polling" target="u_error">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="ut14" value="重试" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=1.5;strokeColor=#666666;fontSize=9;dashed=1;" edge="1" parent="1" source="u_error" target="u_idle">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="160" y="760"/>
</Array>
</mxGeometry>
</mxCell>
<!-- ASR Detection State Machine -->
<mxCell id="detect_sm_title" value="4. 实时检测状态机" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=18;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="80" y="870" width="350" height="30" as="geometry"/>
</mxCell>
<mxCell id="detect_sm_box" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=none;strokeColor=#b85450;fontSize=11;dashed=1;strokeWidth=2;" vertex="1" parent="1">
<mxGeometry x="80" y="910" width="1440" height="450" as="geometry"/>
</mxCell>
<!-- Detection States -->
<mxCell id="d_waiting" value="WAITING
等待音频" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="140" y="960" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="d_receiving" value="RECEIVING
接收音频帧" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="320" y="960" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="d_asr_processing" value="ASR_PROCESSING
语音识别中" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="500" y="960" width="140" height="60" as="geometry"/>
</mxCell>
<mxCell id="d_text_received" value="TEXT_RECEIVED
收到文本" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="700" y="960" width="140" height="60" as="geometry"/>
</mxCell>
<mxCell id="d_keyword_check" value="KEYWORD_CHECK
关键词检测" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="140" y="1080" width="140" height="60" as="geometry"/>
</mxCell>
<mxCell id="d_llm_check" value="LLM_CHECK
LLM 检测" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#e1d5e7;strokeColor=#9673a6;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="340" y="1080" width="140" height="60" as="geometry"/>
</mxCell>
<mxCell id="d_analyzing" value="ANALYZING
分析结果" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="540" y="1080" width="140" height="60" as="geometry"/>
</mxCell>
<mxCell id="d_safe" value="SAFE
正常内容" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="740" y="1080" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="d_harmful" value="HARMFUL
有害内容" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="920" y="1080" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="d_vibrating" value="VIBRATING
发送振动" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f8cecc;strokeColor=#b85450;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="1100" y="1080" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="d_logging" value="LOGGING
记录日志" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="1280" y="1080" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="d_done" value="DONE
完成" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;fontSize=12;fontStyle=1;" vertex="1" parent="1">
<mxGeometry x="1280" y="960" width="120" height="60" as="geometry"/>
</mxCell>
<!-- Detection Transitions -->
<mxCell id="dt1" value="收到音频帧" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#6c8ebf;fontSize=10;" edge="1" parent="1" source="d_waiting" target="d_receiving">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="dt2" value="发送到 ASR" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#82b366;fontSize=10;" edge="1" parent="1" source="d_receiving" target="d_asr_processing">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="dt3" value="ASR 返回文本" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#d6b656;fontSize=10;" edge="1" parent="1" source="d_asr_processing" target="d_text_received">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="dt4" value="is_final=true" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#d79b00;fontSize=10;" edge="1" parent="1" source="d_text_received" target="d_keyword_check">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="770" y="1050"/>
<mxPoint x="210" y="1050"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="dt5" value="并行" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#9673a6;fontSize=10;" edge="1" parent="1" source="d_keyword_check" target="d_llm_check">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="dt6" value="合并结果" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#d6b656;fontSize=10;" edge="1" parent="1" source="d_llm_check" target="d_analyzing">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="dt7" value="无害" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#82b366;fontSize=10;" edge="1" parent="1" source="d_analyzing" target="d_safe">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="dt8" value="有害" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#b85450;fontSize=10;" edge="1" parent="1" source="d_analyzing" target="d_harmful">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="dt9" value="发送指令" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#b85450;fontSize=10;" edge="1" parent="1" source="d_harmful" target="d_vibrating">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="dt10" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#d6b656;fontSize=10;" edge="1" parent="1" source="d_vibrating" target="d_logging">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="dt11" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#d6b656;fontSize=10;" edge="1" parent="1" source="d_safe" target="d_logging">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="800" y="1180"/>
<mxPoint x="1340" y="1180"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="dt12" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#82b366;fontSize=10;" edge="1" parent="1" source="d_logging" target="d_done">
<mxGeometry relative="1" as="geometry"/>
</mxCell>
<mxCell id="dt13" value="继续等待" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#666666;fontSize=10;" edge="1" parent="1" source="d_done" target="d_waiting">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="1340" y="920"/>
<mxPoint x="200" y="920"/>
</Array>
</mxGeometry>
</mxCell>
<mxCell id="dt14" value="is_final=false
(忽略)" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;strokeWidth=2;strokeColor=#666666;fontSize=10;dashed=1;" edge="1" parent="1" source="d_text_received" target="d_waiting">
<mxGeometry relative="1" as="geometry">
<Array as="points">
<mxPoint x="900" y="990"/>
<mxPoint x="900" y="920"/>
<mxPoint x="200" y="920"/>
</Array>
</mxGeometry>
</mxCell>
<!-- State Machine Legend -->
<mxCell id="legend_title" value="状态机图例说明" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=middle;whiteSpace=wrap;rounded=0;fontSize=16;fontStyle=1" vertex="1" parent="1">
<mxGeometry x="1320" y="1230" width="200" height="30" as="geometry"/>
</mxCell>
<mxCell id="legend_box" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#f5f5f5;strokeColor=#666666;fontSize=11;verticalAlign=top;align=left;spacingLeft=10;" vertex="1" parent="1">
<mxGeometry x="80" y="1230" width="1200" height="130" as="geometry"/>
</mxCell>
<mxCell id="legend_content" value="状态类型:
• 圆形 = 会话/连接状态
• 方形 = 处理/检测状态

箭头类型:
• 实线箭头 → 正常流程
• 虚线箭头 ⇢ 错误/异常流程
• 循环箭头 ↻ 持续/重复操作

颜色含义:
• 灰色 - 初始/空闲状态
• 蓝色 - 连接/传输中
• 绿色 - 正常/成功状态
• 黄色/橙色 - 处理/分析中
• 紫色 - 认证/检测中
• 红色 - 错误/警告/有害内容" style="text;html=1;strokeColor=none;fillColor=none;align=left;verticalAlign=top;whiteSpace=wrap;rounded=0;fontSize=11;spacingLeft=10;" vertex="1" parent="1">
<mxGeometry x="100" y="1250" width="1160" height="100" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>