Skip to content

Commit e473c62

Browse files
committed
refactor(rust): 拆 types.rs 第 5 步 — 提取链路内存态域
1 parent 8773a66 commit e473c62

3 files changed

Lines changed: 91 additions & 83 deletions

File tree

‎app/src-tauri/src/types.rs‎

Lines changed: 3 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -16,93 +16,14 @@ mod types_knowledge;
1616
mod types_note;
1717
#[path = "types_ocr.rs"]
1818
mod types_ocr;
19+
#[path = "types_extract.rs"]
20+
mod types_extract;
1921

2022
pub use types_session::*;
2123
pub use types_knowledge::*;
2224
pub use types_note::*;
2325
pub use types_ocr::*;
24-
25-
/// 单条 ASR 转写片段。
26-
///
27-
/// @ai-context: start_ms/end_ms 为相对会话起点的毫秒时间戳,用于与 OCR 关键帧对齐拼接。
28-
/// @ai-context: v0.5.0 M9(REQ-054 B8):word_timestamps 为词级时间戳
29-
/// ([词, 起始毫秒] 对,相对片段起点;SenseVoice 开启 token timestamps 时产出)。
30-
/// @ai-context: v0.6.0 M2(REQ-062):confidence 为 ASR 段置信度(概率加权融合输入;
31-
/// None=未知/旧数据——融合层回退硬规则兜底)。
32-
/// @ai-context: v0.7.0 M1(REQ-103):volume 为段内平均音量(实时链路聚合 RMS;
33-
/// 融合透传到落库段——音量骤变信号输入;None=未知)。
34-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
35-
pub struct TranscriptSegment {
36-
/// 起始毫秒时间戳
37-
pub start_ms: u64,
38-
/// 结束毫秒时间戳
39-
pub end_ms: u64,
40-
/// 识别出的文本
41-
pub text: String,
42-
/// 词级时间戳(B8;None=未开启/旧数据)
43-
pub word_timestamps: Option<Vec<WordTimestamp>>,
44-
/// ASR 段置信度 0.0-1.0(REQ-062 概率加权融合;None=未知)
45-
#[serde(default)]
46-
pub confidence: Option<f32>,
47-
/// REQ-103:段内平均音量(None=未知)
48-
#[serde(default)]
49-
pub volume: Option<f32>,
50-
}
51-
52-
/// 词级时间戳(B8:产物双向定位 + AI 补缝判定器基础)。
53-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
54-
pub struct WordTimestamp {
55-
pub word: String,
56-
/// 相对片段起点的起始毫秒
57-
pub start_ms: u64,
58-
}
59-
60-
/// 文本块边界框(像素坐标,相对 OCR 输入图;M2/REQ-037 起由 det 结果填充)。
61-
///
62-
/// @ai-context: 供动态字幕区域(region_tracker)做 bbox 密度聚簇/ROI 锁定;
63-
/// 旧数据无 bbox(None),下游必须容忍缺省。
64-
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
65-
pub struct TextBox {
66-
pub x: f32,
67-
pub y: f32,
68-
pub w: f32,
69-
pub h: f32,
70-
}
71-
72-
/// 单个 OCR 识别出的画面文本块(来自一张关键帧)。
73-
///
74-
/// @ai-context: timestamp_ms 为该关键帧相对会话起点的时间戳;离线文件模式下可为 None。
75-
/// @ai-context: v0.5.0 M4(REQ-048):region_kind 标注该块来源版面区域类型
76-
/// (text/table/formula/code/unknown;整帧直跑为 None——兼容旧数据)。
77-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
78-
pub struct OcrBlock {
79-
/// 关联关键帧的时间戳(毫秒),离线导入时可能缺失
80-
pub timestamp_ms: Option<u64>,
81-
/// 识别出的文本
82-
pub text: String,
83-
/// 识别置信度 0.0-1.0
84-
pub score: f32,
85-
/// 检测框(像素坐标,相对 OCR 输入图;无 bbox 时为 None)
86-
pub bbox: Option<TextBox>,
87-
/// 来源版面区域类型(kebab-case;None=整帧直跑/旧数据)
88-
pub region_kind: Option<String>,
89-
}
90-
91-
/// 本地拼接产出的笔记初稿。
92-
///
93-
/// @ai-context: 这是"课堂助手 → 笔记"联动的中间产物(REQ-003/REQ-005)。
94-
/// @ai-context: 纯本地规则生成,不依赖 LLM;markdown 字段为可直接落入笔记编辑器的内容。
95-
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
96-
pub struct NoteDraft {
97-
/// 笔记标题
98-
pub title: String,
99-
/// 讲述内容(转写拼接后的分段文本)
100-
pub transcript_paragraphs: Vec<String>,
101-
/// 画面要点(OCR 去重后的文本,按时间排序)
102-
pub ocr_points: Vec<String>,
103-
/// 组装好的 Markdown 全文
104-
pub markdown: String,
105-
}
26+
pub use types_extract::*;
10627

10728
/// 决策/应用记录(v0.13.3 REQ-208;一表两面,kind 区分)。
10829
///

