A local-first multi-agent app development platform, built on PenguinHarness
feat(plugins): 收录 lesson-video 插件(讲稿一键成竖屏教学视频与封面)
lmlihengb873c041d780
diff --git a/README.zh.md b/README.zh.mdindex 3f3cce1b..8e1d0881 100644--- a/README.zh.md+++ b/README.zh.md@@ -72,7 +72,7 @@ https://github.com/user-attachments/assets/aec49ae9-b743-467b-b247-37bedfeaa36e| 分类 | 插件 || ----------- | ------------------------------------------------------------------------------- |-| 办公效率 | `data-analysis`、`use-firecrawl`、`browser-automation`、`use-bento-slides`、`humanizer`、`goal`、`continual-learning`、`csu-mail` |+| 办公效率 | `data-analysis`、`use-firecrawl`、`browser-automation`、`use-bento-slides`、`humanizer`、`goal`、`continual-learning`、`csu-mail`、`lesson-video` || 软件开发 | `software-development`、`use-claude-code`、`wechat-miniprogram` || AI 应用开发 | `agent-development`、`model-development`、`skill-porting`、`agent-tuning` || Agent 公司 | `agent-company` |diff --git a/packages/cli/package.json b/packages/cli/package.jsonindex 35eb9b00..2bee2ec4 100644--- a/packages/cli/package.json+++ b/packages/cli/package.json@@ -33,6 +33,7 @@"@lmliheng/data-analysis": "workspace:*","@lmliheng/goal": "workspace:*","@lmliheng/humanizer": "workspace:*",+ "@lmliheng/lesson-video": "workspace:*","@lmliheng/model-development": "workspace:*","@lmliheng/skill-porting": "workspace:*","@lmliheng/software-development": "workspace:*",diff --git a/packages/core/package.json b/packages/core/package.jsonindex 9ce0aadd..91ab4a41 100644--- a/packages/core/package.json+++ b/packages/core/package.json@@ -66,6 +66,7 @@"@lmliheng/data-analysis": "workspace:*","@lmliheng/goal": "workspace:*","@lmliheng/humanizer": "workspace:*",+ "@lmliheng/lesson-video": "workspace:*","@lmliheng/model-development": "workspace:*","@lmliheng/skill-porting": "workspace:*","@lmliheng/software-development": "workspace:*",diff --git a/packages/core/test/plugins.test.ts b/packages/core/test/plugins.test.tsindex e5fa29a2..c1f0a204 100644--- a/packages/core/test/plugins.test.ts+++ b/packages/core/test/plugins.test.ts@@ -65,7 +65,7 @@ describe("loadLibraryPlugins", () => {it("loads every plugin directory sorted by name, each with a date-sequence version and a category", () => {const plugins = loadLibraryPlugins();expect(plugins.map((p) => p.name)).toEqual([...plugins.map((p) => p.name)].sort());- expect(plugins.length).toBe(16);+ expect(plugins.length).toBe(17);for (const plugin of plugins) {expect(plugin.version, plugin.name).toMatch(PLUGIN_VERSION_PATTERN);expect(@@ -212,6 +212,7 @@ describe("groupPlugins / loadPluginGroups", () => {"data-analysis","goal","humanizer",+ "lesson-video","use-bento-slides","use-firecrawl",]);diff --git a/packages/desktop/package.json b/packages/desktop/package.jsonindex ce2864a5..1c4a077f 100644--- a/packages/desktop/package.json+++ b/packages/desktop/package.json@@ -25,6 +25,7 @@"@lmliheng/data-analysis": "workspace:*","@lmliheng/goal": "workspace:*","@lmliheng/humanizer": "workspace:*",+ "@lmliheng/lesson-video": "workspace:*","@lmliheng/model-development": "workspace:*","@lmliheng/skill-porting": "workspace:*","@lmliheng/software-development": "workspace:*",diff --git a/packages/docs/content/skills.en.md b/packages/docs/content/skills.en.mdindex ffba1d5b..53e6ef08 100644--- a/packages/docs/content/skills.en.md+++ b/packages/docs/content/skills.en.md@@ -223,6 +223,7 @@ The built-in plugins, by category (`PLUGIN_CATEGORIES` in `packages/core/src/plu| | `goal` | The stop hook behind [goal mode](/goal-mode): keeps the Session working toward an objective until it is complete, blocked, or out of Token budget (preinstalled) || | `continual-learning` | When a Task ends after more than 30 turns, hands its condensed excerpt to a background subagent that folds the durable findings into the agent's Skills (not preinstalled) || | `csu-mail` | Manage a Coremail mailbox (CSU student mail, `mail.csu.edu.cn`): generate a client app password once, then list, search, read and send mail over IMAP/SMTP, with a copy kept in the Sent folder — daily mail work never touches the unified auth portal (not preinstalled) |+| | `lesson-video` | Turn a written script into a narrated vertical lesson video (1080×1920, Douyin / Reels ready) and its cover art: an HTML deck pinned to a timeline, edge-tts voice-over with word-level timing, Playwright frame capture, an ffmpeg mux, edge safe areas left empty for mobile app buttons, a pre-render self-check for overflow and clipping, and publishing copy with at most five tags (not preinstalled: install from the library when needed) || Software Development | `software-development` | Software development end to end, with two Skills: `software-engineering` (investigate, implement and validate with minimal scope) and `web-design` (the Penguin visual language for generated web UIs) || | `use-claude-code` | Run Claude Code on a remote host over SSH: a persistent expect session, headless `-p` with the stdin fix, a tmux-driven interactive TUI and multi-turn continuity (not preinstalled: install from the library when needed) || | `wechat-miniprogram` | Take a WeChat mini-program from code to published on a headless Linux server: QR login to mp.weixin.qq.com, switching from a public account to the mini-program backend, the AppID and upload key, IP whitelisting, upload with miniprogram-ci, a verified preview QR, the mandatory user-privacy policy, review and release (not preinstalled) |diff --git a/packages/docs/content/skills.zh.md b/packages/docs/content/skills.zh.mdindex 4ad650c5..0f6d78a5 100644--- a/packages/docs/content/skills.zh.md+++ b/packages/docs/content/skills.zh.md@@ -223,6 +223,7 @@ Agent 可以在 Task 中重写自己的 `SKILL.md`。结合 Benchmark 评估和| | `goal` | [目标模式](/goal-mode)背后的 stop 钩子:让 Session 持续朝着目标推进,直到完成、受阻或 Token 预算耗尽(预装) || | `continual-learning` | Task 运行超过 30 轮才结束时,把 Task 的精简摘录交给后台子 Agent,由它把有长期价值的发现沉淀到 Agent 的 Skill 中(不预装) || | `csu-mail` | 管理中南大学 Coremail 邮箱(`mail.csu.edu.cn`):一次性生成客户端专用密码,之后用 IMAP/SMTP 从命令行查信、检索、读信、发信,并在「已发送」留底——日常收发信完全不碰统一身份认证(不预装) |+| | `lesson-video` | 把写好的讲稿做成竖屏教学视频(1080×1920,抖音 / Reels 规格)与配套封面:HTML 课件按时间轴定格、edge-tts 逐词对齐配音、Playwright 逐帧截图、ffmpeg 合成,两侧与上部按手机 App 按钮留出安全区,渲染前先自检越界与裁切,并给出标签不超过五个的发布文案(不预装:需要时从插件库安装) || 软件开发 | `software-development` | 端到端的软件开发,包含两个 Skill:`software-engineering`(在最小范围内调查、实现和验证)和 `web-design`(生成 Web UI 用的 Penguin 视觉语言) || | `use-claude-code` | 通过 SSH 在远程主机上运行 Claude Code:持久 expect 会话、带 stdin 修复的无头 `-p` 模式、tmux 驱动的交互式 TUI,以及多轮连续性(不预装:需要时从插件库安装) || | `wechat-miniprogram` | 在无桌面的 Linux 服务器上把微信小程序从代码做到发布:扫码登录 mp.weixin.qq.com、从公众号后台切到小程序后台、取 AppID 与上传密钥、加 IP 白名单、用 miniprogram-ci 上传、交付校验过的预览码、填写必填的用户隐私保护指引、提交审核与发布(不预装) |diff --git a/plugins/README.md b/plugins/README.mdindex 94878807..ca33a318 100644--- a/plugins/README.md+++ b/plugins/README.md@@ -8,12 +8,12 @@ Included plugins, by category (`PLUGIN_CATEGORIES` in `packages/core/src/plugins| Category | Plugins || --- | --- |-| Office Productivity | `data-analysis`, `use-firecrawl`, `browser-automation`, `use-bento-slides`, `humanizer`, `goal`, `continual-learning`, `csu-mail` |+| Office Productivity | `data-analysis`, `use-firecrawl`, `browser-automation`, `use-bento-slides`, `humanizer`, `goal`, `continual-learning`, `csu-mail`, `lesson-video` || Software Development | `software-development`, `use-claude-code`, `wechat-miniprogram` || AI App Development | `agent-development`, `model-development`, `skill-porting`, `agent-tuning` || Agent Company | `agent-company` |-`humanizer`, `use-claude-code`, `continual-learning`, `agent-company`, `csu-mail` and `wechat-miniprogram` carry `preinstall: false`, so `default_agent` does not get them at initialization — they are installed from the library on demand (`agent-company` by the organization itself, when it creates the CEO and hires employees, or by hand onto any Agent that should be able to create one). `goal` is the stop hook behind goal mode: its `start.mjs`, a `user_prompt` command marked `"trigger": "host"` so that it runs only when a goal starts, writes the Session's `GOAL.json` and composes round 1; its `stop.mjs` reads the Trace after every Task and injects the next round or ends the goal. `continual-learning` hands a long task's condensed excerpt to a background subagent that folds the findings into the agent's skills.+`humanizer`, `use-claude-code`, `continual-learning`, `agent-company`, `csu-mail`, `wechat-miniprogram` and `lesson-video` carry `preinstall: false`, so `default_agent` does not get them at initialization — they are installed from the library on demand (`agent-company` by the organization itself, when it creates the CEO and hires employees, or by hand onto any Agent that should be able to create one). `goal` is the stop hook behind goal mode: its `start.mjs`, a `user_prompt` command marked `"trigger": "host"` so that it runs only when a goal starts, writes the Session's `GOAL.json` and composes round 1; its `stop.mjs` reads the Trace after every Task and injects the next round or ends the goal. `continual-learning` hands a long task's condensed excerpt to a background subagent that folds the findings into the agent's skills.`browser-automation` drives the desktop app's built-in browser through `penguin browser`: GenericAgent's scan → act → check loop over simplified HTML, trusted clicks and typing, and sign-ins imported from the system browser, with Amazon orders as the worked example.diff --git a/plugins/lesson-video/LICENSE b/plugins/lesson-video/LICENSEnew file mode 100644index 00000000..261eeb9e--- /dev/null+++ b/plugins/lesson-video/LICENSE@@ -0,0 +1,201 @@+ Apache License+ Version 2.0, January 2004+ http://www.apache.org/licenses/++ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION++ 1. Definitions.++ "License" shall mean the terms and conditions for use, reproduction,+ and distribution as defined by Sections 1 through 9 of this document.++ "Licensor" shall mean the copyright owner or entity authorized by+ the copyright owner that is granting the License.++ "Legal Entity" shall mean the union of the acting entity and all+ other entities that control, are controlled by, or are under common+ control with that entity. For the purposes of this definition,+ "control" means (i) the power, direct or indirect, to cause the+ direction or management of such entity, whether by contract or+ otherwise, or (ii) ownership of fifty percent (50%) or more of the+ outstanding shares, or (iii) beneficial ownership of such entity.++ "You" (or "Your") shall mean an individual or Legal Entity+ exercising permissions granted by this License.++ "Source" form shall mean the preferred form for making modifications,+ including but not limited to software source code, documentation+ source, and configuration files.++ "Object" form shall mean any form resulting from mechanical+ transformation or translation of a Source form, including but+ not limited to compiled object code, generated documentation,+ and conversions to other media types.++ "Work" shall mean the work of authorship, whether in Source or+ Object form, made available under the License, as indicated by a+ copyright notice that is included in or attached to the work+ (an example is provided in the Appendix below).++ "Derivative Works" shall mean any work, whether in Source or Object+ form, that is based on (or derived from) the Work and for which the+ editorial revisions, annotations, elaborations, or other modifications+ represent, as a whole, an original work of authorship. For the purposes+ of this License, Derivative Works shall not include works that remain+ separable from, or merely link (or bind by name) to the interfaces of,+ the Work and Derivative Works thereof.++ "Contribution" shall mean any work of authorship, including+ the original version of the Work and any modifications or additions+ to that Work or Derivative Works thereof, that is intentionally+ submitted to Licensor for inclusion in the Work by the copyright owner+ or by an individual or Legal Entity authorized to submit on behalf of+ the copyright owner. For the purposes of this definition, "submitted"+ means any form of electronic, verbal, or written communication sent+ to the Licensor or its representatives, including but not limited to+ communication on electronic mailing lists, source code control systems,+ and issue tracking systems that are managed by, or on behalf of, the+ Licensor for the purpose of discussing and improving the Work, but+ excluding communication that is conspicuously marked or otherwise+ designated in writing by the copyright owner as "Not a Contribution."++ "Contributor" shall mean Licensor and any individual or Legal Entity+ on behalf of whom a Contribution has been received by Licensor and+ subsequently incorporated within the Work.++ 2. Grant of Copyright License. Subject to the terms and conditions of+ this License, each Contributor hereby grants to You a perpetual,+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable+ copyright license to reproduce, prepare Derivative Works of,+ publicly display, publicly perform, sublicense, and distribute the+ Work and such Derivative Works in Source or Object form.++ 3. Grant of Patent License. Subject to the terms and conditions of+ this License, each Contributor hereby grants to You a perpetual,+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable+ (except as stated in this section) patent license to make, have made,+ use, offer to sell, sell, import, and otherwise transfer the Work,+ where such license applies only to those patent claims licensable+ by such Contributor that are necessarily infringed by their+ Contribution(s) alone or by combination of their Contribution(s)+ with the Work to which such Contribution(s) was submitted. If You+ institute patent litigation against any entity (including a+ cross-claim or counterclaim in a lawsuit) alleging that the Work+ or a Contribution incorporated within the Work constitutes direct+ or contributory patent infringement, then any patent licenses+ granted to You under this License for that Work shall terminate+ as of the date such litigation is filed.++ 4. Redistribution. You may reproduce and distribute copies of the+ Work or Derivative Works thereof in any medium, with or without+ modifications, and in Source or Object form, provided that You+ meet the following conditions:++ (a) You must give any other recipients of the Work or+ Derivative Works a copy of this License; and++ (b) You must cause any modified files to carry prominent notices+ stating that You changed the files; and++ (c) You must retain, in the Source form of any Derivative Works+ that You distribute, all copyright, patent, trademark, and+ attribution notices from the Source form of the Work,+ excluding those notices that do not pertain to any part of+ the Derivative Works; and++ (d) If the Work includes a "NOTICE" text file as part of its+ distribution, then any Derivative Works that You distribute must+ include a readable copy of the attribution notices contained+ within such NOTICE file, excluding those notices that do not+ pertain to any part of the Derivative Works, in at least one+ of the following places: within a NOTICE text file distributed+ as part of the Derivative Works; within the Source form or+ documentation, if provided along with the Derivative Works; or,+ within a display generated by the Derivative Works, if and+ wherever such third-party notices normally appear. The contents+ of the NOTICE file are for informational purposes only and+ do not modify the License. You may add Your own attribution+ notices within Derivative Works that You distribute, alongside+ or as an addendum to the NOTICE text from the Work, provided+ that such additional attribution notices cannot be construed+ as modifying the License.++ You may add Your own copyright statement to Your modifications and+ may provide additional or different license terms and conditions+ for use, reproduction, or distribution of Your modifications, or+ for any such Derivative Works as a whole, provided Your use,+ reproduction, and distribution of the Work otherwise complies with+ the conditions stated in this License.++ 5. Submission of Contributions. Unless You explicitly state otherwise,+ any Contribution intentionally submitted for inclusion in the Work+ by You to the Licensor shall be under the terms and conditions of+ this License, without any additional terms or conditions.+ Notwithstanding the above, nothing herein shall supersede or modify+ the terms of any separate license agreement you may have executed+ with Licensor regarding such Contributions.++ 6. Trademarks. This License does not grant permission to use the trade+ names, trademarks, service marks, or product names of the Licensor,+ except as required for reasonable and customary use in describing the+ origin of the Work and reproducing the content of the NOTICE file.++ 7. Disclaimer of Warranty. Unless required by applicable law or+ agreed to in writing, Licensor provides the Work (and each+ Contributor provides its Contributions) on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or+ implied, including, without limitation, any warranties or conditions+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A+ PARTICULAR PURPOSE. You are solely responsible for determining the+ appropriateness of using or redistributing the Work and assume any+ risks associated with Your exercise of permissions under this License.++ 8. Limitation of Liability. In no event and under no legal theory,+ whether in tort (including negligence), contract, or otherwise,+ unless required by applicable law (such as deliberate and grossly+ negligent acts) or agreed to in writing, shall any Contributor be+ liable to You for damages, including any direct, indirect, special,+ incidental, or consequential damages of any character arising as a+ result of this License or out of the use or inability to use the+ Work (including but not limited to damages for loss of goodwill,+ work stoppage, computer failure or malfunction, or any and all+ other commercial damages or losses), even if such Contributor+ has been advised of the possibility of such damages.++ 9. Accepting Warranty or Additional Liability. While redistributing+ the Work or Derivative Works thereof, You may choose to offer,+ and charge a fee for, acceptance of support, warranty, indemnity,+ or other liability obligations and/or rights consistent with this+ License. However, in accepting such obligations, You may act only+ on Your own behalf and on Your sole responsibility, not on behalf+ of any other Contributor, and only if You agree to indemnify,+ defend, and hold each Contributor harmless for any liability+ incurred by, or claims asserted against, such Contributor by reason+ of your accepting any such warranty or additional liability.++ END OF TERMS AND CONDITIONS++ APPENDIX: How to apply the Apache License to your work.++ To apply the Apache License to your work, attach the following+ boilerplate notice, with the fields enclosed by brackets "[]"+ replaced with your own identifying information. (Don't include+ the brackets!) The text should be enclosed in the appropriate+ comment syntax for the file format. We also recommend that a+ file or class name and description of purpose be included on the+ same "printed page" as the copyright notice for easier+ identification within third-party archives.++ Copyright [yyyy] [name of copyright owner]++ Licensed under the Apache License, Version 2.0 (the "License");+ you may not use this file except in compliance with the License.+ You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++ Unless required by applicable law or agreed to in writing, software+ distributed under the License is distributed on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ See the License for the specific language governing permissions and+ limitations under the License.diff --git a/plugins/lesson-video/README.md b/plugins/lesson-video/README.mdnew file mode 100644index 00000000..d600b8ae--- /dev/null+++ b/plugins/lesson-video/README.md@@ -0,0 +1,51 @@+# lesson-video++Narrated **vertical lesson videos** (1080×1920, Douyin / Reels ready) from a written script — plus the cover art and the publishing copy that goes with them.++The whole thing rests on one idea: **the picture is a pure function of time `t`**. You write what is said, edge-tts speaks it and hands back word-level timings, and every frame is then *computed* from that timeline. Voice, subtitles and slides line up by construction, so there is nothing to edit afterwards.++```+script.json ──tts.py──▶ narration.wav + lesson.json ──render.mjs──▶ 30fps JPEG frames ──build.py──▶ mp4 + srt+covers.json ──cover.mjs──▶ 1080×1920 video cover + 1080×1440 profile cover+```++## Why it exists++- **Safe areas for real phones.** App buttons and status bars cover the edges of a portrait screen, so the layout keeps the sides and the top empty by design: content lives inside 745 × 1170 px, and the subtitle band starts at y = 1470.+- **A pre-render self-check.** `render.mjs --check` fails *before* spending minutes on frames: content past the subtitle safe line, code lines clipped by the card, and titles left with a one-character orphan line.+- **No editing software, no GPU.** Headless Chrome + `imageio-ffmpeg`; a three-minute episode renders in about five minutes on CPU, and re-rendering after a script fix is one command.+- **No baked-in branding.** Watermark, brand mark, CTA and every caption come from the data files — the templates ship with nothing of anyone's hard-coded.++## What's inside++| Path | What it is |+| --- | --- |+| `skills/lesson-video/SKILL.md` | The skill: script schema, the three commands, the layout rules, the pitfalls |+| `skills/lesson-video/kit/` | The toolkit — `tts.py`, `render.mjs`, `build.py`, `deck.html`, `cover.mjs`, `cover.html`; copy it into a project as `lib/` |+| `skills/lesson-video/example/` | A skeleton `script.json` (four scene types) and `covers.json` |++## Requirements++| Need | Install |+| --- | --- |+| Python packages | `pip install edge-tts imageio-ffmpeg` (the ffmpeg binary comes with the second one) |+| Playwright core | any usable `playwright-core`; point `PLAYWRIGHT_MODULE` at it |+| A browser | any Chrome / Chromium; point `CHROME_PATH` at it |++## Quick start++```bash+cp -r <skill>/kit/* <project>/lib/+mkdir -p <project>/lessons/ep01++# 1. write <project>/lessons/ep01/script.json (see the skill for the schema)++PYTHONUTF8=1 python lib/tts.py lessons/ep01+node lib/render.mjs --dir lessons/ep01 --check # 10s: safe area, clipped code, orphan titles+PLAYWRIGHT_MODULE=… CHROME_PATH=… node lib/render.mjs --dir lessons/ep01+PYTHONUTF8=1 python lib/build.py lessons/ep01 # out/ep01.mp4 + out/ep01.srt+```++## License++Apache-2.0diff --git a/plugins/lesson-video/icon.svg b/plugins/lesson-video/icon.svgnew file mode 100644index 00000000..80454858--- /dev/null+++ b/plugins/lesson-video/icon.svg@@ -0,0 +1,7 @@+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Lesson video">+ <rect x="20" y="5" width="24" height="54" rx="6" fill="#2f6fed"/>+ <rect x="24.5" y="10" width="15" height="44" rx="3.5" fill="#0b1220"/>+ <path d="M30 25.5v13l10-6.5z" fill="#eaf1ff"/>+ <rect x="27.5" y="43" width="9" height="2.6" rx="1.3" fill="#7aa7f7"/>+ <rect x="27.5" y="47.5" width="6" height="2.6" rx="1.3" fill="#5f8ff0"/>+</svg>diff --git a/plugins/lesson-video/package.json b/plugins/lesson-video/package.jsonnew file mode 100644index 00000000..f60c5400--- /dev/null+++ b/plugins/lesson-video/package.json@@ -0,0 +1,33 @@+{+ "name": "@lmliheng/lesson-video",+ "version": "0.3.1",+ "description": "Narrated vertical lesson videos (1080x1920) from a script: an HTML slide deck driven by time, edge-tts voice-over with word-level timing, Playwright frame capture, ffmpeg mux, cover art and publishing copy.",+ "license": "Apache-2.0",+ "repository": {+ "type": "git",+ "url": "git+https://github.com/lmliheng/Adelie.git",+ "directory": "plugins/lesson-video"+ },+ "keywords": [+ "adelie-plugin",+ "penguin-harness",+ "video",+ "1080x1920",+ "vertical",+ "tts",+ "edge-tts",+ "playwright",+ "ffmpeg",+ "slides"+ ],+ "files": [+ "plugin.json",+ "icon.svg",+ "README.md",+ "skills",+ "LICENSE"+ ],+ "publishConfig": {+ "access": "public"+ }+}diff --git a/plugins/lesson-video/plugin.json b/plugins/lesson-video/plugin.jsonnew file mode 100644index 00000000..2110a462--- /dev/null+++ b/plugins/lesson-video/plugin.json@@ -0,0 +1,9 @@+{+ "description": "Produce a narrated vertical lesson video (1080x1920) and its cover art from a written script: an HTML slide deck driven purely by time, edge-tts voice-over with word-level timing, Playwright frame capture, and an ffmpeg mux with edge safe areas left empty for mobile app buttons — plus a pre-render self-check for text overflow, and publishing copy with at most five tags.",+ "description_zh": "把写好的讲稿做成竖屏教学视频(1080×1920)与配套封面:HTML 课件按时间轴定格、edge-tts 逐词对齐配音、Playwright 逐帧截图、ffmpeg 合成,两侧与上部按手机 App 按钮留出安全区,渲染前先自检越界与裁切,并给出标签不超过五个的发布文案。",+ "short_description": "Narrated 1080x1920 lesson video from a script: HTML deck + edge-tts + ffmpeg.",+ "short_description_zh": "讲稿一键成竖屏教学视频(1080×1920):HTML 课件 + edge-tts + ffmpeg,含封面与发布文案。",+ "version": "2026.10.06.1",+ "category": "office-productivity",+ "preinstall": false+}diff --git a/plugins/lesson-video/skills/lesson-video/SKILL.md b/plugins/lesson-video/skills/lesson-video/SKILL.mdnew file mode 100644index 00000000..6e7d2647--- /dev/null+++ b/plugins/lesson-video/skills/lesson-video/SKILL.md@@ -0,0 +1,172 @@+---+name: lesson-video+description: Turn a narration script into a narrated vertical lesson video (1080x1920, Douyin/Reels ready) plus matching cover art — an HTML slide deck driven purely by time, edge-tts voice-over with word-level timing, Playwright frame capture, and an ffmpeg mux with burned-out safe areas. Use whenever the task is to produce a short portrait teaching or explainer video, a narrated slide video, or its cover and publishing copy, from a written script or from source material such as a notebook, dataset or paper.+---++# 竖屏教学视频:讲稿 → 配音 → 逐帧渲染 → 成片 + 封面++## Before you start++如果消息只是点名这个技能(比如「用 lesson-video」)而没有具体要讲的内容,先问清楚讲什么、给谁看、+一集多长——**先有话,再有画面**,没有讲稿就没有可渲染的东西。有内容时先自检三样东西在不在:Python+包(`edge-tts`、`imageio-ffmpeg`)、一个可用的 `playwright-core`、一个 Chrome/Chromium 可执行文件;+缺哪个按第一节的表装哪个,别急着渲染。渲染是最后一步,不是第一步:`render.mjs --check` 先过一遍,+再花那几分钟出帧。++## 结论先行++一句话:**画面是时间 t 的纯函数**。先用话把内容说清楚,把每一句话写成脚本,配音合成后拿到逐词时间,画面按这个时间去定格 —— 于是配音、字幕、画面天然咬合,不需要剪辑。++| 你要的东西 | 用哪一步 | 产物 |+| --- | --- | --- |+| 一份讲稿 | 手写 `lessons/<集>/script.json` | 分镜 + 旁白 + 出现时机(`cue`) |+| 配音 + 时间轴 | `python lib/tts.py lessons/<集>` | `audio/narration.wav`、`lesson.json` |+| 逐帧画面 | `node lib/render.mjs --dir lessons/<集>` | `frames/f_00000.jpg…` (30fps) |+| 成片 + 字幕 | `python lib/build.py lessons/<集>` | `out/<id>.mp4`、`<id>.srt` |+| 封面 | `node lib/cover.mjs --data covers/covers.json --out covers/out --sizes 1920,1440` | 1080×1920 与 1080×1440 两张 PNG |++写成一条链(GPU 无关,纯 CPU,3 分钟的片子约 5 分钟出片):++```bash+python lib/tts.py lessons/ep01 && \+node lib/render.mjs --dir lessons/ep01 && \+python lib/build.py lessons/ep01+```++**动手前先跑自检**(10 秒,不出帧):++```bash+node lib/render.mjs --dir lessons/ep01 --check+```++它报三件事:内容有没有越过 y=1470 的字幕安全线、代码行有没有被卡片裁掉、标题折行有没有剩下孤字。三项全过再花几分钟渲染。++## 一、把工具包放进项目++技能目录里的 `kit/` 就是全部工具,复制到项目下当 `lib/` 用:++```bash+mkdir -p <项目>/lessons/<集名> <项目>/covers+cp -r <技能目录>/kit/* <项目>/lib/+```++`kit/` 六个文件,各管一件事:++| 文件 | 作用 |+| --- | --- |+| `tts.py` | edge-tts 逐幕配音,拿逐词边界,写出 `lesson.json`(时间轴 + 字幕)+ `narration.wav` |+| `render.mjs` | Playwright 逐帧截图;`--check` 只自检;`--scale 0.5` 低清预览 |+| `build.py` | ffmpeg 合成 H.264/AAC、响度归一、`+faststart`,顺带写 SRT |+| `deck.html` | 课件本体,一种 1080×1920 版式,幕类型见第三节 |+| `cover.mjs` / `cover.html` | 封面图(9:16 视频首图 + 3:4 主页封面) |++**依赖**(缺哪个装哪个):++| 依赖 | 装法 | 备注 |+| --- | --- | --- |+| Python 包 | `pip install edge-tts imageio-ffmpeg` | `imageio-ffmpeg` 自带 ffmpeg 二进制,不用单独装 ffmpeg |+| Node 包 | 任意可用的 `playwright-core` | 用 `PLAYWRIGHT_MODULE` 指到它的路径即可,不必装进本项目 |+| 浏览器 | 任意 Chrome / Chromium 可执行文件 | 用 `CHROME_PATH` 指过去 |++两个环境变量(Windows / Linux 都一样,`render.mjs` 与 `cover.mjs` 都认):++```bash+PLAYWRIGHT_MODULE=/path/to/node_modules/playwright-core \+CHROME_PATH=/path/to/chrome.exe \+ node lib/render.mjs --dir lessons/ep01+```++## 二、脚本 `script.json` 怎么写++顶层字段:++| 字段 | 含义 |+| --- | --- |+| `id` | 集目录名与成片名(`out/<id>.mp4`),如 `ep01-regression` |+| `series` / `episode` / `brand` | 系列名 / 集标题(只在日志里用)/ **画面左上台标文字** |+| `wm` | 画面右上角水印文字;不给就整块隐藏(模板里没有任何固定文案) |+| `mark` | 台标方块的字母;不给就取 `brand` 的首字 |+| `voice` / `rate` | edge-tts 音色与语速,如 `zh-CN-YunxiNeural` / `+18%` |+| `gap` | 每幕之间的静音秒数,默认 0.35;一口气讲完的系列用 0.3 |+| `scenes` | 幕数组,见下 |++每一幕:`id`(幕内短名,用来命名音频)、`type`(版式)、`narration`(**这一集真正要讲的话**),其余字段按 `type` 取。++| `type` | 特有字段 | 用途 |+| --- | --- | --- |+| `title` | `kicker` `title` `sub` `tags[]` | 开场:大标题 + 一句副标题 + 三两个标签 |+| `points` | `kicker` `title` `items[]` | 要点幕,`<em>` 标蓝关键词 |+| `math` | `kicker` `title` `steps[{label,formula,hi}]` | 公式卡,`hi: true` 把某张卡高亮;≥4 张自动切紧凑版式 |+| `code` | `kicker` `title` `file` `code` `code_reveal` | 代码卡,`code` 用 `\n` 分行,逐行出现 |+| `source` | 同 `code`,另加 `notes[]` | 代码 + 下方 2–3 条注记(读库源码时用) |+| `outro` | `kicker` `title` `sub` `cta` | 结尾 + CTA 按钮 |++### 出现时机:写 `cue`,不写秒数++任何元素上写 `"cue": "关键词"`,`tts.py` 会在**配音的逐词时间**里找这个关键词,把元素出现的时刻标成 `at`(相对本幕秒数,比人声早 0.15s)。++- 关键词必须**真的出现在同一幕的 `narration` 里**(`cue_time` 按去掉空白的字符流做子串匹配),否则静默失败、元素永不出现;+- 想要 CTA 晚点出,就写 `"cta_cue": "关注"` —— 任何 `<名>_cue` 都会解析成 `<名>_at`;+- 已经手写了 `at` 的不会被覆盖,两种写法可以混用;+- 中文数字按念法写关键词:旁白念「负二点三四」,cue 就写 `负二点三四`,别写 `-2.34`。++### 字数与节奏(实测)++中文旁白约 **5.9 字/秒**(`rate` 为 `+18%`、`zh-CN-YunxiNeural`)——**3 分钟 ≈ 1070 字**,按这个数分配每一幕。写完先估一遍,别等合成完才发现超时。++## 三、画面规矩(都在 `kit/deck.html` 里,改一处全片生效)++**安全区**:抖音等 App 的按钮、状态栏会压住画面边缘,所以两侧和上部必须留白。当前版式:++| 位置 | 数值 |+| --- | --- |+| 场景内边距 | `padding: 300px 185px 450px 150px`(上 / 右 / 下 / 左) |+| 内容可用区 | 宽 **745px**、高 **1170px**(y=300 → y=1470) |+| 左上台标 | `left:150px; top:172px` |+| 右上水印 | `right:178px; top:180px` |+| 字幕带 | y=1470 起,两行 46px/36px,居中 860px 宽 |++由此推出两条硬约束:++1. **内容底边 < 1470**(否则盖住字幕);+2. **代码行 ≤ 约 55 个西文字符**(卡片内宽 697px ÷ 等宽字体 12.65px/字;实测 51 字符安全)。代码里长行放不下就换行、或把变量名缩短,别指望它自己折 —— `.card-bd` 是 `overflow:hidden`,超了会被**悄悄裁掉**。++另外两点:++- `kicker` 会被 CSS `text-transform:uppercase`,**别在 kicker 里写希腊字母或中文以外的敏感字形**;+- 标题用了 `text-wrap:balance`,折行时左右均衡,避免最后一行只剩一两个字。++## 四、封面 `covers.json` + `covers/out/`++```bash+PLAYWRIGHT_MODULE=… CHROME_PATH=… \+ node lib/cover.mjs --data covers/covers.json --out covers/out --sizes 1920,1440+```++每条封面一个对象:`id`(文件名前缀)`no`(集号,右上角大数字)`brand` `wm` `cta` `titleLines[]`(**自己写好断行**,最后一行自动标蓝)`subLines[]`(每行别超过约 20 字,多了会折成三行)`pills[]`(三个标签)`tag`(可选,接在「第 N 集」后面)`foot`(左下角一行)。++一次出两张:`<id>-9x16.png`(1080×1920,视频首图)和 `<id>-1080x1440.png`(1080×1440,主页封面)。++## 五、发布物料++写进项目的 `covers/copy.md`,一集一段:**标题**(一句话,最好带一个真实数字)、**文案**(三行要点 + 每行一句解释)、**标签**。++- 抖音描述**标签最多 5 个**(如 `#Kaggle #机器学习 #分类 #逻辑回归 #Python`),多了不显示;+- 文案里的数字**必须是片子里真跑出来的**,不要编——这一条比排版重要得多。++## 六、踩过的坑++1. **Python 找不到 stdout 编码(Windows)**:控制台是 GBK,任何 `print` 中文或 `python -c` 都会 `UnicodeEncodeError`。所有 Python 调用前加 `PYTHONUTF8=1`。+2. **`edge-tts` 偶尔空手而归**(`NoAudioReceived`):`tts.py` 里已带 4 次重试,别自己再包一层;真的是网络断了再排查。+3. **必须显式要 `boundary="WordBoundary"`**:edge-tts 7.x 默认按句返回边界,拿不到逐词时间,字幕就贴不上人声。+4. **Python 写回的 JSON 是 CRLF**:要改已经生成过的 `lesson.json`,别用文本替换,改用 Python 脚本读写。+5. **帧序列很占地方**:3 分钟的片子约 1.5 GB(5511 张 JPEG)。确认成片没问题后可以删 `lessons/<集>/frames/`,要重渲再跑一次 `render.mjs`。+6. **渲染前千万别跳过 `--check`**:内容越线、代码被裁、标题孤字,这三类问题在成片里很难发现,在自检里一眼就能看到。+7. **帧数与时间轴不符**:`build.py` 会比对帧数与 `duration × fps`,差超过 2 帧就报警 —— 那通常说明渲染中途被打断了,重渲。+8. **`PLAYWRIGHT_MODULE` 指的必须是 playwright-core 的目录**(含 `package.json` 的那层),不是 `playwright`。++## 七、边界++- 画面是**时间 t 的纯函数**,没有 CSS 过渡、没有随机数:同一份 `script.json` 每次渲染结果一致,改一句话重渲即可,不需要剪辑软件。+- 这套版式只做 1080×1920 竖屏;横屏或方形要另做版式(`deck.html` 的 `html,body` 宽高与场景内边距是硬编码的)。+- 配音只走 edge-tts(免费、无需密钥)。要换别的 TTS,替换 `tts.py` 里的 `synth()` 即可,其余步骤不用动。diff --git a/plugins/lesson-video/skills/lesson-video/example/covers.json b/plugins/lesson-video/skills/lesson-video/example/covers.jsonnew file mode 100644index 00000000..64118c50--- /dev/null+++ b/plugins/lesson-video/skills/lesson-video/example/covers.json@@ -0,0 +1,14 @@+[+ {+ "id": "demo-gap",+ "no": "1",+ "brand": "示例教程 · 1 集",+ "wm": "@GitHub/your-handle",+ "cta": "关注抖音号 your-handle",+ "titleLines": ["一句话", "讲一件事"],+ "subLines": ["两行副标题,每行别超过二十来个字", "第二行放一个真实数字"],+ "pills": ["标签一", "标签二", "标签三"],+ "tag": "示例",+ "foot": "示例系列 · 第 1 集"+ }+]diff --git a/plugins/lesson-video/skills/lesson-video/example/script.json b/plugins/lesson-video/skills/lesson-video/example/script.jsonnew file mode 100644index 00000000..ee515c54--- /dev/null+++ b/plugins/lesson-video/skills/lesson-video/example/script.json@@ -0,0 +1,53 @@+{+ "id": "demo-gap",+ "series": "示例系列",+ "episode": "第 1 集 · 示例",+ "brand": "示例教程 · 1 集",+ "wm": "@GitHub/your-handle",+ "voice": "zh-CN-YunxiNeural",+ "rate": "+18%",+ "gap": 0.3,+ "scenes": [+ {+ "id": "s1",+ "type": "title",+ "kicker": "第 1 集 · 示例",+ "title": "一集三分钟,讲清一件事",+ "sub": "标题、要点、代码,三幕都要有",+ "tags": ["示例", "竖屏", "课件"],+ "narration": "这一集是模板示例。三分钟讲一件事,画面由时间轴驱动,配音和字幕都是从同一份脚本里长出来的。"+ },+ {+ "id": "s2",+ "type": "points",+ "kicker": "01 · 要点",+ "title": "要点幕:三行字就够",+ "items": [+ "每行一句话,<em>关键词</em>用 em 标蓝",+ "cue 写在 content 上,配音念到就出现",+ "整幕内容不能越过 y=1470 的字幕安全线"+ ],+ "narration": "要点幕放三行就够。关键词用 em 标出来,配音念到哪个词,哪一行就跟着出现,不用手算时间。"+ },+ {+ "id": "s3",+ "type": "code",+ "kicker": "02 · 代码",+ "title": "代码幕:行宽是关键",+ "file": "demo.py",+ "code": "def hello(name):\n return f\"hi {name}\"",+ "code_reveal": 3,+ "narration": "代码幕要注意行宽,太长的行会被卡片裁掉,渲染前的自检会告你哪一行越界。"+ },+ {+ "id": "s4",+ "type": "outro",+ "kicker": "下一集",+ "title": "把标题写在这里",+ "sub": "副标题写一句就够了",+ "cta": "关注抖音号 your-handle",+ "cta_cue": "关注",+ "narration": "好,这一集就到这。关注我,下一集见。"+ }+ ]+}diff --git a/plugins/lesson-video/skills/lesson-video/kit/build.py b/plugins/lesson-video/skills/lesson-video/kit/build.pynew file mode 100644index 00000000..3cce64c8--- /dev/null+++ b/plugins/lesson-video/skills/lesson-video/kit/build.py@@ -0,0 +1,78 @@+"""把帧序列 + 配音轨 + 字幕合成成竖屏 MP4(1080x1920,H.264/AAC,抖音可直传)。++用法: python lib/build.py lessons/ep00-pilot [--out out/pilot.mp4]+"""+from __future__ import annotations++import argparse+import json+import subprocess+from pathlib import Path++import imageio_ffmpeg++FFMPEG = imageio_ffmpeg.get_ffmpeg_exe()+++def srt_time(sec: float) -> str:+ ms = int(round(sec * 1000))+ h, ms = divmod(ms, 3600_000)+ m, ms = divmod(ms, 60_000)+ s, ms = divmod(ms, 1000)+ return f"{h:02d}:{m:02d}:{s:02d},{ms:03d}"+++def write_srt(subs: list[dict], path: Path) -> None:+ lines = []+ for i, s in enumerate(subs, 1):+ lines += [str(i), f"{srt_time(s['start'])} --> {srt_time(s['end'])}", s["text"], ""]+ path.write_text("\n".join(lines), encoding="utf-8")+++def main() -> None:+ ap = argparse.ArgumentParser()+ ap.add_argument("dir")+ ap.add_argument("--out")+ ap.add_argument("--crf", type=int, default=18)+ args = ap.parse_args()++ d = Path(args.dir).resolve()+ lesson = json.loads((d / "lesson.json").read_text(encoding="utf-8"))+ frames = sorted((d / "frames").glob("f_*.jpg"))+ if not frames:+ raise SystemExit(f"没有帧,先跑 render.mjs:{d / 'frames'}")+ audio = d / "audio" / "narration.wav"+ out = Path(args.out) if args.out else d / "out" / f"{lesson['meta']['id']}.mp4"+ if not out.is_absolute():+ out = d / out+ out.parent.mkdir(parents=True, exist_ok=True)++ fps = lesson["fps"]+ expect = round(lesson["duration"] * fps)+ if abs(len(frames) - expect) > 2:+ print(f"⚠ 帧数与时间轴不符:{len(frames)} vs {expect}")++ write_srt(lesson["subtitles"], out.with_suffix(".srt"))++ cmd = [+ FFMPEG, "-y", "-hide_banner", "-loglevel", "error",+ "-framerate", str(fps), "-start_number", "0", "-i", str(d / "frames" / "f_%05d.jpg"),+ "-i", str(audio),+ # JPEG 帧是全范围,转成广播标准的 limited range + bt709,避免平台转码后发灰+ "-vf", "scale=in_range=full:out_range=tv,format=yuv420p",+ "-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709",+ "-c:v", "libx264", "-preset", "slow", "-crf", str(args.crf),+ "-profile:v", "high", "-level", "4.2",+ # 社媒响度:-14 LUFS / 真峰值 -1.5 dBTP+ "-af", "loudnorm=I=-14:TP=-1.5:LRA=11",+ "-c:a", "aac", "-b:a", "192k", "-ar", "48000", "-ac", "1",+ "-shortest", "-movflags", "+faststart",+ str(out),+ ]+ subprocess.run(cmd, check=True)+ print(f"OK {out} {out.stat().st_size / 1024**2:.1f} MB "+ f"{lesson['duration']:.1f}s @ {fps}fps 字幕 {out.with_suffix('.srt').name}")+++if __name__ == "__main__":+ main()diff --git a/plugins/lesson-video/skills/lesson-video/kit/cover.html b/plugins/lesson-video/skills/lesson-video/kit/cover.htmlnew file mode 100644index 00000000..65c88d15--- /dev/null+++ b/plugins/lesson-video/skills/lesson-video/kit/cover.html@@ -0,0 +1,257 @@+<!doctype html>+<html lang="zh-CN">+ <head>+ <meta charset="utf-8" />+ <title>Kaggle 房价预测 · 封面</title>+ <style>+ /* 竖屏封面:与课件同一套视觉语言(纯黑 + 点阵 + 单一蓝强调),一帧定格、无动画 */+ :root {+ --bg: #000;+ --surface: #0d0d0d;+ --border: #1f1f1f;+ --border-2: #303030;+ --fg: #f3f4f6;+ --fg-muted: #9ca3af;+ --fg-faint: #6b7280;+ --brand: #8ab4f8;+ --brand-deep: #4285f4;+ --brand-tint: #1a2b45;+ }+ * {+ box-sizing: border-box;+ -webkit-font-smoothing: antialiased;+ }+ html,+ body {+ margin: 0;+ padding: 0;+ width: 1080px;+ height: 100%;+ overflow: hidden;+ background: var(--bg);+ color: var(--fg);+ font-family:+ "Microsoft YaHei", "PingFang SC", ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;+ }++ #grid {+ position: absolute;+ inset: 0;+ background-image: radial-gradient(rgba(138, 180, 248, 0.12) 1.8px, transparent 1.8px);+ background-size: 76px 76px;+ }+ #num {+ position: absolute;+ right: -70px;+ bottom: -190px;+ font-size: 900px;+ font-weight: 700;+ line-height: 0.78;+ color: rgba(66, 133, 244, 0.11);+ letter-spacing: -0.06em;+ user-select: none;+ }++ #top {+ position: absolute;+ left: 96px;+ right: 150px;+ top: 104px;+ display: flex;+ align-items: center;+ justify-content: space-between;+ }+ #brand {+ display: flex;+ align-items: center;+ gap: 18px;+ font-size: 32px;+ color: var(--fg-faint);+ letter-spacing: 0.02em;+ }+ #brand .mark {+ width: 44px;+ height: 44px;+ border-radius: 12px 12px 12px 5px;+ background: var(--brand-deep);+ display: flex;+ align-items: center;+ justify-content: center;+ font-size: 28px;+ font-weight: 700;+ color: #08111f;+ }+ #wm {+ font-size: 26px;+ color: var(--fg-faint);+ opacity: 0.55;+ font-family: Consolas, "Cascadia Mono", ui-monospace, SFMono-Regular, Menlo, monospace;+ }++ #mid {+ position: absolute;+ left: 96px;+ right: 120px;+ top: 0;+ bottom: 0;+ display: flex;+ flex-direction: column;+ justify-content: center;+ gap: 0;+ }+ .badge {+ align-self: flex-start;+ background: var(--brand-tint);+ color: var(--brand);+ font-size: 38px;+ font-weight: 600;+ letter-spacing: 0.06em;+ padding: 14px 34px;+ border-radius: 9999px;+ margin-bottom: 52px;+ }+ .title {+ font-size: 134px;+ font-weight: 600;+ letter-spacing: -0.045em;+ line-height: 1.12;+ margin: 0;+ }+ .title .ln {+ display: block;+ }+ .title .hi {+ color: var(--brand);+ }+ .rule {+ width: 230px;+ height: 7px;+ background: var(--brand-deep);+ border-radius: 4px;+ margin: 56px 0 44px;+ }+ .sub {+ font-size: 48px;+ line-height: 1.42;+ color: var(--fg-muted);+ margin: 0;+ }+ .sub .ln {+ display: block;+ }+ .pills {+ display: flex;+ flex-wrap: wrap;+ gap: 18px;+ margin-top: 54px;+ }+ .pill {+ border: 1px solid var(--border-2);+ border-radius: 9999px;+ padding: 14px 32px;+ font-size: 34px;+ color: var(--fg-muted);+ }++ #foot {+ position: absolute;+ left: 96px;+ right: 150px;+ bottom: 110px;+ display: flex;+ align-items: center;+ justify-content: space-between;+ font-size: 36px;+ color: var(--fg-muted);+ }+ #foot .cta {+ background: var(--fg);+ color: #111827;+ font-weight: 600;+ border-radius: 10px;+ padding: 18px 42px;+ font-size: 34px;+ }++ /* 主页 3:4 版:内容居中不变,只把字号与留白收一点,避免上下被裁 */+ .h34 .title {+ font-size: 118px;+ }+ .h34 .sub {+ font-size: 44px;+ }+ .h34 .badge {+ font-size: 34px;+ margin-bottom: 44px;+ }+ .h34 .rule {+ margin: 46px 0 38px;+ }+ .h34 .pills {+ margin-top: 46px;+ }+ .h34 #foot {+ bottom: 80px;+ }+ .h34 #num {+ font-size: 760px;+ bottom: -160px;+ }+ </style>+ </head>+ <body>+ <div id="grid"></div>+ <div id="num"></div>+ <div id="top">+ <div id="brand"><span class="mark" id="brand-mark"></span><span id="brand-text"></span></div>+ <div id="wm"></div>+ </div>+ <div id="mid">+ <div class="badge" id="badge"></div>+ <h1 class="title" id="title"></h1>+ <div class="rule"></div>+ <p class="sub" id="sub"></p>+ <div class="pills" id="pills"></div>+ </div>+ <div id="foot">+ <span id="foot-left"></span>+ <span class="cta" id="cta"></span>+ </div>+ <script>+ "use strict";+ const esc = (s) =>+ String(s).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");+ window.__init = function (c, size) {+ if (size === "3x4") document.body.classList.add("h34");+ const brand = c.brand || "";+ document.getElementById("brand-text").textContent = brand;+ // 台标字母 / 右上角水印 / 右下角 CTA 都从数据来:没给就自动取首字、或整块隐藏+ document.getElementById("brand-mark").textContent =+ c.mark || brand.trim().slice(0, 1) || "▶";+ const wm = document.getElementById("wm");+ wm.textContent = c.wm || "";+ wm.style.display = c.wm ? "" : "none";+ const cta = document.getElementById("cta");+ cta.textContent = c.cta || "";+ cta.style.display = c.cta ? "" : "none";+ document.getElementById("badge").textContent =+ "第 " + c.no + " 集" + (c.tag ? " · " + c.tag : "");+ document.getElementById("title").innerHTML = c.titleLines+ .map(+ (l, i) =>+ `<span class="ln${i === c.titleLines.length - 1 && c.hiLast !== false ? " hi" : ""}">${esc(l)}</span>`,+ )+ .join("");+ document.getElementById("sub").innerHTML = c.subLines+ .map((l) => `<span class="ln">${esc(l)}</span>`)+ .join("");+ document.getElementById("pills").innerHTML = c.pills+ .map((p) => `<span class="pill">${esc(p)}</span>`)+ .join("");+ document.getElementById("num").textContent = c.no;+ document.getElementById("foot-left").textContent = c.foot || "Kaggle 房价预测 · 16 集";+ document.title = c.no + " " + c.titleLines.join("");+ };+ </script>+ </body>+</html>diff --git a/plugins/lesson-video/skills/lesson-video/kit/cover.mjs b/plugins/lesson-video/skills/lesson-video/kit/cover.mjsnew file mode 100644index 00000000..1d4f8e3f--- /dev/null+++ b/plugins/lesson-video/skills/lesson-video/kit/cover.mjs@@ -0,0 +1,64 @@+#!/usr/bin/env node+/**+ * 把 covers/covers.json 渲染成抖音封面图:9:16(1080×1920,视频首图)与 3:4(1080×1440,主页封面)。+ *+ * 用法:+ * PLAYWRIGHT_MODULE=<pw-core 路径> CHROME_PATH=<chrome.exe> \+ * node lib/cover.mjs --data covers/covers.json --out covers/out [--sizes 1920,1440]+ */+import fs from "node:fs";+import path from "node:path";+import { createRequire } from "node:module";+import { fileURLToPath, pathToFileURL } from "node:url";++const require = createRequire(import.meta.url);+const HERE = path.dirname(fileURLToPath(import.meta.url));+const pw = require(process.env.PLAYWRIGHT_MODULE || "playwright-core");+const CHROME = process.env.CHROME_PATH || "";++const argv = process.argv.slice(2);+const arg = (k, d) => {+ const i = argv.indexOf(k);+ return i >= 0 ? argv[i + 1] : d;+};++const dataFile = path.resolve(arg("--data", "covers/covers.json"));+const outDir = path.resolve(arg("--out", "covers/out"));+const sizes = arg("--sizes", "1920,1440")+ .split(",")+ .map((s) => parseInt(s, 10));+const W = 1080;++const covers = JSON.parse(fs.readFileSync(dataFile, "utf8"));+fs.mkdirSync(outDir, { recursive: true });++const browser = await pw.chromium.launch({+ executablePath: CHROME || undefined,+ args: [+ "--no-sandbox",+ "--disable-dev-shm-usage",+ "--hide-scrollbars",+ "--force-color-profile=srgb",+ ],+});++for (const c of covers) {+ for (const H of sizes) {+ const size = H === 1920 ? "9x16" : `${W}x${H}`;+ const ctx = await browser.newContext({+ viewport: { width: W, height: H },+ deviceScaleFactor: 1,+ });+ const page = await ctx.newPage();+ await page.addInitScript(`window.__COVER__ = ${JSON.stringify(c)};`);+ await page.goto(pathToFileURL(path.join(HERE, "cover.html")).href, { waitUntil: "load" });+ await page.evaluate((s) => window.__init(window.__COVER__, s), H === 1440 ? "3x4" : "9x16");+ await page.evaluate(() => document.fonts.ready);+ const file = path.join(outDir, `${c.id}-${size}.png`);+ await page.screenshot({ path: file });+ await ctx.close();+ console.log(`OK ${file} ${W}x${H}`);+ }+}++await browser.close();diff --git a/plugins/lesson-video/skills/lesson-video/kit/deck.html b/plugins/lesson-video/skills/lesson-video/kit/deck.htmlnew file mode 100644index 00000000..615228e6--- /dev/null+++ b/plugins/lesson-video/skills/lesson-video/kit/deck.html@@ -0,0 +1,632 @@+<!doctype html>+<html lang="zh-CN">+ <head>+ <meta charset="utf-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1" />+ <title>Kaggle 房价预测 · 竖屏课件</title>+ <style>+ /* 1080x1920 竖屏课件:所有样式都从时间 t 计算,不含 CSS 过渡,保证逐帧可复现 */+ :root {+ --bg: #000;+ --surface: #0d0d0d;+ --border: #1f1f1f;+ --border-2: #303030;+ --fg: #f3f4f6;+ --fg-muted: #9ca3af;+ --fg-faint: #6b7280;+ --brand: #8ab4f8;+ --brand-deep: #4285f4;+ --brand-tint: #1a2b45;+ --amber: #f0b429;+ --ease: cubic-bezier(0.2, 0.7, 0.3, 1);+ }+ * {+ box-sizing: border-box;+ -webkit-font-smoothing: antialiased;+ }+ html,+ body {+ margin: 0;+ padding: 0;+ width: 1080px;+ height: 1920px;+ overflow: hidden;+ background: var(--bg);+ color: var(--fg);+ font-family:+ "Microsoft YaHei", "PingFang SC", ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;+ }+ code,+ pre,+ .mono {+ font-family: Consolas, "Cascadia Mono", ui-monospace, SFMono-Regular, Menlo, monospace;+ }++ /* 常驻背景:点阵网格,随整条片子极缓慢平移 —— 页面切换时的“连续性”来源 */+ #bg {+ position: absolute;+ inset: 0;+ background-image: radial-gradient(rgba(138, 180, 248, 0.1) 1.6px, transparent 1.6px);+ background-size: 72px 72px;+ }++ #bar {+ position: absolute;+ left: 0;+ top: 0;+ width: 1080px;+ height: 8px;+ background: #141414;+ z-index: 40;+ }+ #barfill {+ height: 100%;+ width: 0;+ background: var(--brand-deep);+ }++ #brand {+ position: absolute;+ left: 150px;+ top: 172px;+ z-index: 35;+ display: flex;+ align-items: center;+ gap: 18px;+ font-size: 30px;+ color: var(--fg-faint);+ letter-spacing: 0.02em;+ }+ #brand .mark {+ width: 38px;+ height: 38px;+ border-radius: 10px 10px 10px 4px;+ background: var(--brand-deep);+ display: flex;+ align-items: center;+ justify-content: center;+ font-size: 24px;+ font-weight: 700;+ color: #08111f;+ }+ /* 常驻水印:右上角,与正文右边界对齐 */+ #wm {+ position: absolute;+ right: 178px;+ top: 180px;+ z-index: 35;+ font-size: 26px;+ letter-spacing: 0.02em;+ color: var(--fg-faint);+ opacity: 0.62;+ font-family: Consolas, "Cascadia Mono", ui-monospace, SFMono-Regular, Menlo, monospace;+ }++ .scene {+ position: absolute;+ left: 0;+ top: 0;+ width: 1080px;+ height: 1920px;+ padding: 300px 185px 450px 150px;+ display: none;+ flex-direction: column;+ justify-content: flex-start;+ will-change: transform, opacity;+ }+ .scene.on {+ display: flex;+ }+ .scene.center {+ justify-content: center;+ padding-bottom: 620px;+ }++ .kicker {+ font-size: 30px;+ letter-spacing: 0.2em;+ text-transform: uppercase;+ color: var(--brand);+ margin-bottom: 30px;+ }+ /* text-wrap:balance —— 标题折行时左右均衡,避免最后一行只剩一两个字(安全区变窄后尤其明显) */+ .stitle {+ font-size: 68px;+ font-weight: 600;+ letter-spacing: -0.025em;+ line-height: 1.24;+ margin: 0 0 62px;+ text-wrap: balance;+ }++ /* 开场 */+ .hero {+ font-size: 132px;+ font-weight: 600;+ letter-spacing: -0.045em;+ line-height: 1.06;+ margin: 0 0 30px;+ text-wrap: balance;+ }+ .hero-sub {+ font-size: 48px;+ color: var(--fg-muted);+ line-height: 1.5;+ margin: 0 0 54px;+ }+ .rule {+ width: 220px;+ height: 5px;+ background: var(--brand-deep);+ border-radius: 3px;+ margin-bottom: 48px;+ }+ .tags {+ display: flex;+ flex-wrap: wrap;+ gap: 16px;+ }+ .tag {+ border: 1px solid var(--border-2);+ border-radius: 9999px;+ padding: 12px 26px;+ font-size: 32px;+ color: var(--fg-muted);+ }++ /* 要点 */+ .item {+ display: flex;+ gap: 26px;+ align-items: flex-start;+ border: 1px solid var(--border);+ border-radius: 14px;+ background: var(--surface);+ padding: 34px 38px;+ margin-bottom: 30px;+ }+ .item .dot {+ flex: 0 0 auto;+ width: 16px;+ height: 16px;+ border-radius: 9999px;+ background: var(--brand-deep);+ margin-top: 20px;+ }+ .item .tx {+ font-size: 42px;+ line-height: 1.5;+ }+ .item .tx em {+ font-style: normal;+ color: var(--brand);+ }++ /* 数学 */+ .formula-card {+ border: 1px solid var(--border);+ border-radius: 14px;+ background: var(--surface);+ padding: 38px 40px;+ margin-bottom: 32px;+ border-left: 6px solid var(--border-2);+ }+ .formula-card.hi {+ border-left-color: var(--brand-deep);+ background: var(--brand-tint);+ }+ .fc-label {+ font-size: 30px;+ color: var(--fg-faint);+ margin-bottom: 22px;+ }+ .fc-body {+ font-size: 50px;+ line-height: 1.6;+ color: var(--fg);+ }+ .fc-body sup,+ .fc-body sub {+ font-size: 0.62em;+ }+ .frac {+ display: inline-flex;+ flex-direction: column;+ vertical-align: middle;+ text-align: center;+ margin: 0 6px;+ font-size: 0.78em;+ line-height: 1.15;+ }+ .frac b {+ font-weight: 600;+ border-bottom: 2px solid currentColor;+ padding: 0 8px;+ }+ .frac i {+ font-style: normal;+ padding: 0 8px;+ }++ /* 密集型:公式卡 ≥4 张时收紧,保证不越过 y=1470 的字幕安全线 */+ .scene.dense .stitle {+ font-size: 56px;+ margin-bottom: 36px;+ }+ .scene.dense .formula-card {+ padding: 22px 32px;+ margin-bottom: 18px;+ }+ .scene.dense .fc-label {+ font-size: 24px;+ margin-bottom: 10px;+ }+ .scene.dense .fc-body {+ font-size: 38px;+ line-height: 1.5;+ }++ /* 代码 */+ .card {+ border: 1px solid var(--border);+ border-radius: 14px;+ background: var(--surface);+ overflow: hidden;+ }+ .card-hd {+ display: flex;+ align-items: center;+ gap: 12px;+ padding: 20px 26px;+ border-bottom: 1px solid var(--border);+ font-size: 26px;+ color: var(--fg-faint);+ }+ .card-hd .dots {+ display: flex;+ gap: 9px;+ }+ .card-hd .dots i {+ width: 14px;+ height: 14px;+ border-radius: 9999px;+ background: var(--border-2);+ display: block;+ }+ .card-bd {+ padding: 22px 24px 26px;+ font-size: 23px;+ line-height: 1.7;+ white-space: pre;+ overflow: hidden;+ }+ .ln {+ display: block;+ }+ .k {+ color: #ff7b72;+ } /* keyword */+ .s {+ color: #a5d6ff;+ } /* string */+ .c {+ color: #6b7280;+ } /* comment */+ .n {+ color: #79c0ff;+ } /* number */+ .f {+ color: #d2a8ff;+ } /* call */+ .m {+ color: var(--fg-muted);+ }++ .notes {+ margin-top: 30px;+ }+ .note {+ display: flex;+ gap: 20px;+ font-size: 32px;+ color: var(--fg-muted);+ line-height: 1.55;+ margin-bottom: 18px;+ }+ .note .n-dot {+ flex: 0 0 auto;+ width: 12px;+ height: 12px;+ border-radius: 9999px;+ background: var(--brand);+ margin-top: 16px;+ }++ /* 结尾 */+ .outro {+ font-size: 104px;+ font-weight: 600;+ letter-spacing: -0.04em;+ line-height: 1.12;+ margin: 0 0 28px;+ text-wrap: balance;+ }+ .outro-sub {+ font-size: 44px;+ color: var(--fg-muted);+ margin: 0 0 64px;+ }+ .cta {+ display: inline-block;+ background: var(--fg);+ color: #111827;+ font-size: 40px;+ font-weight: 600;+ border-radius: 10px;+ padding: 22px 46px;+ }++ /* 字幕 */+ #subs {+ position: absolute;+ left: 0;+ top: 1490px;+ width: 1080px;+ height: 230px;+ z-index: 30;+ text-align: center;+ }+ .sub {+ position: absolute;+ left: 110px;+ width: 860px;+ text-align: center;+ font-size: 46px;+ line-height: 1.34;+ font-weight: 600;+ text-shadow: 0 2px 18px rgba(0, 0, 0, 0.95);+ }+ .sub.prev {+ top: 0;+ font-size: 36px;+ font-weight: 400;+ color: var(--fg-faint);+ }+ .sub.cur {+ top: 66px;+ }+ </style>+ </head>+ <body>+ <div id="bg"></div>+ <div id="brand"><span class="mark" id="brand-mark"></span><span id="brand-text"></span></div>+ <div id="wm"></div>+ <div id="scenes"></div>+ <div id="subs">+ <div class="sub prev" id="sub-prev"></div>+ <div class="sub cur" id="sub-cur"></div>+ </div>+ <div id="bar"><div id="barfill"></div></div>++ <script>+ "use strict";+ const esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");++ /* ---------- 极简 Python 语法高亮(离线、确定性) ---------- */+ const PY_MASTER =+ /(#[^\n]*)|('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*")|\b(\d+\.?\d*)\b|\b(from|import|def|class|return|if|elif|else|for|in|while|with|as|not|and|or|None|True|False|lambda|self|print)\b|([A-Za-z_][A-Za-z_0-9]*)(?=\()/g;+ function highlight(src) {+ let out = "",+ last = 0,+ m;+ PY_MASTER.lastIndex = 0;+ while ((m = PY_MASTER.exec(src)) !== null) {+ out += esc(src.slice(last, m.index));+ const [full, comment, str, num, kw, fn] = m;+ const cls = comment ? "c" : str ? "s" : num ? "n" : kw ? "k" : "f";+ out += `<span class="${cls}">${esc(full)}</span>`;+ last = m.index + full.length;+ }+ out += esc(src.slice(last));+ return out;+ }+ /* 代码行逐行出现:整段在 reveal 秒内走完,长幕短幕都合适 */+ function codeLines(code, dur, reveal) {+ const lines = code.split("\n");+ const n = lines.length;+ const secs = Math.min(reveal || 4.5, (dur || 10) * 0.55);+ const start = 0.04 * (dur || 10);+ const step = n > 1 ? (secs - start) / (n - 1) : 0;+ return lines+ .map(+ (l, i) =>+ `<span class="ln" data-at="${Math.max(0, start + i * step).toFixed(2)}">${l ? highlight(l) : " "}</span>`,+ )+ .join("");+ }++ /* ---------- 各幕模板 ---------- */+ const T = {+ title: (s) => `+ <div class="kicker" data-r="0.02">${esc(s.kicker)}</div>+ <h1 class="hero" data-r="0.06">${esc(s.title)}</h1>+ <div class="rule" data-r="0.12"></div>+ <p class="hero-sub" data-r="0.16">${esc(s.sub)}</p>+ <div class="tags">${(s.tags || []).map((t, i) => `<span class="tag" data-r="${(0.24 + i * 0.07).toFixed(2)}">${esc(t)}</span>`).join("")}</div>`,++ points: (s) => `+ <div class="kicker" data-r="0.02">${esc(s.kicker)}</div>+ <h2 class="stitle" data-r="0.06">${esc(s.title)}</h2>+ ${(s.items || [])+ .map(+ (t, i) => `<div class="item" data-r="${(0.16 + i * 0.17).toFixed(2)}">+ <span class="dot"></span><div class="tx">${t}</div></div>`,+ )+ .join("")}`,++ math: (s) => `+ <div class="kicker" data-r="0.02">${esc(s.kicker)}</div>+ <h2 class="stitle" data-r="0.06">${esc(s.title)}</h2>+ ${(s.steps || [])+ .map(+ (st, i) => `<div class="formula-card${st.hi ? " hi" : ""}" ${at(st, 0.16 + i * 0.24)}>+ <div class="fc-label">${esc(st.label)}</div>+ <div class="fc-body">${st.formula}</div></div>`,+ )+ .join("")}`,++ code: (s) => `+ <div class="kicker" data-r="0.02">${esc(s.kicker)}</div>+ <h2 class="stitle" data-r="0.06">${esc(s.title)}</h2>+ <div class="card" data-r="0.10">+ <div class="card-hd"><span class="dots"><i></i><i></i><i></i></span>${esc(s.file)}</div>+ <div class="card-bd">${codeLines(s.code, s.dur, s.code_reveal)}</div>+ </div>`,++ source: (s) => `+ <div class="kicker" data-r="0.02">${esc(s.kicker)}</div>+ <h2 class="stitle" data-r="0.06">${esc(s.title)}</h2>+ <div class="card" data-r="0.10">+ <div class="card-hd"><span class="dots"><i></i><i></i><i></i></span>${esc(s.file)}</div>+ <div class="card-bd">${codeLines(s.code, s.dur, s.code_reveal)}</div>+ </div>+ <div class="notes">${(s.notes || [])+ .map(+ (t, i) =>+ `<div class="note" ${at(t, 0.56 + i * 0.12)}><span class="n-dot"></span><span>${esc(typeof t === "string" ? t : t.text)}</span></div>`,+ )+ .join("")}</div>`,++ outro: (s) => `+ <div class="kicker" data-r="0.02">${esc(s.kicker)}</div>+ <h2 class="outro" data-r="0.08">${esc(s.title)}</h2>+ <p class="outro-sub" data-r="0.16">${esc(s.sub)}</p>+ <div ${at({ at: s.cta_at }, 0.3)}><span class="cta">${esc(s.cta)}</span></div>`,+ };++ /* 出现时机:优先用脚本里写死的秒数 at(贴着讲解走),否则按场景进度比例 r */+ function at(item, r) {+ return item && item.at !== undefined ? `data-at="${item.at}"` : `data-r="${r.toFixed(2)}"`;+ }++ /* ---------- 缓动:与设计规范同一条 cubic-bezier(.2,.7,.3,1) ---------- */+ function cubicBezier(x1, y1, x2, y2) {+ const A = (a, b) => 1 - 3 * b + 3 * a,+ B = (a, b) => 3 * b - 6 * a,+ C = (a) => 3 * a;+ const calc = (t, a, b) => ((A(a, b) * t + B(a, b)) * t + C(a)) * t;+ const slope = (t, a, b) => 3 * A(a, b) * t * t + 2 * B(a, b) * t + C(a);+ return (x) => {+ if (x <= 0) return 0;+ if (x >= 1) return 1;+ let t = x;+ for (let i = 0; i < 8; i++) {+ const d = slope(t, x1, x2);+ if (Math.abs(d) < 1e-6) break;+ t -= (calc(t, x1, x2) - x) / d;+ }+ return calc(t, y1, y2);+ };+ }+ const ease = cubicBezier(0.2, 0.7, 0.3, 1);+ const clamp01 = (v) => (v < 0 ? 0 : v > 1 ? 1 : v);++ /* ---------- 全局状态 ---------- */+ let L = null,+ scenes = [];+ const els = [];++ function __init(lesson) {+ L = lesson;+ const meta = lesson.meta;+ const brand = meta.brand || meta.series || "";+ document.getElementById("brand-text").textContent = brand;+ // 台标字母与右上角水印都来自数据:meta.mark / meta.wm,没给就自动取首字 / 整块隐藏+ document.getElementById("brand-mark").textContent =+ meta.mark || brand.trim().slice(0, 1) || "▶";+ const wm = document.getElementById("wm");+ wm.textContent = meta.wm || "";+ wm.style.display = meta.wm ? "" : "none";+ const host = document.getElementById("scenes");+ scenes = lesson.scenes;+ scenes.forEach((s) => {+ const el = document.createElement("div");+ el.className = "scene";+ if (s.type === "title" || s.type === "outro") el.classList.add("center");+ if (s.type === "math" && (s.steps || []).length >= 4) el.classList.add("dense");+ el.innerHTML = T[s.type](s);+ host.appendChild(el);+ els.push({+ def: s,+ el,+ rev: [...el.querySelectorAll("[data-r],[data-at]")].map((n) => ({+ n,+ // data-at 是相对本幕的秒数;data-r 是场景进度比例,统一折成秒+ at:+ n.dataset.at !== undefined+ ? parseFloat(n.dataset.at)+ : parseFloat(n.dataset.r) * s.dur,+ })),+ });+ });+ }++ function seek(t) {+ const total = L.duration;+ document.getElementById("barfill").style.width = clamp01(t / total) * 100 + "%";+ document.getElementById("bg").style.backgroundPosition =+ `${(-t * 11).toFixed(1)}px ${(-t * 7).toFixed(1)}px`;++ // 字幕:当前句 + 上一句+ const subs = L.subtitles;+ let idx = -1;+ for (let i = 0; i < subs.length; i++) if (t >= subs[i].start) idx = i;+ const cur = subs[idx],+ prev = idx > 0 ? subs[idx - 1] : null;+ const elCur = document.getElementById("sub-cur"),+ elPrev = document.getElementById("sub-prev");+ if (cur && t <= cur.end + 0.5) {+ elCur.textContent = cur.text;+ elCur.style.opacity = Math.min(+ clamp01((t - cur.start) / 0.14),+ clamp01((cur.end + 0.28 - t) / 0.2),+ );+ if (prev && t < cur.start + 0.9) {+ elPrev.textContent = prev.text;+ elPrev.style.opacity = clamp01((cur.start + 0.9 - t) / 0.5) * 0.75;+ } else {+ elPrev.textContent = "";+ elPrev.style.opacity = 0;+ }+ } else {+ elCur.style.opacity = 0;+ elPrev.style.opacity = 0;+ }++ els.forEach(({ def, el, rev }, i) => {+ const local = t - def.start;+ if (local < 0 || local > def.dur) {+ el.classList.remove("on");+ return;+ }+ el.classList.add("on");+ const p = clamp01(local / def.dur);+ const enter = ease(clamp01(local / 0.42)); // 进场 0.42s+ const leave = ease(clamp01((def.dur - local) / 0.3)); // 出场 0.30s+ const a = Math.min(enter, leave);+ el.style.opacity = a;+ el.style.transform = `translateY(${((1 - enter) * 46 - (1 - leave) * 34).toFixed(2)}px)`;+ rev.forEach(({ n, at }) => {+ // 逐帧算,不用 CSS 过渡 —— 进场固定 0.38s,与幕长无关+ const q = ease(clamp01((local - at) / 0.38));+ n.style.opacity = q;+ n.style.transform = `translateY(${((1 - q) * 24).toFixed(2)}px)`;+ });+ });+ }++ window.__init = __init;+ window.seek = seek;+ </script>+ </body>+</html>diff --git a/plugins/lesson-video/skills/lesson-video/kit/render.mjs b/plugins/lesson-video/skills/lesson-video/kit/render.mjsnew file mode 100644index 00000000..15716a3c--- /dev/null+++ b/plugins/lesson-video/skills/lesson-video/kit/render.mjs@@ -0,0 +1,169 @@+#!/usr/bin/env node+/**+ * 逐帧渲染课件:把 deck.html 按 lesson.json 的时间轴定格成 30fps 的图片序列。+ * 每一帧都由 seek(t) 从时间 t 纯函数地算出来,所以画面与配音、字幕严格对齐。+ *+ * 用法:+ * PLAYWRIGHT_MODULE=<pw-core 路径> CHROME_PATH=<chrome.exe> \+ * node lib/render.mjs --dir lessons/ep00-pilot [--fps 30] [--scale 0.5]+ */+import fs from "node:fs";+import path from "node:path";+import { createRequire } from "node:module";+import { fileURLToPath, pathToFileURL } from "node:url";++const require = createRequire(import.meta.url);+const HERE = path.dirname(fileURLToPath(import.meta.url));+const PW = process.env.PLAYWRIGHT_MODULE || "playwright-core";+const CHROME = process.env.CHROME_PATH || "";+const pw = require(PW);+const { chromium } = pw;++const argv = process.argv.slice(2);+const arg = (k, d) => {+ const i = argv.indexOf(k);+ return i >= 0 ? argv[i + 1] : d;+};++const dir = path.resolve(arg("--dir", "lessons/ep00-pilot"));+// CSS 布局固定按 1080x1920 设计;--scale 只缩放光栅,用来快速预览+const dsf = parseFloat(arg("--scale", "1")) || 1;+const W = 1080,+ H = 1920;++const lesson = JSON.parse(fs.readFileSync(path.join(dir, "lesson.json"), "utf8"));+const fps = parseInt(arg("--fps", String(lesson.fps || 30)), 10);+const framesDir = path.join(dir, "frames");+fs.rmSync(framesDir, { recursive: true, force: true });+fs.mkdirSync(framesDir, { recursive: true });++const total = Math.round(lesson.duration * fps);+console.log(+ `渲染 ${lesson.meta.series} · ${lesson.meta.episode}: ${lesson.duration}s × ${fps}fps = ${total} 帧 @ ${W * dsf}x${H * dsf}`,+);++const browser = await chromium.launch({+ executablePath: CHROME || undefined,+ args: [+ "--no-sandbox",+ "--disable-dev-shm-usage",+ "--hide-scrollbars",+ "--force-color-profile=srgb",+ ],+});+const ctx = await browser.newContext({ viewport: { width: W, height: H }, deviceScaleFactor: dsf });+const page = await ctx.newPage();+await page.addInitScript(`window.__LESSON__ = ${JSON.stringify(lesson)};`);+// 每集可以自带 deck.html 覆盖版式;没有就用 lib/deck.html 这份共用的+const localDeck = path.join(dir, "deck.html");+const deck = fs.existsSync(localDeck) ? localDeck : path.join(HERE, "deck.html");+await page.goto(pathToFileURL(deck).href, { waitUntil: "load" });+await page.evaluate(() => window.__init(window.__LESSON__));+await page.evaluate(() => document.fonts.ready);++// 安全区自检:字幕带从 y=1470 开始,任何一幕的内容越线都会盖住字幕。+// 逐幕快进到结束前,量一遍可见元素的底边。+const SAFE_BOTTOM = 1470;+const over = await page.evaluate((safe) => {+ const bad = [];+ const nodes = document.querySelectorAll(".scene");+ window.__LESSON__.scenes.forEach((s, i) => {+ window.seek(s.start + s.dur - 0.35);+ let worst = 0,+ who = "";+ nodes[i].querySelectorAll("*").forEach((n) => {+ const r = n.getBoundingClientRect();+ if (r.height > 0 && r.bottom > worst) {+ worst = r.bottom;+ who = (n.className || n.tagName).toString();+ }+ });+ if (worst > safe) bad.push({ scene: s.id, bottom: Math.round(worst), el: who.slice(0, 40) });+ });+ return bad;+}, SAFE_BOTTOM);+if (over.length) {+ console.log("⚠ 越出字幕安全线:");+ over.forEach((o) => console.log(` ${o.scene} 底边 ${o.bottom} (${o.el})`));+} else {+ console.log(`安全区自检通过(所有内容底边 < ${SAFE_BOTTOM})`);+}++// 代码行比卡片宽就会被悄悄裁掉(.card-bd 是 overflow:hidden),这里逐幕量一遍+const clipped = await page.evaluate(() => {+ const bad = [];+ document.querySelectorAll(".scene").forEach((sc, i) => {+ const bd = sc.querySelector(".card-bd");+ if (bd && bd.scrollWidth > bd.clientWidth + 1) {+ bad.push({+ scene: sc.classList.contains("on") ? i : i,+ w: bd.scrollWidth,+ box: bd.clientWidth,+ });+ }+ });+ return bad;+});+if (clipped.length) {+ console.log("⚠ 代码行被裁:");+ clipped.forEach((o) => console.log(` 第 ${o.scene + 1} 幕 内容 ${o.w}px > 卡片 ${o.box}px`));+} else {+ console.log("代码宽度自检通过(没有行被裁)");+}++// 标题折行后末行只剩一两个字(孤字)会被安全区挤出来,这里量一遍每个标题的行宽+const orphans = await page.evaluate(() => {+ const bad = [];+ const nodes = document.querySelectorAll(".scene");+ nodes.forEach((sc, i) => {+ // 先切到这一幕:.scene 默认 display:none,隐藏元素的 Range 量不到行框+ const s = window.__LESSON__.scenes[i];+ window.seek(s.start + s.dur * 0.5);+ const h = sc.querySelector(".hero, .stitle, .outro");+ if (!h) return;+ const range = document.createRange();+ range.selectNodeContents(h);+ const rects = [...range.getClientRects()].filter((r) => r.width > 0);+ if (rects.length < 2) return;+ const widths = rects.map((r) => r.width);+ const last = widths[widths.length - 1],+ max = Math.max(...widths);+ if (last < max * 0.45)+ bad.push({ scene: i + 1, text: h.textContent, last: Math.round(last), max: Math.round(max) });+ });+ return bad;+});+if (orphans.length) {+ console.log("⚠ 标题末行过短(孤字):");+ orphans.forEach((o) =>+ console.log(` 第 ${o.scene} 幕 「${o.text}」 末行 ${o.last}px / 最长行 ${o.max}px`),+ );+} else {+ console.log("标题折行自检通过(没有孤字行)");+}++const t0 = Date.now();+if (argv.includes("--check")) {+ // 只做自检,不出帧+ await browser.close();+ process.exit(over.length || clipped.length || orphans.length ? 1 : 0);+}+for (let i = 0; i < total; i++) {+ const t = i / fps;+ await page.evaluate((tt) => window.seek(tt), t);+ await page.screenshot({+ path: path.join(framesDir, `f_${String(i).padStart(5, "0")}.jpg`),+ type: "jpeg",+ quality: 95,+ });+ if (i % 30 === 0 || i === total - 1) {+ const done = i + 1,+ el = (Date.now() - t0) / 1000;+ process.stdout.write(+ `\r ${done}/${total} ${((el / done) * 1000).toFixed(0)}ms/帧 eta ${(((el / done) * (total - done)) / 60).toFixed(1)} min `,+ );+ }+}+process.stdout.write("\n");+await browser.close();+console.log(`OK ${total} 帧 -> ${framesDir}`);diff --git a/plugins/lesson-video/skills/lesson-video/kit/tts.py b/plugins/lesson-video/skills/lesson-video/kit/tts.pynew file mode 100644index 00000000..275735b8--- /dev/null+++ b/plugins/lesson-video/skills/lesson-video/kit/tts.py@@ -0,0 +1,223 @@+"""把分镜脚本变成「配音 + 精确时间轴」。++流程:edge-tts 逐幕合成配音(同时拿到逐词边界)→ 转 48k 单声道 wav 量长度 →+拼出全局时间轴 → 写出 lesson.json(课件渲染与视频合成共用这一份数据)。++用法: python lib/tts.py lessons/ep00-pilot+"""+from __future__ import annotations++import asyncio+import json+import re+import subprocess+import sys+import time+import wave+from pathlib import Path++import edge_tts+import imageio_ffmpeg++FFMPEG = imageio_ffmpeg.get_ffmpeg_exe()+PUNCT = ",。!?;:、"+++async def synth(text: str, voice: str, rate: str, mp3: Path) -> list[dict]:+ """合成一段配音,返回逐词边界(秒)。++ edge-tts 7.x 默认 boundary='SentenceBoundary',拿不到逐词时间——必须显式要 WordBoundary,+ 字幕才能贴着人声逐句走。+ """+ comm = edge_tts.Communicate(text, voice, rate=rate, boundary="WordBoundary")+ words: list[dict] = []+ with open(mp3, "wb") as f:+ async for chunk in comm.stream():+ if chunk["type"] == "audio":+ f.write(chunk["data"])+ elif chunk["type"] == "WordBoundary":+ words.append({+ "text": chunk["text"],+ "start": chunk["offset"] / 1e7,+ "dur": chunk["duration"] / 1e7,+ })+ return words+++def synth_retry(text: str, voice: str, rate: str, mp3: Path, tries: int = 4) -> list[dict]:+ """edge-tts 偶尔会空手而归(NoAudioReceived),重试几次就好。"""+ last: Exception | None = None+ for i in range(tries):+ try:+ words = asyncio.run(synth(text, voice, rate, mp3))+ if words:+ return words+ last = RuntimeError("没有拿到逐词边界")+ except Exception as e: # noqa: BLE001+ last = e+ time.sleep(1.5 * (i + 1))+ print(f" 重试 {i + 1}/{tries - 1}:{type(last).__name__}")+ raise SystemExit(f"配音合成失败:{last}")+++def to_wav(mp3: Path, wav: Path) -> None:+ subprocess.run([FFMPEG, "-y", "-hide_banner", "-loglevel", "error",+ "-i", str(mp3), "-ar", "48000", "-ac", "1", "-c:a", "pcm_s16le", str(wav)], check=True)+++def wav_duration(p: Path) -> float:+ with wave.open(str(p), "rb") as w:+ return w.getnframes() / w.getframerate()+++def join_words(group: list[dict]) -> str:+ """把词拼回一行;中文与西文交界处补一个空格,中英混排才不挤。"""+ out = ""+ for w in group:+ t = w["text"]+ if out and t:+ a, b = out[-1], t[0]+ ascii_a, ascii_b = a.isascii() and a.isalnum(), b.isascii() and b.isalnum()+ if (ascii_a and ascii_b) or (ascii_a != ascii_b and (a.isalnum() or b.isalnum())):+ out += " "+ out += t+ return out+++def build_subtitles(text: str, words: list[dict], lead: float, max_len: int = 13) -> list[dict]:+ """先按标点断句,再按**词**切短行——不能按字数硬切,否则会把 Kaggle 切一半。++ 时间直接取该行首词与末词的 WordBoundary,所以字幕贴着人声走。+ 句尾标点补回最后一行。+ """+ subs: list[dict] = []+ wi = 0+ for sent in re.findall(rf"[^{PUNCT}]+[{PUNCT}]*", text):+ if not sent.strip():+ continue+ m = re.search(rf"[{PUNCT}]+$", sent)+ tail = m.group(0) if m else ""+ need = len(re.sub(r"\s", "", sent[: m.start()] if m else sent))++ groups: list[list[dict]] = []+ cur: list[dict] = []+ consumed = 0 # 本句已吃掉的字数,用来判断这句的词吃完了没有+ curlen = 0 # 当前这一行的字数,用来判断该不该换行+ while consumed < need and wi < len(words):+ t = words[wi]["text"]+ if cur and curlen + len(t) > max_len:+ groups.append(cur)+ cur, curlen = [], 0+ cur.append(words[wi])+ curlen += len(t)+ consumed += len(t)+ wi += 1+ if cur:+ groups.append(cur)++ for gi, g in enumerate(groups):+ subs.append({+ "text": join_words(g) + (tail if gi == len(groups) - 1 else ""),+ "start": round(lead + g[0]["start"], 3),+ "end": round(lead + g[-1]["start"] + g[-1]["dur"], 3),+ })+ return subs+++def cue_time(cue: str, words: list[dict]) -> float | None:+ """在逐词流里找到这句关键词,返回它第一个字被念到的时间(相对本幕)。++ 刻意按「词」而不是按「字幕行」匹配:字幕行长度有限,像+ 「X 转置 X 的逆」这种 cue 很可能正好横跨两行,按行匹配会匹配不到。+ """+ joined, owner = "", []+ for wi, w in enumerate(words):+ t = re.sub(r"\s", "", w["text"])+ joined += t+ owner.extend([wi] * len(t))+ p = joined.find(re.sub(r"\s", "", cue))+ return None if p < 0 else words[owner[p]]["start"]+++def apply_cues(node, words: list[dict], lead: float = 0.15) -> None:+ """把脚本里的 "cue": "关键词"(或 "<名>_cue")解析成出现秒数。++ 写作时只写「念到这个词的时候,这块内容出现」,不用手算时间;+ 配音合成后拿逐词时间反过来标定,画面和讲解自动咬合。已经写了 at 的不覆盖。+ """+ if isinstance(node, dict):+ for k in [kk for kk in list(node) if kk.endswith("_cue") and isinstance(node[kk], str)]:+ t = cue_time(node[k], words)+ if t is not None:+ node.setdefault(k[:-4] + "_at", max(0.0, round(t - lead, 2)))+ if isinstance(node.get("cue"), str) and "at" not in node:+ t = cue_time(node["cue"], words)+ if t is not None:+ node["at"] = max(0.0, round(t - lead, 2))+ for v in node.values():+ apply_cues(v, words, lead)+ elif isinstance(node, list):+ for v in node:+ apply_cues(v, words, lead)+++def main() -> None:+ lesson_dir = Path(sys.argv[1]).resolve() if len(sys.argv) > 1 else Path("lessons/ep00-pilot").resolve()+ script = json.loads((lesson_dir / "script.json").read_text(encoding="utf-8"))+ audio_dir = lesson_dir / "audio"+ audio_dir.mkdir(exist_ok=True)++ voice, rate, gap = script["voice"], script["rate"], script.get("gap", 0.35)+ scenes, subs, cursor = [], [], 0.0++ for i, sc in enumerate(script["scenes"]):+ mp3 = audio_dir / f"{sc['id']}.mp3"+ wav = audio_dir / f"{sc['id']}.wav"+ words = synth_retry(sc["narration"], voice, rate, mp3)+ to_wav(mp3, wav)+ dur = wav_duration(wav)++ scene_subs = build_subtitles(sc["narration"], words, cursor)+ entry = {k: v for k, v in sc.items() if k != "narration"}+ apply_cues(entry, words)+ entry.update({"start": round(cursor, 3), "dur": round(dur + gap, 3), "audio": round(dur, 3)})+ scenes.append(entry)+ subs.extend(scene_subs)+ print(f" {sc['id']:>4} {dur:5.2f}s {sc['narration']}")+ cursor += dur + gap++ duration = round(cursor, 3)+ # meta 里除 scenes 之外的顶层标量原样传下去:deck.html 用 meta.wm / meta.mark 渲染+ # 右上角水印、台标字母,脚本里写什么就显示什么,模板本身不含任何固定文案。+ meta = {"series": script["series"], "episode": script["episode"], "id": script["id"],+ "brand": script.get("brand", script["series"]), "voice": voice, "rate": rate}+ meta.update({k: v for k, v in script.items() if isinstance(v, (str, int, float, bool))})+ lesson = {+ "meta": meta,+ "fps": 30,+ "duration": duration,+ "scenes": scenes,+ "subtitles": [{"text": s["text"], "start": round(s["start"], 3), "end": round(s["end"], 3)} for s in subs],+ }+ (lesson_dir / "lesson.json").write_text(json.dumps(lesson, ensure_ascii=False, indent=2), encoding="utf-8")++ # 配音轨:每幕之间补上 gap 长度的静音,最后也补一段+ concat = audio_dir / "concat.txt"+ lines = []+ for i, sc in enumerate(scenes):+ lines.append(f"file '{(audio_dir / (sc['id'] + '.wav')).as_posix()}'")+ lines.append(f"file '{(audio_dir / 'gap.wav').as_posix()}'")+ with wave.open(str(audio_dir / "gap.wav"), "wb") as w:+ w.setnchannels(1); w.setsampwidth(2); w.setframerate(48000)+ w.writeframes(b"\x00" * int(48000 * 2 * gap))+ concat.write_text("\n".join(lines) + "\n", encoding="utf-8")+ subprocess.run([FFMPEG, "-y", "-hide_banner", "-loglevel", "error",+ "-f", "concat", "-safe", "0", "-i", str(concat),+ str(audio_dir / "narration.wav")], check=True)++ print(f"OK 时长 {duration:.2f}s -> {lesson_dir / 'lesson.json'}")+ print(f" 配音 -> {audio_dir / 'narration.wav'} ({wav_duration(audio_dir / 'narration.wav'):.2f}s)")+++if __name__ == "__main__":+ main()diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 7f7134ae..f449a590 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -75,6 +75,9 @@ importers:'@lmliheng/humanizer':specifier: workspace:*version: link:../../plugins/humanizer+ '@lmliheng/lesson-video':+ specifier: workspace:*+ version: link:../../plugins/lesson-video'@lmliheng/model-development':specifier: workspace:*version: link:../../plugins/model-development@@ -166,6 +169,9 @@ importers:'@lmliheng/humanizer':specifier: workspace:*version: link:../../plugins/humanizer+ '@lmliheng/lesson-video':+ specifier: workspace:*+ version: link:../../plugins/lesson-video'@lmliheng/model-development':specifier: workspace:*version: link:../../plugins/model-development@@ -257,6 +263,9 @@ importers:'@lmliheng/humanizer':specifier: workspace:*version: link:../../plugins/humanizer+ '@lmliheng/lesson-video':+ specifier: workspace:*+ version: link:../../plugins/lesson-video'@lmliheng/model-development':specifier: workspace:*version: link:../../plugins/model-development@@ -664,6 +673,8 @@ importers:plugins/humanizer: {}+ plugins/lesson-video: {}+plugins/model-development: {}plugins/sandbox-bwrap:@@ -1460,6 +1471,9 @@ packages:'@lmliheng/humanizer@file:plugins/humanizer':resolution: {directory: plugins/humanizer, type: directory}+ '@lmliheng/lesson-video@file:plugins/lesson-video':+ resolution: {directory: plugins/lesson-video, type: directory}+'@lmliheng/model-development@file:plugins/model-development':resolution: {directory: plugins/model-development, type: directory}@@ -5537,6 +5551,8 @@ snapshots:'@lmliheng/humanizer@file:plugins/humanizer': {}+ '@lmliheng/lesson-video@file:plugins/lesson-video': {}+'@lmliheng/model-development@file:plugins/model-development': {}'@lmliheng/penguin-cli@file:packages/cli([email protected])':@@ -5550,6 +5566,7 @@ snapshots:'@lmliheng/data-analysis': file:plugins/data-analysis'@lmliheng/goal': file:plugins/goal'@lmliheng/humanizer': file:plugins/humanizer+ '@lmliheng/lesson-video': file:plugins/lesson-video'@lmliheng/model-development': file:plugins/model-development'@lmliheng/penguin-core': file:packages/core([email protected])([email protected])'@lmliheng/penguin-server': file:packages/server([email protected])@@ -5585,6 +5602,7 @@ snapshots:'@lmliheng/data-analysis': file:plugins/data-analysis'@lmliheng/goal': file:plugins/goal'@lmliheng/humanizer': file:plugins/humanizer+ '@lmliheng/lesson-video': file:plugins/lesson-video'@lmliheng/model-development': file:plugins/model-development'@lmliheng/skill-porting': file:plugins/skill-porting'@lmliheng/software-development': file:plugins/software-development@@ -5616,6 +5634,7 @@ snapshots:'@lmliheng/data-analysis': file:plugins/data-analysis'@lmliheng/goal': file:plugins/goal'@lmliheng/humanizer': file:plugins/humanizer+ '@lmliheng/lesson-video': file:plugins/lesson-video'@lmliheng/model-development': file:plugins/model-development'@lmliheng/skill-porting': file:plugins/skill-porting'@lmliheng/software-development': file:plugins/software-development