@biunow/agent-biutalk 0.0.0-stage → 1.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 (227) hide show
  1. package/bin/server.js +355 -0
  2. package/engine/AGENTS.md +1414 -0
  3. package/engine/CLAUDE.md +1 -0
  4. package/engine/LICENSE +21 -0
  5. package/engine/README.md +216 -0
  6. package/engine/bin/explainroo.js +19 -0
  7. package/engine/dev/audio-lab.mjs +268 -0
  8. package/engine/docs/media/contact-sheet.jpg +0 -0
  9. package/engine/docs/media/dns-poster.jpg +0 -0
  10. package/engine/docs/media/intro-poster.jpg +0 -0
  11. package/engine/docs/media/logo-dark.png +0 -0
  12. package/engine/docs/media/logo-light.png +0 -0
  13. package/engine/docs/media/looks-dark.webp +0 -0
  14. package/engine/docs/media/looks-light.webp +0 -0
  15. package/engine/docs/media/product-demo.webp +0 -0
  16. package/engine/docs/media/rebase-poster.jpg +0 -0
  17. package/engine/docs/media/sizes-dark.webp +0 -0
  18. package/engine/docs/media/sizes-light.webp +0 -0
  19. package/engine/engine/audio/dsp.js +69 -0
  20. package/engine/engine/audio/instruments.js +147 -0
  21. package/engine/engine/audio/music.js +576 -0
  22. package/engine/engine/audio/pcm.js +93 -0
  23. package/engine/engine/audio/rng.js +40 -0
  24. package/engine/engine/audio/sfx.js +287 -0
  25. package/engine/engine/audio/soundtrack.js +201 -0
  26. package/engine/engine/audio/synth.js +721 -0
  27. package/engine/engine/audio/theory.js +105 -0
  28. package/engine/engine/audio/wav.js +47 -0
  29. package/engine/engine/captions.js +131 -0
  30. package/engine/engine/clips.js +107 -0
  31. package/engine/engine/code.js +179 -0
  32. package/engine/engine/director.js +475 -0
  33. package/engine/engine/frame.html +135 -0
  34. package/engine/engine/icons/LICENSE-lucide.txt +43 -0
  35. package/engine/engine/icons/lucide-tags.json +1 -0
  36. package/engine/engine/icons/lucide.json +1 -0
  37. package/engine/engine/layout.js +69 -0
  38. package/engine/engine/pathdata.js +234 -0
  39. package/engine/engine/pen.js +240 -0
  40. package/engine/engine/player.html +67 -0
  41. package/engine/engine/player.js +219 -0
  42. package/engine/engine/readability.js +9 -0
  43. package/engine/engine/runtime.js +690 -0
  44. package/engine/engine/stage.js +2247 -0
  45. package/engine/engine/studio.html +216 -0
  46. package/engine/engine/text.js +81 -0
  47. package/engine/engine/themes.js +360 -0
  48. package/engine/engine/transitions.js +161 -0
  49. package/engine/engine/ui.js +1042 -0
  50. package/engine/engine/upload.js +32 -0
  51. package/engine/engine/util.js +204 -0
  52. package/engine/examples/callbacks-to-async-await/code-versions.js +34 -0
  53. package/engine/examples/callbacks-to-async-await/scenes.js +106 -0
  54. package/engine/examples/callbacks-to-async-await/script.md +22 -0
  55. package/engine/examples/callbacks-to-async-await/video.json +16 -0
  56. package/engine/examples/circle-area/scenes.js +228 -0
  57. package/engine/examples/circle-area/script.md +37 -0
  58. package/engine/examples/circle-area/video.json +14 -0
  59. package/engine/examples/explainroo-intro/scenes.js +133 -0
  60. package/engine/examples/explainroo-intro/script.md +27 -0
  61. package/engine/examples/explainroo-intro/video.json +8 -0
  62. package/engine/examples/how-dns-works/scenes.js +130 -0
  63. package/engine/examples/how-dns-works/script.md +28 -0
  64. package/engine/examples/how-dns-works/video.json +8 -0
  65. package/engine/examples/leap-years/scenes.js +156 -0
  66. package/engine/examples/leap-years/script.md +25 -0
  67. package/engine/examples/leap-years/video.json +16 -0
  68. package/engine/examples/leap-years-ja/scenes.js +194 -0
  69. package/engine/examples/leap-years-ja/script.md +32 -0
  70. package/engine/examples/leap-years-ja/video.json +17 -0
  71. package/engine/examples/merge-vs-rebase/scenes.js +129 -0
  72. package/engine/examples/merge-vs-rebase/script.md +22 -0
  73. package/engine/examples/merge-vs-rebase/video.json +8 -0
  74. package/engine/examples/password-storage-zh/scenes.js +185 -0
  75. package/engine/examples/password-storage-zh/script.md +25 -0
  76. package/engine/examples/password-storage-zh/video.json +19 -0
  77. package/engine/examples/sqlite-demo/README.md +19 -0
  78. package/engine/examples/sqlite-demo/scenes.js +423 -0
  79. package/engine/examples/sqlite-demo/script.md +35 -0
  80. package/engine/examples/sqlite-demo/video.json +17 -0
  81. package/engine/examples/unspar-demo/assets/fonts/Figtree-400.woff2 +0 -0
  82. package/engine/examples/unspar-demo/assets/fonts/Figtree-500.woff2 +0 -0
  83. package/engine/examples/unspar-demo/assets/fonts/Figtree-600.woff2 +0 -0
  84. package/engine/examples/unspar-demo/assets/fonts/Figtree-700.woff2 +0 -0
  85. package/engine/examples/unspar-demo/assets/fonts/Figtree-OFL.txt +93 -0
  86. package/engine/examples/unspar-demo/assets/unspar-logo.svg +23 -0
  87. package/engine/examples/unspar-demo/scenes.js +367 -0
  88. package/engine/examples/unspar-demo/script.md +25 -0
  89. package/engine/examples/unspar-demo/video.json +21 -0
  90. package/engine/examples/why-is-the-sky-blue-es/scenes.js +160 -0
  91. package/engine/examples/why-is-the-sky-blue-es/script.md +22 -0
  92. package/engine/examples/why-is-the-sky-blue-es/video.json +15 -0
  93. package/engine/fonts/ArchitectsDaughter-400-latin-ext.woff2 +0 -0
  94. package/engine/fonts/ArchitectsDaughter-400-latin.woff2 +0 -0
  95. package/engine/fonts/CabinSketch-400-latin.woff2 +0 -0
  96. package/engine/fonts/CabinSketch-700-latin.woff2 +0 -0
  97. package/engine/fonts/InstrumentSerif-400-italic-latin-ext.woff2 +0 -0
  98. package/engine/fonts/InstrumentSerif-400-italic-latin.woff2 +0 -0
  99. package/engine/fonts/InstrumentSerif-400-normal-latin-ext.woff2 +0 -0
  100. package/engine/fonts/InstrumentSerif-400-normal-latin.woff2 +0 -0
  101. package/engine/fonts/Inter-400-latin-ext.woff2 +0 -0
  102. package/engine/fonts/Inter-400-latin.woff2 +0 -0
  103. package/engine/fonts/JetBrainsMono-400-latin-ext.woff2 +0 -0
  104. package/engine/fonts/JetBrainsMono-400-latin.woff2 +0 -0
  105. package/engine/fonts/Kalam-400-latin-ext.woff2 +0 -0
  106. package/engine/fonts/Kalam-400-latin.woff2 +0 -0
  107. package/engine/fonts/Kalam-700-latin-ext.woff2 +0 -0
  108. package/engine/fonts/Kalam-700-latin.woff2 +0 -0
  109. package/engine/fonts/NotoSansDevanagari-400.ttf +0 -0
  110. package/engine/fonts/NotoSansDevanagari-700.ttf +0 -0
  111. package/engine/fonts/PatrickHand-400-latin-ext.woff2 +0 -0
  112. package/engine/fonts/PatrickHand-400-latin.woff2 +0 -0
  113. package/engine/fonts/PlusJakartaSans-600-latin-ext.woff2 +0 -0
  114. package/engine/fonts/PlusJakartaSans-600-latin.woff2 +0 -0
  115. package/engine/fonts/SpaceGrotesk-500-latin-ext.woff2 +0 -0
  116. package/engine/fonts/SpaceGrotesk-500-latin.woff2 +0 -0
  117. package/engine/fonts/fonts.json +216 -0
  118. package/engine/fonts/licenses/ArchitectsDaughter-OFL.txt +93 -0
  119. package/engine/fonts/licenses/CabinSketch-OFL.txt +93 -0
  120. package/engine/fonts/licenses/InstrumentSerif-OFL.txt +93 -0
  121. package/engine/fonts/licenses/Inter-OFL.txt +93 -0
  122. package/engine/fonts/licenses/JetBrainsMono-OFL.txt +93 -0
  123. package/engine/fonts/licenses/Kalam-OFL.txt +93 -0
  124. package/engine/fonts/licenses/NotoSansDevanagari-OFL.txt +118 -0
  125. package/engine/fonts/licenses/PatrickHand-OFL.txt +93 -0
  126. package/engine/fonts/licenses/PlusJakartaSans-OFL.txt +93 -0
  127. package/engine/fonts/licenses/SpaceGrotesk-OFL.txt +93 -0
  128. package/engine/package-lock.json +1201 -0
  129. package/engine/package.json +67 -0
  130. package/engine/scripts/build-icons.mjs +74 -0
  131. package/engine/scripts/fetch-fonts.mjs +68 -0
  132. package/engine/skills/explainroo/SKILL.md +51 -0
  133. package/engine/src/align.js +357 -0
  134. package/engine/src/browser.js +121 -0
  135. package/engine/src/capture.js +315 -0
  136. package/engine/src/chapters.js +32 -0
  137. package/engine/src/cli.js +421 -0
  138. package/engine/src/clips.js +19 -0
  139. package/engine/src/elevenlabs.js +90 -0
  140. package/engine/src/env.js +16 -0
  141. package/engine/src/export.js +187 -0
  142. package/engine/src/ffmpeg.js +103 -0
  143. package/engine/src/fonts.js +86 -0
  144. package/engine/src/g2p.py +76 -0
  145. package/engine/src/images.js +151 -0
  146. package/engine/src/licenses/misaki-Apache-2.0.txt +201 -0
  147. package/engine/src/math.js +83 -0
  148. package/engine/src/models.js +161 -0
  149. package/engine/src/phonemes.js +162 -0
  150. package/engine/src/pipeline.js +63 -0
  151. package/engine/src/project.js +331 -0
  152. package/engine/src/qa.js +186 -0
  153. package/engine/src/recordings.js +89 -0
  154. package/engine/src/render.js +156 -0
  155. package/engine/src/script.js +266 -0
  156. package/engine/src/server.js +288 -0
  157. package/engine/src/subtitles.js +78 -0
  158. package/engine/src/timeline.js +55 -0
  159. package/engine/src/voice.js +240 -0
  160. package/engine/src/wav.js +98 -0
  161. package/engine/templates/starter/scenes.js +31 -0
  162. package/engine/templates/starter/script.md +14 -0
  163. package/engine/test/align.test.js +108 -0
  164. package/engine/test/brand.test.js +41 -0
  165. package/engine/test/browser.test.js +89 -0
  166. package/engine/test/camera-browser.test.js +225 -0
  167. package/engine/test/caption-phrases.test.js +35 -0
  168. package/engine/test/capture-browser.test.js +90 -0
  169. package/engine/test/capture-fixture.js +46 -0
  170. package/engine/test/capture.test.js +62 -0
  171. package/engine/test/chapters.test.js +41 -0
  172. package/engine/test/cjk-browser.test.js +101 -0
  173. package/engine/test/cjk.test.js +232 -0
  174. package/engine/test/cli-exit.test.js +25 -0
  175. package/engine/test/cli.test.js +116 -0
  176. package/engine/test/clips-browser.test.js +125 -0
  177. package/engine/test/clips.test.js +67 -0
  178. package/engine/test/code-morph-browser.test.js +99 -0
  179. package/engine/test/code-morph.test.js +110 -0
  180. package/engine/test/contrast-browser.test.js +63 -0
  181. package/engine/test/contrast.test.js +80 -0
  182. package/engine/test/director.test.js +316 -0
  183. package/engine/test/engine-pure.test.js +29 -0
  184. package/engine/test/export-browser.test.js +224 -0
  185. package/engine/test/export.test.js +96 -0
  186. package/engine/test/fixtures/capture.html +55 -0
  187. package/engine/test/formats-pace.test.js +104 -0
  188. package/engine/test/languages-browser.test.js +78 -0
  189. package/engine/test/languages.test.js +140 -0
  190. package/engine/test/looks-browser.test.js +109 -0
  191. package/engine/test/looks-preview.test.js +57 -0
  192. package/engine/test/looks.test.js +130 -0
  193. package/engine/test/math-browser.test.js +114 -0
  194. package/engine/test/math.test.js +54 -0
  195. package/engine/test/multi-size-browser.test.js +133 -0
  196. package/engine/test/multi-size.test.js +116 -0
  197. package/engine/test/phonemes.test.js +92 -0
  198. package/engine/test/readability-browser.test.js +36 -0
  199. package/engine/test/readability.test.js +20 -0
  200. package/engine/test/render-options.test.js +52 -0
  201. package/engine/test/script.test.js +67 -0
  202. package/engine/test/server.test.js +256 -0
  203. package/engine/test/stills-browser.test.js +70 -0
  204. package/engine/test/subtitles.test.js +83 -0
  205. package/engine/test/timeline.test.js +31 -0
  206. package/engine/test/transparent-browser.test.js +123 -0
  207. package/engine/test/ui-kit.test.js +96 -0
  208. package/engine/test/upload-browser.test.js +55 -0
  209. package/engine/test/voice-providers.test.js +338 -0
  210. package/lib/host.mjs +480 -0
  211. package/manifest.json +54 -0
  212. package/package.json +8 -4
  213. package/skills/biutalk/SKILL.md +21 -0
  214. package/studio/app.js +209 -0
  215. package/studio/assert-panel-permit.mjs +67 -0
  216. package/studio/composer.css +354 -0
  217. package/studio/composer.js +169 -0
  218. package/studio/index.html +82 -0
  219. package/studio/looks/blueprint.svg +21 -0
  220. package/studio/looks/chalk.svg +15 -0
  221. package/studio/looks/clean.svg +20 -0
  222. package/studio/looks/editorial.svg +18 -0
  223. package/studio/looks/midnight.svg +17 -0
  224. package/studio/looks/paper.svg +11 -0
  225. package/studio/select-menu.js +268 -0
  226. package/studio/styles.css +4 -0
  227. package/README.md +0 -3