‎app/src-tauri/src/types_extract.rs‎

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//! @ai-context: 提取链路内存态类型(ADR-004 定性为"引擎层产物"):ASR 段、词级时间戳、bbox、OCR 块、拼接初稿。
2+
//! @ai-context: 纯数据定义(0 impl / 0 IO / 0 副作用);被 asr/ocr/concat/engine 各层复用,不落库。
3+
//! @ai-context: 由 types.rs 门面 `#[path]` 声明 + `pub use` 再导出 ⇒ crate::types::X 引用路径逐字不变。
4+
5+
use serde::{Deserialize, Serialize};
6+
7+
/// 单条 ASR 转写片段。
8+
///
9+
/// @ai-context: start_ms/end_ms 为相对会话起点的毫秒时间戳,用于与 OCR 关键帧对齐拼接。
10+
/// @ai-context: v0.5.0 M9(REQ-054 B8):word_timestamps 为词级时间戳
11+
/// ([词, 起始毫秒] 对,相对片段起点;SenseVoice 开启 token timestamps 时产出)。
12+
/// @ai-context: v0.6.0 M2(REQ-062):confidence 为 ASR 段置信度(概率加权融合输入;
13+
/// None=未知/旧数据——融合层回退硬规则兜底)。
14+
/// @ai-context: v0.7.0 M1(REQ-103):volume 为段内平均音量(实时链路聚合 RMS;
15+
/// 融合透传到落库段——音量骤变信号输入;None=未知)。
16+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
17+
pub struct TranscriptSegment {
18+
/// 起始毫秒时间戳
19+
pub start_ms: u64,
20+
/// 结束毫秒时间戳
21+
pub end_ms: u64,
22+
/// 识别出的文本
23+
pub text: String,
24+
/// 词级时间戳(B8;None=未开启/旧数据)
25+
pub word_timestamps: Option<Vec<WordTimestamp>>,
26+
/// ASR 段置信度 0.0-1.0(REQ-062 概率加权融合;None=未知)
27+
#[serde(default)]
28+
pub confidence: Option<f32>,
29+
/// REQ-103:段内平均音量(None=未知)
30+
#[serde(default)]
31+
pub volume: Option<f32>,
32+
}
33+
34+
/// 词级时间戳(B8:产物双向定位 + AI 补缝判定器基础)。
35+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
36+
pub struct WordTimestamp {
37+
pub word: String,
38+
/// 相对片段起点的起始毫秒
39+
pub start_ms: u64,
40+
}
41+
42+
/// 文本块边界框(像素坐标,相对 OCR 输入图;M2/REQ-037 起由 det 结果填充)。
43+
///
44+
/// @ai-context: 供动态字幕区域(region_tracker)做 bbox 密度聚簇/ROI 锁定;
45+
/// 旧数据无 bbox(None),下游必须容忍缺省。
46+
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
47+
pub struct TextBox {
48+
pub x: f32,
49+
pub y: f32,
50+
pub w: f32,
51+
pub h: f32,
52+
}
53+
54+
/// 单个 OCR 识别出的画面文本块(来自一张关键帧)。
55+
///
56+
/// @ai-context: timestamp_ms 为该关键帧相对会话起点的时间戳;离线文件模式下可为 None。
57+
/// @ai-context: v0.5.0 M4(REQ-048):region_kind 标注该块来源版面区域类型
58+
/// (text/table/formula/code/unknown;整帧直跑为 None——兼容旧数据)。
59+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
60+
pub struct OcrBlock {
61+
/// 关联关键帧的时间戳(毫秒),离线导入时可能缺失
62+
pub timestamp_ms: Option<u64>,
63+
/// 识别出的文本
64+
pub text: String,
65+
/// 识别置信度 0.0-1.0
66+
pub score: f32,
67+
/// 检测框(像素坐标,相对 OCR 输入图;无 bbox 时为 None)
68+
pub bbox: Option<TextBox>,
69+
/// 来源版面区域类型(kebab-case;None=整帧直跑/旧数据)
70+
pub region_kind: Option<String>,
71+
}
72+
73+
/// 本地拼接产出的笔记初稿。
74+
///
75+
/// @ai-context: 这是"课堂助手 → 笔记"联动的中间产物(REQ-003/REQ-005)。
76+
/// @ai-context: 纯本地规则生成,不依赖 LLM;markdown 字段为可直接落入笔记编辑器的内容。
77+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
78+
pub struct NoteDraft {
79+
/// 笔记标题
80+
pub title: String,
81+
/// 讲述内容(转写拼接后的分段文本)
82+
pub transcript_paragraphs: Vec<String>,
83+
/// 画面要点(OCR 去重后的文本,按时间排序)
84+
pub ocr_points: Vec<String>,
85+
/// 组装好的 Markdown 全文
86+
pub markdown: String,
87+
}

‎app/src-tauri/src/types_ocr.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! @ai-context: 由 types.rs 门面 `#[path]` 声明 + `pub use` 再导出 ⇒ crate::types::X 引用路径逐字不变。
44
55
use serde::{Deserialize, Serialize};
6-
use super::TextBox;
6+
use super::types_extract::TextBox;
77

88
/// 会话 OCR 块(关键帧画面文字 / 字幕区文字)。
99
///

0 commit comments

Comments
 (0)