@willh/subtitle-correction-agent 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +184 -0
  3. package/dist/index.js +4783 -0
  4. package/package.json +44 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Will 保哥
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,184 @@
1
+ # 影片字幕校正代理人
2
+
3
+ 使用 GitHub Copilot SDK 開發的影片字幕校正代理人,能自動分析、校正 VTT 字幕檔案中的錯字,並產生章節資訊與內容總結。
4
+
5
+ ## 功能特色
6
+
7
+ 1. **主題分析** - 自動分析影片的主要談論內容與方向
8
+ 2. **關鍵字整理** - 根據主題領域整理常見的專業術語與專有名詞
9
+ 3. **字幕校正** - 分析每段字幕的正確性,自動校正轉錄錯誤
10
+ 4. **修正清單** - 記錄所有修正項目,包含原文、校正後文字與修正原因
11
+ 5. **章節生成** - 自動建立分段章節,包含標題與時間戳
12
+ 6. **內容總結** - 產生影片內容的摘要總結
13
+
14
+ ## 安裝
15
+
16
+ ### 全域安裝 (建議)
17
+
18
+ ```bash
19
+ npm install -g @willh/subtitle-correction-agent
20
+ # 或
21
+ bun add -g @willh/subtitle-correction-agent
22
+ ```
23
+
24
+ 安裝完成後即可使用 `subtitle-correction-agent` 指令。
25
+
26
+ ### 直接執行 (免安裝)
27
+
28
+ ```bash
29
+ npx @willh/subtitle-correction-agent <vtt-file-path>
30
+ ```
31
+
32
+ ## 環境設定
33
+
34
+ 複製 `.env.example` 為 `.env` 並填入 Azure OpenAI 的設定:
35
+
36
+ ```bash
37
+ cp .env.example .env
38
+ ```
39
+
40
+ 需要設定以下環境變數:
41
+
42
+ | 變數名稱 | 說明 |
43
+ |---------|------|
44
+ | `AZURE_OPENAI_ENDPOINT` | Azure OpenAI 端點 URL |
45
+ | `AZURE_OPENAI_API_KEY` | Azure OpenAI API 金鑰 |
46
+ | `AZURE_OPENAI_DEPLOYMENT` | Azure OpenAI 部署名稱 |
47
+ | `AZURE_OPENAI_API_VERSION` | API 版本 (預設: 2024-10-21) |
48
+
49
+ ## 使用方式
50
+
51
+ ```bash
52
+ # 基本使用
53
+ subtitle-correction-agent <vtt-file-path>
54
+
55
+ # 指定輸出目錄
56
+ subtitle-correction-agent <vtt-file-path> --output-dir <output-directory>
57
+
58
+ # 範例
59
+ subtitle-correction-agent ./examples/sample.vtt
60
+ subtitle-correction-agent "C:\Videos\lecture.vtt" --output-dir ./output
61
+ ```
62
+
63
+ ## Telegram Bot
64
+
65
+ 只要使用者上傳 `.vtt` 檔案,Bot 會自動校正字幕並回傳所有輸出檔案。
66
+ 同樣需要設定 Azure OpenAI 的環境變數。
67
+
68
+ ### 環境變數
69
+
70
+ | 變數名稱 | 說明 |
71
+ |---------|------|
72
+ | `TELEGRAM_BOT_TOKEN` | Telegram Bot Token |
73
+ | `OWNER_CHAT_ID` | 允許使用 Bot 的唯一 chat id |
74
+ | `TELEGRAM_STARTUP_CHAT_ID` | 啟動通知的 chat id (可用逗號分隔多個) |
75
+ | `BOT_MAX_CONCURRENT` | 同時處理數量上限 (預設: 1) |
76
+ | `KEEP_TEMP_FILES` | 保留暫存檔案 (1=保留,預設: 0) |
77
+ | `BOT_LOG_LEVEL` | 日誌等級 (debug/info/warn/error,預設: info) |
78
+ | `BOT_DEBUG` | 快速開啟 debug (1=啟用) |
79
+ | `BOT_DATA_DIR` | 資料持久化目錄 (預設: 專案根目錄的 data/) |
80
+
81
+ ### 執行
82
+
83
+ ```bash
84
+ # 本地開發模式
85
+ bun run bot
86
+
87
+ # 建置後執行
88
+ bun run build:bot
89
+ node dist/telegram-bot.js
90
+ ```
91
+
92
+ ### 使用流程
93
+
94
+ 1. 在 Telegram 對 Bot 傳送 `/start`
95
+ - 只有 `OWNER_CHAT_ID` 指定的 chat 可以使用
96
+ 2. 上傳 `.vtt` 字幕檔案
97
+ 3. 等待校正完成後,Bot 會回傳:
98
+ - 校正後字幕
99
+ - 修正清單
100
+ - 章節資訊
101
+ - 內容總結
102
+ 4. 另外會回傳一則執行摘要到聊天室
103
+ 5. 聊天室 ID 會持久化到 `BOT_DATA_DIR/telegram-chat-ids.json`
104
+
105
+ ## 輸出檔案
106
+
107
+ 執行後會在 VTT 檔案所在目錄(或指定的輸出目錄)產生以下檔案:
108
+
109
+ | 檔案 | 說明 |
110
+ |------|------|
111
+ | `{filename}-corrected.vtt` | 校正後的字幕檔案 |
112
+ | `{filename}-corrections.txt` | 修正清單 |
113
+ | `{filename}-chapters.txt` | 章節資訊 |
114
+ | `{filename}-summary.txt` | 內容總結 |
115
+
116
+ ## 專案結構
117
+
118
+ ```
119
+ subtitle-correction-agent/
120
+ ├── package.json
121
+ ├── tsconfig.json
122
+ ├── .env.example
123
+ ├── README.md
124
+ └── src/
125
+ ├── index.ts # CLI 入口
126
+ ├── agent.ts # 代理人核心邏輯
127
+ ├── telegram-bot.ts # Telegram Bot 入口
128
+ ├── tools/
129
+ │ ├── index.ts # 工具匯出
130
+ │ ├── read-vtt.ts # VTT 讀取工具
131
+ │ ├── write-file.ts # 檔案寫入工具
132
+ │ └── update-vtt.ts # VTT 更新工具
133
+ └── utils/
134
+ └── vtt-parser.ts # VTT 解析器
135
+ ```
136
+
137
+ ## 技術細節
138
+
139
+ - **GitHub Copilot SDK** - 使用 @github/copilot-sdk 建立 AI 代理人
140
+ - **Azure OpenAI BYOK** - 支援自帶金鑰的 Azure OpenAI 服務
141
+ - **自訂工具** - 定義了讀取、更新 VTT 和寫入檔案等工具
142
+ - **Bun** - 以 Bun 進行建置與測試
143
+
144
+ ## 處理流程
145
+
146
+ 1. 讀取指定的 VTT 字幕檔案
147
+ 2. 分析整體內容,判斷影片的主題方向
148
+ 3. 根據主題領域整理正確的專業術語清單
149
+ 4. 逐一分析每段字幕,找出潛在的轉錄錯誤
150
+ 5. 根據上下文和專業術語清單進行校正
151
+ 6. 產生修正清單,記錄所有變更
152
+ 7. 儲存校正後的 VTT 檔案
153
+ 8. 根據內容自動建立章節索引
154
+ 9. 產生影片內容總結
155
+
156
+ ## 開發
157
+
158
+ ```bash
159
+ bun install
160
+
161
+ # 本地執行 (TS 直接執行)
162
+ bun run dev -- <vtt-file-path>
163
+
164
+ # 型別檢查
165
+ bun run typecheck
166
+
167
+ # 單元測試
168
+ bun run test
169
+
170
+ # 建置
171
+ bun run build
172
+ ```
173
+
174
+ ## 貢獻
175
+
176
+ 歡迎 PR!建議流程:
177
+
178
+ 1. Fork 專案並建立分支
179
+ 2. 提交變更並補齊對應測試
180
+ 3. 確認 `bun run test` 通過後送出 PR
181
+
182
+ ## 授權
183
+
184
+ MIT License. 詳見 `LICENSE`。