@@ -0,0 +1 @@
1
+ @AGENTS.md
package/engine/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vincent Schmalbach
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.
@@ -0,0 +1,216 @@
1
+ <p align="center">
2
+ <a href="https://www.explainroo.com">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="docs/media/logo-dark.png">
5
+ <img src="docs/media/logo-light.png" alt="explainroo" width="340">
6
+ </picture>
7
+ </a>
8
+ </p>
9
+
10
+ <p align="center">
11
+ <b>Explainer videos made by your AI agent.</b><br>
12
+ Free and open source. The voice, the timing and the rendering run on your computer.
13
+ </p>
14
+
15
+ <p align="center">
16
+ <a href="https://www.explainroo.com">Website</a> &nbsp;·&nbsp;
17
+ <a href="https://www.explainroo.com/videos/">Example videos</a> &nbsp;·&nbsp;
18
+ <a href="https://www.explainroo.com/docs/">Docs</a> &nbsp;·&nbsp;
19
+ <a href="AGENTS.md">AGENTS.md</a>
20
+ </p>
21
+
22
+ https://github.com/user-attachments/assets/6dd5dc32-c975-4e0e-8cd4-2ef3ccc11e61
23
+
24
+ <p align="center">
25
+ <sub>A coding agent made this video with explainroo. You can also watch it on <a href="https://www.explainroo.com/videos/how-explainroo-makes-a-video/">explainroo.com</a>.</sub>
26
+ </p>
27
+
28
+ ## News
29
+
30
+ - **Oct 20, 2026**: [explainroo 0.4.1](https://www.explainroo.com/news/explainroo-0-4-1/) keeps arrow and chart labels whole while a shot holds.
31
+ - **Oct 15, 2026**: [explainroo 0.4](https://www.explainroo.com/news/explainroo-0-4/) films each scene with a camera that follows the narration.
32
+ - **Oct 13, 2026**: [explainroo 0.3](https://www.explainroo.com/news/explainroo-0-3/) narrates in Japanese and Mandarin Chinese, and adds the editorial look.
33
+ - **Oct 13, 2026**: [explainroo 0.2](https://www.explainroo.com/news/explainroo-0-2/) adds five more languages, other voices and video clips.
34
+
35
+ All news is on [explainroo.com/news](https://www.explainroo.com/news/).
36
+
37
+ ## Make a video
38
+
39
+ > [!TIP]
40
+ > **Give your coding agent this repo and tell it what the video should explain.**
41
+ > It works with Claude Code, Codex, Pi and other coding agents. Right now it
42
+ > works best with Claude Code and Opus 5.5.
43
+
44
+ Copy this into your agent and put your topic in place of the brackets:
45
+
46
+ ```text
47
+ Make me a short explainer video about [your topic].
48
+ Use explainroo for it: clone https://github.com/vincentsch/explainroo,
49
+ read its AGENTS.md and follow the steps.
50
+ ```
51
+
52
+ The agent sets up explainroo, makes the video and checks it. You get an MP4
53
+ file.
54
+
55
+ ## How does it work?
56
+
57
+ An explainer video is a short video where a voice explains a topic and
58
+ drawings appear while it speaks. For explainroo, the agent writes two files.
59
+ `script.md` has the words the voice says. `scenes.js` draws the pictures with
60
+ a bit of JavaScript, and each drawing can appear on a word from the script.
61
+ explainroo does the rest:
62
+
63
+ - **Voice.** [Kokoro](https://huggingface.co/hexgrad/Kokoro-82M), an open
64
+ voice model, reads the script aloud in English, Spanish, French, Italian,
65
+ Brazilian Portuguese, Hindi, Japanese or Mandarin Chinese. It has 54 voices
66
+ and needs no account or API key. You can also use an [ElevenLabs](https://elevenlabs.io) voice or
67
+ record the narration yourself.
68
+ - **Timing.** [Whisper](https://github.com/openai/whisper) listens to the
69
+ narration and notes when each word is spoken.
70
+ - **Pictures.** Chrome runs in the background and draws the frames. The lines
71
+ can look hand drawn ([Rough.js](https://roughjs.com)), and there are 1,800
72
+ icons from [Lucide](https://lucide.dev). A scene can also show charts, math
73
+ formulas, code that changes step by step, your own screenshots and video
74
+ clips such as screen recordings.
75
+ - **Camera.** A camera films each scene. It moves in on what the voice talks
76
+ about when there is time, and pulls back at the end so the last frame shows
77
+ the whole idea. Cards and labels are never cut in half while a shot holds.
78
+ Things arrive with a little spring, and the final video has motion blur,
79
+ like a film camera.
80
+ - **Sound.** explainroo makes its own background music for each video and
81
+ adds small sound effects. The music gets quieter while the voice speaks.
82
+ - **File.** ffmpeg puts it all together into an MP4, with subtitle files,
83
+ YouTube chapters and a cover image.
84
+
85
+ An agent can't watch a video, so explainroo gives it other ways to check its
86
+ work. It saves stills of the scenes and a sheet of small frames for the whole
87
+ video. A layout check finds text that is cut off or overlaps, and a speech
88
+ check finds words the voice got wrong. For a feed-sized player,
89
+ `explainroo check videos/<name> --view-width 854` also flags small text.
90
+
91
+ None of this leaves your computer, and it costs nothing. Your coding agent is
92
+ a separate service with its own terms and prices. If you want, the agent can
93
+ also make illustrations with an AI image model through OpenRouter, and you pay
94
+ for each image.
95
+
96
+ ## Looks
97
+
98
+ There are six looks: paper, clean, chalk, blueprint, midnight and editorial.
99
+ You change a video's look with one setting in `video.json`. A project can also
100
+ bring its own look, a small JSON file with its colors, fonts and background.
101
+ Here is one frame in each built-in look, from the example videos.
102
+
103
+ <p align="center">
104
+ <picture>
105
+ <source media="(prefers-color-scheme: dark)" srcset="docs/media/looks-dark.webp">
106
+ <img src="docs/media/looks-light.webp" alt="Frames from six example videos, one in each look: paper, clean, chalk, blueprint, midnight and editorial" width="820">
107
+ </picture>
108
+ </p>
109
+
110
+ ## Sizes
111
+
112
+ You pick the size for the place the video goes. YouTube videos are wide, and
113
+ Shorts, TikTok and Reels are tall. Instagram and LinkedIn posts use 4:5, and
114
+ there is a square size too. Shorts, TikTok and Reels put their own buttons
115
+ over the video, and explainroo keeps your text out of those spots.
116
+
117
+ <p align="center">
118
+ <picture>
119
+ <source media="(prefers-color-scheme: dark)" srcset="docs/media/sizes-dark.webp">
120
+ <img src="docs/media/sizes-light.webp" alt="Frames from example videos in four sizes: YouTube 16:9, TikTok 9:16, LinkedIn 4:5 and square" width="820">
121
+ </picture>
122
+ </p>
123
+
124
+ Tall, 4:5 and square videos get captions that light up word by word. One
125
+ project can render several sizes: `explainroo render videos/demo --size tiktok`
126
+ writes the TikTok version next to the wide one.
127
+
128
+ ## More than an MP4
129
+
130
+ Every render also writes subtitle files (`.srt` and `.vtt`) that YouTube and
131
+ LinkedIn accept, a cover image for the thumbnail, and YouTube chapters when
132
+ the script names them. `--format gif` makes a GIF for a README or a post.
133
+ `--transparent --format mov` makes a video with a transparent background, for
134
+ putting a diagram over camera footage in a video editor. `explainroo export`
135
+ writes a small web player that draws the video sharp at any size and embeds
136
+ with an iframe.
137
+
138
+ ## Pace
139
+
140
+ `"pace": 1.2` in a video's `video.json` makes the voice, the pauses and the
141
+ animations 20% quicker. The music gets a little quicker too. Pace goes from
142
+ 0.7 to 1.6, and 1 is normal.
143
+
144
+ ## Product demos
145
+
146
+ explainroo can also make product demos, the videos software companies make to
147
+ show their app. The agent rebuilds the app's screens from its code or its
148
+ website, with the same colors, fonts and button labels. A mouse pointer then
149
+ clicks through the screens and types into the fields. Tell your agent which
150
+ product it is and where to find its code or website. `explainroo capture`
151
+ saves the live site's screenshots, colors, fonts, logo and wording first, and
152
+ a real screen recording can play inside a scene too.
153
+
154
+ <p align="center">
155
+ <a href="https://www.explainroo.com/videos/unspar-product-demo/">
156
+ <img src="docs/media/product-demo.webp" alt="A frame from the Unspar product demo: a form with a website field and an open dropdown" width="820">
157
+ </a>
158
+ </p>
159
+
160
+ Here are the demos for [Unspar](https://www.explainroo.com/videos/unspar-product-demo/)
161
+ and [Vroni](https://www.explainroo.com/videos/vroni-product-demo/), two of my
162
+ own products. The files for the Unspar demo are in
163
+ [examples/unspar-demo](examples/unspar-demo). explainroo.com also has
164
+ unofficial demos of [Gmail, ChatGPT and Claude](https://www.explainroo.com/videos/#product-demos).
165
+
166
+ ## Install it yourself
167
+
168
+ You need Node.js 20.11 or newer, ffmpeg, and Chrome or Chromium. The first
169
+ setup downloads the voice and timing models once, about 400 MB together. You
170
+ don't need a graphics card. I develop explainroo on Linux, and its tests run
171
+ on Linux, macOS and Windows for every change.
172
+
173
+ ```bash
174
+ git clone https://github.com/vincentsch/explainroo.git
175
+ cd explainroo
176
+ npm install
177
+ node bin/explainroo.js doctor --fetch
178
+ ```
179
+
180
+ For narration in Spanish, French, Italian, Portuguese or Hindi, also install
181
+ [espeak-ng](https://github.com/espeak-ng/espeak-ng), for example with
182
+ `sudo apt install espeak-ng` or `brew install espeak-ng`. Japanese and
183
+ Chinese need Python with [misaki](https://github.com/hexgrad/misaki) instead,
184
+ as described in [AGENTS.md](AGENTS.md#japanese-and-chinese).
185
+
186
+ Then start your agent in the `explainroo` folder and ask for a video, for
187
+ example "Make a 60 second video about how HTTPS keeps a password secret." The
188
+ agent follows [AGENTS.md](AGENTS.md) and saves the video as
189
+ `videos/<name>/out/video.mp4`. The example videos are in
190
+ [examples/](examples/), and the full documentation is on
191
+ [explainroo.com](https://www.explainroo.com/docs/).
192
+
193
+ ## The watermark
194
+
195
+ Each video has a small "explainroo.com" in one corner. `"watermark": false` in
196
+ `video.json` turns it off. Please keep it if you can, because that is how
197
+ other people find explainroo.
198
+
199
+ ## Credits and license
200
+
201
+ explainroo is MIT licensed. The voice comes from
202
+ [Kokoro](https://huggingface.co/hexgrad/Kokoro-82M), and the word timing from
203
+ [Whisper](https://github.com/openai/whisper) through
204
+ [Transformers.js](https://github.com/huggingface/transformers.js). The
205
+ drawings use [Rough.js](https://roughjs.com) and [Lucide](https://lucide.dev)
206
+ icons. [MathJax](https://www.mathjax.org) typesets the formulas.
207
+ [Playwright](https://playwright.dev) runs Chrome, and
208
+ [ffmpeg](https://ffmpeg.org) makes the video file. For other languages,
209
+ explainroo runs [espeak-ng](https://github.com/espeak-ng/espeak-ng) as a
210
+ separate program, with phoneme rules from Kokoro's
211
+ [misaki](https://github.com/hexgrad/misaki), and misaki itself for Japanese
212
+ and Chinese. [OpenCC](https://github.com/nk2028/opencc-js) and
213
+ [pinyin-pro](https://github.com/zh-lx/pinyin-pro) help the speech check
214
+ compare Chinese, and [HarfBuzz](https://github.com/harfbuzz/harfbuzzjs) keeps
215
+ web player fonts small. The fonts, including Noto Sans CJK for Japanese and
216
+ Chinese, are under the SIL Open Font License.
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ import { main } from '../src/cli.js';
3
+
4
+ // Exit by letting the event loop drain, not with process.exit(). ONNX Runtime
5
+ // (voice and speech check models) aborts with "mutex lock failed" on macOS when
6
+ // process.exit() runs while its thread pool is alive. The unref'd timer only
7
+ // fires if some handle keeps the process up after main() is done.
8
+ const finish = (code) => {
9
+ process.exitCode = code;
10
+ setTimeout(() => process.exit(code), 5000).unref();
11
+ };
12
+
13
+ main(process.argv.slice(2)).then(
14
+ (code) => finish(code ?? 0),
15
+ (e) => {
16
+ process.stderr.write(`${e && e.stack ? e.stack : e}\n`);
17
+ finish(1);
18
+ },
19
+ );
@@ -0,0 +1,268 @@
1
+ #!/usr/bin/env node
2
+ // Audio lab: renders test soundtracks with engine/audio in headless Chrome,
3
+ // writes WAVs to .scratch/audio/ and measures them with ffmpeg.
4
+ //
5
+ // node dev/audio-lab.mjs [--styles warm,upbeat] [--no-spectro] [--skip-long]
6
+ import http from 'node:http';
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
9
+ import os from 'node:os';
10
+ import crypto from 'node:crypto';
11
+ import { spawnSync } from 'node:child_process';
12
+ import { fileURLToPath } from 'node:url';
13
+ import { chromium } from 'playwright-core';
14
+
15
+ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
16
+ const OUT = path.join(ROOT, '.scratch/audio');
17
+ const FFMPEG = process.env.FFMPEG || 'ffmpeg';
18
+ const VOICE = path.join(OUT, 'voice.wav');
19
+
20
+ const args = process.argv.slice(2);
21
+ const flag = (name) => args.includes(name);
22
+ const opt = (name) => {
23
+ const i = args.indexOf(name);
24
+ return i >= 0 ? args[i + 1] : null;
25
+ };
26
+
27
+ function findChrome() {
28
+ if (process.env.CHROME_PATH) return process.env.CHROME_PATH;
29
+ const cache = path.join(os.homedir(), '.cache/ms-playwright');
30
+ const shells = fs.existsSync(cache)
31
+ ? fs.readdirSync(cache).filter((d) => d.startsWith('chromium_headless_shell-'))
32
+ .sort((a, b) => Number(b.split('-')[1]) - Number(a.split('-')[1]))
33
+ : [];
34
+ for (const dir of shells) {
35
+ for (const rel of ['chrome-headless-shell-linux64/chrome-headless-shell', 'chrome-linux/headless_shell']) {
36
+ const p = path.join(cache, dir, rel);
37
+ if (fs.existsSync(p)) return p;
38
+ }
39
+ }
40
+ for (const p of ['/usr/bin/google-chrome', '/usr/bin/chromium', '/usr/bin/chromium-browser']) if (fs.existsSync(p)) return p;
41
+ throw new Error('No Chrome found; set CHROME_PATH');
42
+ }
43
+
44
+ const TYPES = { '.js': 'text/javascript', '.mjs': 'text/javascript', '.wav': 'audio/wav', '.json': 'application/json', '.html': 'text/html' };
45
+
46
+ function serve() {
47
+ const server = http.createServer((req, res) => {
48
+ const url = new URL(req.url, 'http://x');
49
+ if (url.pathname === '/__lab') {
50
+ res.writeHead(200, { 'content-type': 'text/html' });
51
+ res.end('<!doctype html><meta charset="utf-8"><title>audio lab</title>');
52
+ return;
53
+ }
54
+ const file = path.join(ROOT, decodeURIComponent(url.pathname));
55
+ if (!file.startsWith(ROOT) || !fs.existsSync(file) || fs.statSync(file).isDirectory()) {
56
+ res.writeHead(404);
57
+ res.end();
58
+ return;
59
+ }
60
+ res.writeHead(200, { 'content-type': TYPES[path.extname(file)] || 'application/octet-stream' });
61
+ fs.createReadStream(file).pipe(res);
62
+ });
63
+ return new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve(server)));
64
+ }
65
+
66
+ function wavSeconds(file) {
67
+ const buf = fs.readFileSync(file);
68
+ const sr = buf.readUInt32LE(24);
69
+ const channels = buf.readUInt16LE(22);
70
+ const bits = buf.readUInt16LE(34);
71
+ let off = 12;
72
+ while (off < buf.length) {
73
+ const id = buf.toString('ascii', off, off + 4);
74
+ const size = buf.readUInt32LE(off + 4);
75
+ if (id === 'data') return size / (channels * (bits / 8)) / sr;
76
+ off += 8 + size;
77
+ }
78
+ throw new Error('no data chunk');
79
+ }
80
+
81
+ // Renders in the page and returns WAV bytes plus quick stats.
82
+ async function render(page, opts) {
83
+ const result = await page.evaluate(async (o) => {
84
+ const m = await import('/engine/audio/soundtrack.js');
85
+ const t0 = performance.now();
86
+ const buf = await m.renderSoundtrack(o);
87
+ const ms = performance.now() - t0;
88
+ let peak = 0;
89
+ let sum = 0;
90
+ let bad = 0;
91
+ for (let c = 0; c < buf.numberOfChannels; c++) {
92
+ const d = buf.getChannelData(c);
93
+ for (let i = 0; i < d.length; i++) {
94
+ const v = d[i];
95
+ if (!Number.isFinite(v)) bad++;
96
+ const a = Math.abs(v);
97
+ if (a > peak) peak = a;
98
+ sum += v * v;
99
+ }
100
+ }
101
+ const wav = new Uint8Array(m.encodeWav(buf));
102
+ let bin = '';
103
+ for (let i = 0; i < wav.length; i += 0x8000) bin += String.fromCharCode.apply(null, wav.subarray(i, i + 0x8000));
104
+ return { b64: btoa(bin), ms, peak, rms: Math.sqrt(sum / (buf.length * buf.numberOfChannels)), bad };
105
+ }, opts);
106
+ return { ...result, wav: Buffer.from(result.b64, 'base64') };
107
+ }
108
+
109
+ function ebur(file, range) {
110
+ const af = [range ? `atrim=start=${range[0]}:end=${range[1]}` : null, 'ebur128=peak=true:framelog=quiet'].filter(Boolean).join(',');
111
+ const r = spawnSync(FFMPEG, ['-hide_banner', '-nostats', '-i', file, '-af', af, '-f', 'null', '-'], { encoding: 'utf8' });
112
+ const text = (r.stdout || '') + (r.stderr || '');
113
+ const I = /I:\s+(-?[\d.]+|-inf) LUFS/.exec(text);
114
+ const TP = /Peak:\s+(-?[\d.]+|-inf) dBFS/.exec(text);
115
+ return { lufs: I ? Number(I[1]) : null, truePeak: TP ? Number(TP[1]) : null };
116
+ }
117
+
118
+ function clipped(wav) {
119
+ let n = 0;
120
+ for (let o = 44; o + 1 < wav.length; o += 2) {
121
+ const s = wav.readInt16LE(o);
122
+ if (s >= 32767 || s <= -32768) n++;
123
+ }
124
+ return n;
125
+ }
126
+
127
+ function spectro(file) {
128
+ const png = file.replace(/\.wav$/, '.spectrum.png');
129
+ spawnSync(FFMPEG, ['-hide_banner', '-y', '-i', file, '-lavfi', 'showspectrumpic=s=1400x480:legend=1:scale=log:fscale=log:color=intensity', png]);
130
+ const wave = file.replace(/\.wav$/, '.wave.png');
131
+ spawnSync(FFMPEG, ['-hide_banner', '-y', '-i', file, '-lavfi', 'aformat=channel_layouts=mono,showwavespic=s=1400x240:scale=lin:colors=white', wave]);
132
+ return png;
133
+ }
134
+
135
+ const sha = (b) => crypto.createHash('sha256').update(b).digest('hex').slice(0, 16);
136
+ const db = (x) => (x > 0 ? (20 * Math.log10(x)).toFixed(1) : '-inf');
137
+
138
+ async function main() {
139
+ fs.mkdirSync(OUT, { recursive: true });
140
+ if (!fs.existsSync(VOICE)) throw new Error(`Missing ${VOICE}`);
141
+ const vdur = wavSeconds(VOICE);
142
+ const styles = (opt('--styles') || 'warm,upbeat,calm,tech,playful').split(',');
143
+ const DUR = 40;
144
+ const starts = [2, 14, 27];
145
+ const voice = starts.map((start) => ({ url: '/.scratch/audio/voice.wav', start }));
146
+ const voiceSpans = starts.map((s) => ({ start: s, end: s + vdur }));
147
+ const scenes = [{ start: 0, dur: 13 }, { start: 13, dur: 13 }, { start: 26, dur: 14 }];
148
+ const cues = [
149
+ { name: 'pop', t: 2.5 }, { name: 'whoosh', t: 5 }, { name: 'blip', t: 7, pitch: 0 }, { name: 'blip', t: 7.4, pitch: 1 },
150
+ { name: 'blip', t: 7.8, pitch: 2 }, { name: 'swipe', t: 12.6 }, { name: 'scribble', t: 15, dur: 0.8 }, { name: 'ding', t: 20 },
151
+ { name: 'swipe', t: 25.6 }, { name: 'chime', t: 37.2 },
152
+ ];
153
+
154
+ const server = await serve();
155
+ const base = `http://127.0.0.1:${server.address().port}`;
156
+ const browser = await chromium.launch({ executablePath: findChrome(), headless: true, args: ['--autoplay-policy=no-user-gesture-required'] });
157
+ const rows = [];
158
+ try {
159
+ const page = await browser.newPage();
160
+ page.on('pageerror', (e) => console.error('pageerror', e.message));
161
+ await page.goto(`${base}/__lab`);
162
+
163
+ const save = (name, r) => {
164
+ const file = path.join(OUT, `${name}.wav`);
165
+ fs.writeFileSync(file, r.wav);
166
+ return file;
167
+ };
168
+
169
+ // voice reference
170
+ const v = await render(page, { duration: DUR, voice });
171
+ const vFile = save('voice-only', v);
172
+ const vL = ebur(vFile);
173
+ rows.push({ name: 'voice-only', ...vL, ms: v.ms.toFixed(0), peak: db(v.peak), clip: clipped(v.wav) });
174
+
175
+ for (const style of styles) {
176
+ const music = { style, seed: 1, volume: 0.5 };
177
+ const bed = await render(page, { duration: DUR, music, scenes });
178
+ const bedFile = save(`${style}-bed`, bed);
179
+ const bedL = ebur(bedFile, [2, 36]);
180
+ const ducked = await render(page, { duration: DUR, music, scenes, voiceSpans });
181
+ const duckedFile = save(`${style}-ducked`, ducked);
182
+ const duckL = ebur(duckedFile, [3, 11]);
183
+ const mix = await render(page, { duration: DUR, voice, voiceSpans, music, scenes, sfx: cues });
184
+ const mixFile = save(style, mix);
185
+ const mixL = ebur(mixFile);
186
+ rows.push({
187
+ name: style, ...mixL, ms: mix.ms.toFixed(0), peak: db(mix.peak), clip: clipped(mix.wav), bad: mix.bad,
188
+ bedLufs: bedL.lufs, bedUnderVoice: (vL.lufs - bedL.lufs).toFixed(1), duckedLufs: duckL.lufs, duckedUnderVoice: (vL.lufs - duckL.lufs).toFixed(1),
189
+ });
190
+ if (!flag('--no-spectro')) {
191
+ spectro(mixFile);
192
+ spectro(bedFile);
193
+ }
194
+ }
195
+
196
+ // determinism
197
+ const d1 = await render(page, { duration: DUR, voice, voiceSpans, music: { style: 'warm', seed: 3 }, scenes, sfx: cues });
198
+ const d2 = await render(page, { duration: DUR, voice, voiceSpans, music: { style: 'warm', seed: 3 }, scenes, sfx: cues });
199
+ const d3 = await render(page, { duration: DUR, voice, voiceSpans, music: { style: 'warm', seed: 4 }, scenes, sfx: cues });
200
+ console.log(`determinism: seed3 ${sha(d1.wav)} vs ${sha(d2.wav)} -> ${sha(d1.wav) === sha(d2.wav) ? 'IDENTICAL' : 'DIFFERENT'}; seed4 ${sha(d3.wav)} (${sha(d3.wav) !== sha(d1.wav) ? 'differs as expected' : 'UNEXPECTEDLY SAME'})`);
201
+
202
+ // the same render in Node (no browser) should produce the same bytes
203
+ const { renderSoundtrack, encodeWav } = await import('../engine/audio/soundtrack.js');
204
+ const { parseWav, toMono } = await import('../engine/audio/pcm.js');
205
+ const raw = fs.readFileSync(VOICE);
206
+ const w = parseWav(raw.buffer.slice(raw.byteOffset, raw.byteOffset + raw.byteLength));
207
+ const data = toMono(w.channels);
208
+ const nodeBuf = await renderSoundtrack({
209
+ duration: DUR, voice: starts.map((start) => ({ data, sampleRate: w.sampleRate, start })), voiceSpans, music: { style: 'warm', seed: 3 }, scenes, sfx: cues,
210
+ });
211
+ const nodeWav = Buffer.from(encodeWav(nodeBuf));
212
+ console.log(`node vs chrome: ${sha(nodeWav)} vs ${sha(d1.wav)} -> ${sha(nodeWav) === sha(d1.wav) ? 'IDENTICAL' : 'DIFFERENT'}`);
213
+
214
+ // each sound effect alone: sample peak
215
+ const names = await page.evaluate(async () => Object.keys((await import('/engine/audio/soundtrack.js')).SFX));
216
+ const sfxRows = [];
217
+ for (const name of names) {
218
+ const r = await render(page, { duration: 2.5, sfx: [{ name, t: 0.2 }] });
219
+ sfxRows.push(`${name}:${db(r.peak)}`);
220
+ }
221
+ console.log('sfx sample peaks dBFS (voice peak is about', db(v.peak), '):', sfxRows.join(' '));
222
+ const sheet = await render(page, { duration: names.length * 1.2 + 1, sfx: names.map((name, i) => ({ name, t: 0.3 + i * 1.2, pitch: i % 5 })) });
223
+ const sheetFile = save('sfx-sheet', sheet);
224
+ if (!flag('--no-spectro')) spectro(sheetFile);
225
+ console.log('sfx sheet order:', names.join(', '));
226
+
227
+ // unknown sfx must throw
228
+ const err = await page.evaluate(async () => {
229
+ const m = await import('/engine/audio/soundtrack.js');
230
+ try {
231
+ await m.renderSoundtrack({ duration: 1, sfx: [{ name: 'boing', t: 0 }] });
232
+ return 'no error';
233
+ } catch (e) {
234
+ return e.message;
235
+ }
236
+ });
237
+ console.log('unknown sfx ->', err);
238
+
239
+ // long render timing
240
+ if (!flag('--skip-long')) {
241
+ for (const style of ['upbeat', 'warm']) {
242
+ const LONG = 180;
243
+ const longStarts = [];
244
+ for (let s = 1; s < LONG - 10; s += 11) longStarts.push(s);
245
+ const long = await render(page, {
246
+ duration: LONG,
247
+ voice: longStarts.map((start) => ({ url: '/.scratch/audio/voice.wav', start })),
248
+ voiceSpans: longStarts.map((s) => ({ start: s, end: s + vdur })),
249
+ music: { style, seed: 2 },
250
+ scenes: longStarts.map((s, i) => ({ start: s - 0.5 < 0 ? 0 : s - 0.5, dur: 11 })),
251
+ sfx: longStarts.flatMap((s) => [{ name: 'pop', t: s + 1 }, { name: 'whoosh', t: s + 4 }, { name: 'scribble', t: s + 6 }]),
252
+ });
253
+ const f = save(`long-${style}`, long);
254
+ const L = ebur(f);
255
+ console.log(`180 s ${style}: render ${long.ms.toFixed(0)} ms, ${L.lufs} LUFS, TP ${L.truePeak} dBFS, clipped ${clipped(long.wav)}`);
256
+ }
257
+ }
258
+ } finally {
259
+ await browser.close();
260
+ server.close();
261
+ }
262
+ console.table(rows);
263
+ }
264
+
265
+ main().catch((e) => {
266
+ console.error(e);
267
+ process.exit(1);
268
+ });
Binary file
Binary file
Binary file
@@ -0,0 +1,69 @@
1
+ // Small DSP helpers shared by the music and sound-effect synths.
2
+
3
+ export const mtof = (midi) => 440 * Math.pow(2, (midi - 69) / 12);
4
+ export const dbToGain = (db) => Math.pow(10, db / 20);
5
+ export const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
6
+
7
+ // Look-ahead peak limiter applied to rendered channel data in place.
8
+ // Returns the fraction of samples that needed gain reduction.
9
+ export function limitInPlace(channels, sampleRate, { ceilingDb = -1, lookaheadMs = 5, attackMs = 1, releaseMs = 90 } = {}) {
10
+ const ceiling = dbToGain(ceilingDb);
11
+ const n = channels[0].length;
12
+ const req = new Float32Array(n);
13
+ let any = false;
14
+ for (let i = 0; i < n; i++) {
15
+ let p = 0;
16
+ for (const c of channels) {
17
+ const v = Math.abs(c[i]);
18
+ if (v > p) p = v;
19
+ }
20
+ if (p > ceiling) {
21
+ req[i] = ceiling / p;
22
+ any = true;
23
+ } else {
24
+ req[i] = 1;
25
+ }
26
+ }
27
+ if (!any) return 0;
28
+
29
+ // sliding minimum over [i, i + L]: gain starts falling before a peak arrives
30
+ const L = Math.max(1, Math.round((lookaheadMs * sampleRate) / 1000));
31
+ const win = new Float32Array(n);
32
+ const dq = new Int32Array(n);
33
+ let head = 0;
34
+ let tail = 0;
35
+ for (let i = n - 1; i >= 0; i--) {
36
+ while (tail > head && req[dq[tail - 1]] >= req[i]) tail--;
37
+ dq[tail++] = i;
38
+ while (dq[head] > i + L) head++;
39
+ win[i] = req[dq[head]];
40
+ }
41
+
42
+ const aCoef = Math.exp(-1 / ((attackMs * sampleRate) / 1000));
43
+ const rCoef = Math.exp(-1 / ((releaseMs * sampleRate) / 1000));
44
+ let g = 1;
45
+ let reduced = 0;
46
+ for (let i = 0; i < n; i++) {
47
+ const target = win[i];
48
+ g = target < g ? target + (g - target) * aCoef : target + (g - target) * rCoef;
49
+ if (g < 0.9999) reduced++;
50
+ for (const c of channels) {
51
+ let v = c[i] * g;
52
+ if (v > ceiling) v = ceiling;
53
+ else if (v < -ceiling) v = -ceiling;
54
+ c[i] = v;
55
+ }
56
+ }
57
+ return reduced / n;
58
+ }
59
+
60
+ // Short fades at both edges so the file never starts or stops on a click.
61
+ export function fadeEdges(channels, sampleRate, inSeconds = 0.004, outSeconds = 0.015) {
62
+ const n = channels[0].length;
63
+ const fi = Math.min(n, Math.floor(inSeconds * sampleRate));
64
+ const fo = Math.min(n, Math.floor(outSeconds * sampleRate));
65
+ for (const c of channels) {
66
+ for (let i = 0; i < fi; i++) c[i] *= i / fi;
67
+ for (let i = 0; i < fo; i++) c[n - 1 - i] *= i / fo;
68
+ }
69
+ }