@senseihq/emaki-cli 0.1.0 → 0.1.2

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 (65) hide show
  1. package/README.md +42 -7
  2. package/package.json +4 -2
  3. package/plugin/.claude-plugin/plugin.json +1 -1
  4. package/plugin/modules/campaign/README.md +10 -3
  5. package/plugin/modules/campaign/day-script.template.md +2 -1
  6. package/plugin/modules/posting-desk/README.md +2 -2
  7. package/plugin/skills/emaki/references/03-content-model.md +7 -4
  8. package/plugin/skills/emaki/references/04-scene-authoring.md +3 -0
  9. package/plugin/skills/emaki/references/05-voice-and-video.md +41 -8
  10. package/plugin/skills/emaki/references/09-publishing.md +5 -2
  11. package/plugin/skills/story-media/SKILL.md +2 -0
  12. package/plugin/skills/story-publish/SKILL.md +18 -4
  13. package/src/api.js +12 -1
  14. package/src/build-media.js +166 -0
  15. package/src/build-video.js +113 -0
  16. package/src/campaign.js +138 -0
  17. package/src/capture.js +6 -118
  18. package/src/carousel.js +91 -0
  19. package/src/commands/campaign.js +63 -0
  20. package/src/commands/posting.js +74 -0
  21. package/src/commands/production.js +128 -0
  22. package/src/commands/run.js +19 -0
  23. package/src/commands/setup.js +97 -0
  24. package/src/csv.js +42 -0
  25. package/src/day-script.js +66 -0
  26. package/src/desk-client.js +37 -0
  27. package/src/desk-plan.js +57 -0
  28. package/src/film-checks.js +102 -0
  29. package/src/films.js +7 -75
  30. package/src/fit.js +79 -0
  31. package/src/http.js +30 -0
  32. package/src/index.js +10 -184
  33. package/src/init.js +10 -13
  34. package/src/media.js +80 -0
  35. package/src/migrate.js +84 -0
  36. package/src/publish.js +136 -0
  37. package/src/render.js +125 -0
  38. package/src/show-page.js +75 -0
  39. package/src/stage.js +120 -0
  40. package/src/stories.js +66 -0
  41. package/src/takes.js +18 -0
  42. package/src/tts-cloud.js +122 -0
  43. package/src/tts-io.js +51 -0
  44. package/src/tts-offline.js +85 -0
  45. package/src/tts.js +5 -237
  46. package/src/upload/instagram.js +34 -0
  47. package/src/upload/youtube.js +90 -0
  48. package/src/util.js +7 -0
  49. package/src/voice.js +8 -118
  50. package/src/youtube-text.js +58 -0
  51. package/templates/content/films/measure-the-right-work/film.json +9 -0
  52. package/templates/content/films/measure-the-right-work/look.css +1 -0
  53. package/templates/content/films/measure-the-right-work/timing.en.json +24 -0
  54. package/templates/content/films/measure-the-right-work/timing.es.json +24 -0
  55. package/templates/content/films/measure-the-right-work/voice/en/close.m4a +0 -0
  56. package/templates/content/films/measure-the-right-work/voice/en/groups.m4a +0 -0
  57. package/templates/content/films/measure-the-right-work/voice/en/hook.m4a +0 -0
  58. package/templates/content/films/measure-the-right-work/voice/en/pair.m4a +0 -0
  59. package/templates/content/films/measure-the-right-work/voice/en/problem.m4a +0 -0
  60. package/templates/content/films/measure-the-right-work/voice/es/close.m4a +0 -0
  61. package/templates/content/films/measure-the-right-work/voice/es/groups.m4a +0 -0
  62. package/templates/content/films/measure-the-right-work/voice/es/hook.m4a +0 -0
  63. package/templates/content/films/measure-the-right-work/voice/es/pair.m4a +0 -0
  64. package/templates/content/films/measure-the-right-work/voice/es/problem.m4a +0 -0
  65. package/templates/film/look.css +1 -0
package/src/voice.js CHANGED
@@ -1,10 +1,14 @@
1
- // The narration: choose a voice per locale, synthesise takes, fit scene times to them, and build the final videos
2
- // (voice + score + captions, -14 LUFS).
1
+ // The narration: choose a voice per locale and synthesise the takes. Fitting scene times to them (fit.js) and
2
+ // building the final videos (build-video.js: voice + score + captions, -14 LUFS) are re-exported from here.
3
3
  import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
