Files

55 lines
3.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 语记手表版 YuJiWatch — Apple Watch 伴生 App
抬腕点一下就录,录完自动传到 iPhone:手机端系统语音识别转写,再 AI 整理成 Markdown。
手表只负责录和传,整理、存储、分享都在 iPhone 端复用语记现有能力。
## 能做什么
- ⌚ 手表主页一键录音(72pt 红色话筒钮),录音中显示计时,停止即发送
- 📲 WatchConnectivity 传文件到 iPhone,iPhone 端自动转写并生成笔记
- 🧩 表盘复杂功能:圆形 / 长条形 / 行内形三种,显示今日速记数,点一下打开手表 App 开始录音
- 📋 手表端最近录音列表(时间、时长、是否已传到 iPhone)
## 目录结构
```
YuJiWatch/
├── YuJiWatchApp/ # → Watch App target
│ ├── YuJiWatchApp.swift # 入口
│ ├── ContentView.swift # 主页:录音 / 今日数 / 最近录音
│ ├── WatchRecorder.swift # AVAudioRecorder 录 AAC .m4a
│ ├── WatchSessionManager.swift # WCSession 传文件 + 今日数 + 刷新复杂功能
│ └── WatchStore.swift # 手表本地最近录音记录
├── YuJiWatchWidget/ # → Widget Extension target
│ └── Complication.swift # 三种复杂功能
└── Phone/ # → 拖进 YuJi iPhone 工程
└── WatchSyncService.swift # iPhone 端收文件、转写、建笔记
```
注意:`WatchSessionManager.swift` 要同时放进 Watch App 和 Widget Extension 两个 target,
因为复杂功能读今日数走它里面的 `loadTodayCount()`。两个 target 各有一个 `@main`,不要把
`Complication.swift` 放进 Watch App target,否则 `@main` 冲突。
## 在 Mac 上接进 YuJi 工程
1. 用 Xcode 16+ 打开 YuJi 工程 → File → New → Target → Watch App,部署目标选 watchOS 10
(watchOS 10 对应 Series 4 及以后、SE、Ultra 都能用;不需要 Ultra 专属功能)
2. 把 `YuJiWatchApp/` 里的文件加进 Watch App target;新建 Widget Extension target,
把 `YuJiWatchWidget/Complication.swift` 和 `WatchSessionManager.swift` 加进去
3. 把 `Phone/WatchSyncService.swift` 拖进 YuJi iPhone target,在 YuJiApp 启动时调一次:
`WatchSyncService.shared.activate(modelContext:)`(modelContext 就是 SwiftData 那个)
4. 真机联调:手表和 iPhone 配对后,手表录一段 → iPhone 端应该自动多出一条“手表速记”笔记
## 可选:App Group
现在今日数存在手表本地 UserDefaults,只给复杂功能用。如果想让 iPhone 端也读到今日数,
在 Xcode 里给 Watch App、Widget Extension、iPhone App 三个 target 开同一个 App Group,
把 `UserDefaults.standard` 换成 `UserDefaults(suiteName: "group.com.你的域名.yuji")` 即可。
## 注意
- 这份代码在 Linux 环境下写的,没在 Xcode 里实际编译过。第一次打开如果有个别编译报错,
把报错发给 Muse,一轮就能修好。
- 手表录音是短录音场景:抬腕说完就停,不要设计成长时间连续录(续航和后台限制)。
- 手表自己能录音,但转写和 AI 整理必须连上 iPhone 才回来;蜂窝版也一样,只是传输时机不同。