4
4
  import { join } from 'node:path'
5
- import { SUFFIX } from './config.js'
6
5
  import { OFFLINE, provider, TTSError, voiceConfig } from './tts.js'
7
- import { die, load, mediaLength, pad2, run, save } from './util.js'
6
+ import { die, load, mediaLength, pad2, save } from './util.js'
7
+
8
+ // The steps after the takes, re-exported: the timing (fit.js), the final videos (build-video.js), the takes (takes.js).
9
+ export { fit, voiceWeb } from './fit.js'
10
+ export { build, captions } from './build-video.js'
11
+ export { takesFor } from './takes.js'
8
12
 
9
13
  export const NO_PROVIDER = (loc) => `no voice provider is set for ${loc}. Choose one and record it with set-voice, for example:
10
14
  offline piper (good, free) kokoro (very natural, free) macos (Mac drafts) espeak (robotic drafts)
@@ -100,117 +104,3 @@ export async function voice(p, slug, { locale, only, provider: override, opts =
100
104
  writeFileSync(join(takes, 'provider.json'), JSON.stringify(keep, null, 1) + '\n')
101
105
  return made
102
106
  }
103
-
104
- /** scene id → [take file, voice line] for the takes that exist. */
105
- export function takesFor(p, slug, locale) {
106
- const d = p.filmDir(slug), lines = load(join(d, 'voice', `${locale}.json`)), folder = p.prod(slug, locale, 'takes')
107
- const out = new Map()
108
- lines.forEach((l, i) => {
109
- for (const ext of ['wav', 'mp3', 'm4a', 'aiff']) {
110
- const f = join(folder, `take-${pad2(i + 1)}.${ext}`)
111
- if (existsSync(f)) { out.set(l.scene, [f, l]); break }
112
- }
113
- })
114
- return out
115
- }
116
-
117
- /** timing.<locale>.json: each scene runs at least lead + take + tail; shorter takes keep the design time. */
118
- export function fit(p, slug, { locale, check = false, length = mediaLength } = {}) {
119
- const d = p.filmDir(slug), film = load(join(d, 'film.json')), takes = takesFor(p, slug, locale)
120
- const tp = join(d, `timing.${locale}.json`)
121
- const timing = existsSync(tp) ? load(tp) : { scenes: {} }
122
- const tsc = (timing.scenes ??= {})
123
- const rows = []
124
- for (const s of film.scenes) {
125
- const c = tsc[s.id] ?? {}
126
- const holds = (c.holds ?? []).reduce((n, h) => n + h[1], 0)
127
- const L = takes.has(s.id) ? length(takes.get(s.id)[0]) : 0
128
- const need = L ? Math.ceil((p.lead + L + p.tail) * 10) / 10 : 0
129
- const base = s.dur + holds, runs = Math.max(base, need)
130
- if (runs > base + 1e-6) c.dur = runs
131
- else delete c.dur
132
- if (Object.keys(c).length) tsc[s.id] = c
133
- else delete tsc[s.id]
134
- rows.push({ scene: s.id, design: s.dur, holds, take: L, runs, longer: runs > base + 1e-6 })
135
- }
136
- if (!check) save(tp, timing)
137
- return { rows, total: rows.reduce((n, r) => n + r.runs, 0), path: p.rel(tp), written: !check }
138
- }
139
-
140
- const stamp = (t, sep = '.') => {
141
- const h = Math.floor(t / 3600), m = Math.floor((t % 3600) / 60), s = t % 60
142
- return `${pad2(h)}:${pad2(m)}:${s.toFixed(3).padStart(6, '0')}`.replace('.', sep)
143
- }
144
-
145
- /** Captions from the voice lines, spread over each take by sentence length. */
146
- export function captions(takes, starts, lead, length = mediaLength) {
147
- const vtt = ['WEBVTT', ''], srt = []
148
- let k = 0
149
- for (const [sid, [f, line]] of takes) {
150
- let t0 = starts.get(sid)[0] + lead
151
- const span = length(f) - 0.1
152
- const parts = line.text.split(/(?<=[.!?¿¡;:])\s+/).map((x) => x.trim()).filter(Boolean)
153
- const total = parts.reduce((n, x) => n + x.length, 0)
154
- for (const x of parts) {
155
- const dd = (span * x.length) / total
156
- k++
157
- vtt.push(`${stamp(t0)} --> ${stamp(t0 + dd)}`, x, '')
158
- srt.push(String(k), `${stamp(t0, ',')} --> ${stamp(t0 + dd, ',')}`, x, '')
159
- t0 += dd
160
- }
161
- }
162
- return { vtt: vtt.join('\n'), srt: srt.join('\n') }
163
- }
164
-
165
- /** Final videos per orientation: picture + voice + ducked score, captions burned in (and shipped as .srt/.vtt). */
166
- export function build(p, slug, { locale, noCaptions = false, log = console.info } = {}) {
167
- const d = p.filmDir(slug), film = load(join(d, 'film.json'))
168
- const tp = join(d, `timing.${locale}.json`)
169
- const tm = existsSync(tp) ? (load(tp).scenes ?? {}) : {}
170
- const takes = takesFor(p, slug, locale)
171
- if (!takes.size) die(`no takes in ${p.rel(p.prod(slug, locale, 'takes'))}; run \`emaki voice\` (or record them) first`)
172
- const starts = new Map()
173
- let at = 0
174
- for (const s of film.scenes) {
175
- const holds = (tm[s.id]?.holds ?? []).reduce((n, h) => n + h[1], 0)
176
- const dur = Math.max(s.dur + holds, tm[s.id]?.dur ?? 0)
177
- starts.set(s.id, [at, dur])
178
- at += dur
179
- }
180
- const render = p.prod(slug, locale, 'render'), out = p.prod(slug, locale, 'out')
181
- mkdirSync(out, { recursive: true })
182
- const cap = captions(takes, starts, p.lead)
183
- const srtPath = join(out, `${slug}-${locale}.srt`)
184
- writeFileSync(join(out, `${slug}-${locale}.vtt`), cap.vtt)
185
- writeFileSync(srtPath, cap.srt)
186
- const inputs = [], filters = []
187
- ;[...takes].forEach(([sid, [f]], i) => {
188
- inputs.push('-i', f)
189
- const ms = Math.round((starts.get(sid)[0] + p.lead) * 1000)
190
- filters.push(`[${i}:a]aresample=48000,adelay=${ms}|${ms},apad[v${i}]`)
191
- })
192
- const voicePath = join(out, 'voice.wav')
193
- run('ffmpeg', ['-y', '-v', 'error', ...inputs, '-filter_complex',
194
- filters.join(';') + ';' + [...takes].map((_, i) => `[v${i}]`).join('') + `amix=inputs=${takes.size}:normalize=0,atrim=0:${at.toFixed(3)}[vo]`,
195
- '-map', '[vo]', '-ac', '2', voicePath])
196
- const score = join(render, 'score.wav'), hasScore = existsSync(score), built = []
197
- for (const layout of ['landscape', 'portrait']) {
198
- const pic = join(render, `${slug}-${locale}-${SUFFIX[layout]}.mp4`)
199
- if (!existsSync(pic)) continue
200
- const dst = join(out, `${slug}-${locale}-${SUFFIX[layout]}.mp4`)
201
- const mix = hasScore
202
- ? `[1:a]volume=1[vo];[2:a]volume=${p.cfg.scoreLevel ?? 0.55}[sc];[sc][vo]sidechaincompress=threshold=0.05:ratio=6:release=400[duck];[duck][1:a]amix=inputs=2:normalize=0,loudnorm=I=-14:TP=-1.5:LRA=11[a]`
203
- : '[1:a]loudnorm=I=-14:TP=-1.5:LRA=11[a]'
204
- // libass lays SRT out on a 384x288 canvas scaled to the video, so these are in 288ths of the height:
205
- // landscape 16 ≈ 60 px text 127 px up; portrait 9 ≈ 60 px text 333 px up (clear of the platform's buttons).
206
- const size = layout === 'landscape' ? 16 : 9, margin = layout === 'landscape' ? 34 : 50
207
- const burn = noCaptions ? [] : ['-vf', `subtitles=${srtPath.replace(/([:\\'])/g, '\\$1')}:force_style='FontName=Inter,FontSize=${size},PrimaryColour=&H00FFFFFF,OutlineColour=&H66000000,BackColour=&H66000000,BorderStyle=3,Outline=5,Shadow=0,MarginV=${margin}'`]
208
- run('ffmpeg', ['-y', '-v', 'error', '-i', pic, '-i', voicePath, ...(hasScore ? ['-i', score] : []), '-filter_complex', mix,
209
- '-map', '0:v', '-map', '[a]', ...burn, '-c:v', 'libx264', '-crf', '18', '-preset', 'medium', '-pix_fmt', 'yuv420p',
210
- '-c:a', 'aac', '-b:a', '192k', '-t', at.toFixed(3), '-movflags', '+faststart', dst])
211
- log(`built ${p.rel(dst)}`)
212
- built.push(dst)
213
- }
214
- log(`captions: ${p.rel(out)}/${slug}-${locale}.vtt/.srt`)
215
- return { built, duration: at }
216
- }
@@ -0,0 +1,58 @@
1
+ // The words that go up with a YouTube film: chapters YouTube accepts, the description, and how an update merges
2
+ // ours with what is already on the video.
3
+ import { readFileSync } from 'node:fs'
4
+ import { join } from 'node:path'
5
+ import { filmFiles, storyUrl } from './stories.js'
6
+ import { exists, load, runningTime } from './util.js'
7
+
8
+ /**
9
+ * [[at, name]] for the description: first at 0:00, every chapter at least 10 s (YouTube shows none unless all its
10
+ * rules hold). Short scenes fold into the chapter they start; a short tail joins the last chapter.
11
+ */
12
+ export function chapters(plan) {
13
+ const groups = []
14
+ let cur = [], start = 0
15
+ for (const s of plan) {
16
+ cur.push(s)
17
+ if (s.at + s.dur - start >= 10 - 1e-6) {
18
+ groups.push([start, cur])
19
+ cur = []
20
+ start = s.at + s.dur
21
+ }
22
+ }
23
+ if (cur.length) groups.length ? groups.at(-1)[1].push(...cur) : groups.push([start, cur])
24
+ return groups.map(([at, ss]) => [at, ss.map((s) => s.name).join(' + ')])
25
+ }
26
+
27
+ /** Each scene's start and running time in one locale (design time, holds, and timing.<locale>.json). */
28
+ export function scenePlan(p, slug, locale) {
29
+ const d = join(p.films, slug), film = load(join(d, 'film.json'))
30
+ const tp = join(d, `timing.${locale}.json`), tm = exists(tp) ? (load(tp).scenes ?? {}) : {}
31
+ let at = 0
32
+ return film.scenes.map((s) => {
33
+ const dur = runningTime(s, tm[s.id])
34
+ const row = { id: s.id, name: s.name ?? s.id, at, dur }
35
+ at += dur
36
+ return row
37
+ })
38
+ }
39
+
40
+ /** The description to publish: the built out/description.txt, else title + chapters + the story's link. */
41
+ export function youtubeDescription(p, slug, locale, title) {
42
+ const f = filmFiles(p, slug, locale).description
43
+ if (f) return readFileSync(f, 'utf-8')
44
+ const lines = chapters(scenePlan(p, slug, locale)).map(([at, n]) => `${Math.floor(at / 60)}:${String(Math.floor(at % 60)).padStart(2, '0')} ${n}\n`).join('')
45
+ return `${title}\n\n${lines}\n${storyUrl(p, slug, locale)}\n`
46
+ }
47
+
48
+ /** prepend: ours first, then what was there (minus earlier copies of ours); replace: ours only. */
49
+ export function mergeDescription(remote, local, mode = 'prepend') {
50
+ if (mode === 'replace') return local
51
+ const ours = local.trim()
52
+ let rest = (remote ?? '').trim()
53
+ while (ours && rest.startsWith(ours)) {
54
+ rest = rest.slice(ours.length).trim()
55
+ if (rest.startsWith('---')) rest = rest.slice(3).trim()
56
+ }
57
+ return rest ? `${ours}\n\n---\n\n${rest}\n` : `${ours}\n`
58
+ }
@@ -2,6 +2,15 @@
2
2
  "title": "Measure the Right Work",
3
3
  "look": "Session board: counters, an activity chart, two paired metric cards and metric groups on a dot-grid desk. Washi paper, sumi ink, rationed vermillion for rework, jade for work that landed. The brand mark on the close.",
4
4
  "background": "#F3F0E9",
5
+ "dark": {
6
+ "background": "#1E1B18",
7
+ "palette": [
8
+ "#191614",
9
+ "#D8D0C7",
10
+ "#F2ECE4",
11
+ "#E0795C"
12
+ ]
13
+ },
5
14
  "palette": [
6
15
  "#F9F6F1",
7
16
  "#48413D",
@@ -1,5 +1,6 @@
1
1
  #stage { --ground:#F9F6F1; --main:#48413D; --second:#1F1916; --accent:#C25237; color:var(--second); font-family:var(--sans, system-ui, sans-serif) }
2
2
  #stage { --jade:#599576; --board:#F3F0E9; --dot:#DCD7CD; --tile:#FCFAF6; --hair:#DCD7CD; --mute:#7F7975; --wire:#B2ADA9; --edge:color-mix(in srgb, var(--second) 14%, transparent); --shade:color-mix(in srgb, var(--second) 7%, transparent); --soft:var(--main) }
3
+ #stage[data-mode="dark"] { --ground:#191614; --main:#D8D0C7; --second:#F2ECE4; --accent:#E0795C; --jade:#6FAE8B; --board:#1E1B18; --dot:#34302B; --tile:#26221F; --hair:#3A3530; --mute:#A0978F; --wire:#5E5751; --shade:rgba(0,0,0,.35) }
3
4
  .ground { position:absolute; inset:0; background:var(--board) }
4
5
  .art { position:absolute; inset:0; width:100%; height:100%; overflow:visible }
5
6
  .cam { position:absolute; inset:0; transform-origin:960px 540px }
@@ -0,0 +1,24 @@
1
+ {
2
+ "scenes": {
3
+ "hook": {
4
+ "voice": 0.6,
5
+ "dur": 6.3
6
+ },
7
+ "problem": {
8
+ "voice": 0.6,
9
+ "dur": 6.3
10
+ },
11
+ "pair": {
12
+ "voice": 0.6,
13
+ "dur": 12.2
14
+ },
15
+ "groups": {
16
+ "voice": 0.6,
17
+ "dur": 7.4
18
+ },
19
+ "close": {
20
+ "voice": 0.6,
21
+ "dur": 4.1
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "scenes": {
3
+ "groups": {
4
+ "dur": 9.1,
5
+ "voice": 0.6
6
+ },
7
+ "hook": {
8
+ "voice": 0.6,
9
+ "dur": 6.4
10
+ },
11
+ "problem": {
12
+ "voice": 0.6,
13
+ "dur": 7.7
14
+ },
15
+ "pair": {
16
+ "voice": 0.6,
17
+ "dur": 12.2
18
+ },
19
+ "close": {
20
+ "voice": 0.6,
21
+ "dur": 5.1
22
+ }
23
+ }
24
+ }
@@ -1,5 +1,6 @@
1
1
  #stage { --ground:#F9F6F1; --main:#48413D; --second:#1F1916; --accent:#C25237; color:var(--second); font-family:var(--sans, system-ui, sans-serif) }
2
2
  #stage { --jade:#599576; --board:#F3F0E9; --dot:#DCD7CD; --tile:#FCFAF6; --hair:#DCD7CD; --mute:#7F7975; --wire:#B2ADA9; --edge:color-mix(in srgb, var(--second) 14%, transparent); --shade:color-mix(in srgb, var(--second) 7%, transparent); --soft:var(--main) }
3
+ #stage[data-mode="dark"] { --ground:#191614; --main:#D8D0C7; --second:#F2ECE4; --accent:#E0795C; --jade:#6FAE8B; --board:#1E1B18; --dot:#34302B; --tile:#26221F; --hair:#3A3530; --mute:#A0978F; --wire:#5E5751; --shade:rgba(0,0,0,.35) }
3
4
  .ground { position:absolute; inset:0; background:var(--board) }
4
5
  .art { position:absolute; inset:0; width:100%; height:100%; overflow:visible }
5
6
  .cam { position:absolute; inset:0; transform-origin:960px 540px }