@phil65/demoreel 0.5.1 → 0.6.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.
package/README.md CHANGED
@@ -84,7 +84,8 @@ Each run writes into `out/<name>/`:
84
84
 
85
85
  | file | what |
86
86
  | --- | --- |
87
- | `<name>.mp4` | the rendered video |
87
+ | `<name>.mp4` | the rendered video (with muxed AAC audio when `scene.say()` is used) |
88
+ | `<name>.vtt` | WebVTT subtitles aligned to the rendered video (when `scene.say()` is used) |
88
89
  | `<name>.openscreen` | OpenScreen v2 project: open it in the OpenScreen app to tweak by hand, then `demoreel render` |
89
90
  | `recording.mp4` + `.cursor.json` | raw CFR recording and cursor telemetry (OpenScreen's sidecar format) |
90
91
  | `timeline.json` | what happened when: actions with target boxes, zoom / trim regions, captions, timings |
@@ -106,6 +107,7 @@ Each run writes into `out/<name>/`:
106
107
  | `press(key, { show, duration })` | keyboard shortcut (Playwright syntax); optional keycap HUD pill |
107
108
  | `pause(ms)` | wait |
108
109
  | `caption(text, { duration, wait })` | caption overlay (an OpenScreen text annotation, sharp at any zoom) |
110
+ | `say(text, [opts], [fn])` | voiceover narration via `@phil65/anyvoice` (free Edge TTS by default, OpenAI, ElevenLabs); supports `say(text, async (cue) => { await cue.at("word"); ... })` + `.vtt` subtitles |
109
111
  | `zoom(target, { depth, duration, context, wait })` | explicit zoom (integer tier `1..6`: 1.25x..5x) overriding auto zooms |
110
112
  | `highlight(target, { duration, color, dim, badge, zoom })` | outline with optional spotlight dim backdrop and callout badge |
111
113
 
@@ -122,7 +124,36 @@ JSON, relative to the scenario file), `colorScheme`, `seed`, `pacing`
122
124
  (`speed`, `beforeAction`, `afterClick`, `typeDelay`, ...), `zoom` (see below), `look`
123
125
  (`wallpaper`, `padding`, `borderRadius`, `shadowIntensity`, `aspectRatio`,
124
126
  `captionPosition`, `showKeys`), `cursor` (`size`, `clickBounce`, `smoothing`, `motionBlur`,
125
- `show`), `clickRipple`, `trimIdle` (`true` or `{ minMs, keepMs, mode, speed, ignoreFrames }`).
127
+ `show`), `clickRipple`, `trimIdle` (`true` or `{ minMs, keepMs, mode, speed, ignoreFrames }`),
128
+ `voice` (`{ provider: "edge" | "openai" | "elevenlabs", voice, model, speed, pitch, volume, instructions, gapMs, padMs, captions: "vtt" | "burned" | "off", cacheDir }`).
129
+
130
+ ### Voiceover narration (`scene.say`)
131
+
132
+ Add synced voiceover with zero API keys (defaults to free Microsoft Edge Neural TTS via `@phil65/anyvoice`, with SHA-256 disk caching so re-runs only synthesize edited lines):
133
+
134
+ ```ts
135
+ export default defineScenario({
136
+ name: "checkout",
137
+ voice: { provider: "edge", voice: "en-US-AndrewMultilingualNeural", speed: 1.05 },
138
+ async run(scene) {
139
+ await scene.goto("http://localhost:3000/");
140
+ // Standalone beat: holds automatically for the exact spoken duration
141
+ await scene.say("Welcome — let's check out in two clicks.");
142
+ // Narrate while acting: holds if actions finish faster than speech, never overlaps
143
+ await scene.say("Pick the Pro plan and click Checkout.", async (cue) => {
144
+ await cue.at("Pro", -150);
145
+ await scene.select({ label: "Plan" }, "pro");
146
+ await cue.at("Checkout", -150);
147
+ await scene.click({ role: "button", name: "Checkout" });
148
+ });
149
+ },
150
+ });
151
+ ```
152
+
153
+ - `demoreel run --dry-run` warms the SHA-256 voice cache and reports per-cue spoken durations before recording.
154
+ - `trimIdle` automatically keeps every voice cue intact while cutting dead silence between beats.
155
+ - `demoreel render` / `demoreel rezoom --render` stream-copy the OpenScreen H.264 video (`-c:v copy`), mux all cues into AAC audio at post-trim timestamps, and write `<name>.vtt`.
156
+ - Override provider or voice at run time without editing the scenario: `--voice-provider openai --voice nova` or `--no-voice`.
126
157
 
127
158
  Library: `recordScenario`, `dryRunScenario`, `resolveStorageState`, `deriveZoomRegions`,
128
159
  `deriveIdleRegions`, `buildProject`, `buildCursorData`, `buildMarks`, `renderProject`,
package/dist/args.js CHANGED
@@ -24,6 +24,9 @@ export const COMMANDS = {
24
24
  viewport: { type: "string", value: "WxH", description: "override the scenario viewport, e.g. 1280x720" },
25
25
  state: { type: "string", value: "FILE", description: "Playwright storageState JSON (overrides scenario.storageState)" },
26
26
  "dry-run": { type: "boolean", description: "run the scenario fast without ffmpeg, recording, or writing files" },
27
+ "voice-provider": { type: "string", value: "NAME", description: "override voiceover TTS provider: edge (free) | openai | elevenlabs" },
28
+ voice: { type: "string", value: "ID", description: "override voiceover voice ID" },
29
+ "no-voice": { type: "boolean", description: "skip voiceover TTS synthesis for this run" },
27
30
  headed: { type: "boolean", description: "show the browser while recording" },
28
31
  frames,
29
32
  framesheet,
package/dist/cli.js CHANGED
@@ -13,6 +13,7 @@ import { PACKAGE_ROOT } from "./openscreen.js";
13
13
  import { dryRunScenario, recordScenario, resolveStorageState } from "./record.js";
14
14
  import { renderProject, validateProject } from "./render.js";
15
15
  import { extractFrame, findFramesheet, reviewSheet } from "./sheet.js";
16
+ import { formatDryRunVoiceSummary, formatVoiceSummary } from "./voice.js";
16
17
  const fmt = (ms) => `${(ms / 1000).toFixed(1)}s`;
17
18
  const log = (msg) => console.error(msg);
18
19
  function progressPrinter(enabled) {
@@ -31,7 +32,9 @@ function progressPrinter(enabled) {
31
32
  };
32
33
  }
33
34
  function printRender(r) {
34
- log(` rendered ${r.width}x${r.height} ${(r.bytes / 1e6).toFixed(1)} MB in ${fmt(r.renderMs)} (${r.gpu ? "GPU" : "software"}, setup ${fmt(r.setupMs)}) -> ${r.outputPath}`);
35
+ log(` rendered ${r.width}x${r.height} ${(r.bytes / 1e6).toFixed(1)} MB in ${fmt(r.renderMs)} (${r.gpu ? "GPU" : "software"}, setup ${fmt(r.setupMs)})${r.audioMuxed ? " + audio" : ""} -> ${r.outputPath}`);
36
+ if (r.vttPath)
37
+ log(` subtitles: ${r.vttPath}`);
35
38
  if (r.warnings.length)
36
39
  log(` warnings: ${r.warnings.join("; ")}`);
37
40
  }
@@ -62,6 +65,21 @@ async function cmdRun({ positionals, flags }) {
62
65
  overrides.pacing = { ...scenario.pacing, speed: Number(flags.speed) };
63
66
  if (flags["trim-idle"] !== undefined)
64
67
  overrides.trimIdle = Boolean(flags["trim-idle"]) && (scenario.trimIdle || true);
68
+ if (flags["voice-provider"] !== undefined || flags.voice !== undefined || flags["no-voice"]) {
69
+ const voice = { ...scenario.voice };
70
+ if (flags["voice-provider"] !== undefined) {
71
+ const p = String(flags["voice-provider"]);
72
+ if (!["edge", "openai", "elevenlabs"].includes(p)) {
73
+ throw new UsageError("--voice-provider must be edge, openai, or elevenlabs");
74
+ }
75
+ voice.provider = p;
76
+ }
77
+ if (flags["no-voice"])
78
+ voice.enabled = false;
79
+ if (typeof flags.voice === "string")
80
+ voice.voice = flags.voice;
81
+ overrides.voice = voice;
82
+ }
65
83
  const storageState = flags.state ? String(flags.state) : undefined;
66
84
  if (flags["dry-run"]) {
67
85
  const res = await dryRunScenario(scenario, {
@@ -72,6 +90,9 @@ async function cmdRun({ positionals, flags }) {
72
90
  });
73
91
  for (const a of res.actions)
74
92
  console.log(formatActionLine(a));
93
+ if (res.voiceCues.length) {
94
+ console.log(formatDryRunVoiceSummary(res.voiceCues));
95
+ }
75
96
  if (!res.ok && res.error) {
76
97
  log(`FAIL action #${res.error.actionIndex}: ${res.error.message}`);
77
98
  process.exitCode = 1;
@@ -127,6 +148,9 @@ async function cmdRun({ positionals, flags }) {
127
148
  log(` contact sheet (${sheet.tool}): ${sheet.sheet}`);
128
149
  if (sheet.summary)
129
150
  console.log(sheet.summary);
151
+ if (timeline.voiceCues?.length) {
152
+ console.log(formatVoiceSummary(timeline.voiceCues, timeline.outputDurationMs, timeline.trimRegions, timeline.speedRegions));
153
+ }
130
154
  }
131
155
  async function cmdRender({ positionals, flags }) {
132
156
  const projectPath = path.resolve(positionals[0]);
@@ -203,6 +227,13 @@ async function cmdSheet({ positionals, flags }) {
203
227
  });
204
228
  if (sheet.summary)
205
229
  console.log(sheet.summary);
230
+ const tlDir = path.dirname(target);
231
+ if (fs.existsSync(path.join(tlDir, "timeline.json"))) {
232
+ const tl = readTimeline(tlDir);
233
+ if (tl.voiceCues?.length) {
234
+ console.log(formatVoiceSummary(tl.voiceCues, tl.outputDurationMs, tl.trimRegions, tl.speedRegions));
235
+ }
236
+ }
206
237
  log(`contact sheet (${sheet.tool}): ${sheet.sheet}`);
207
238
  console.log(sheet.sheet);
208
239
  if (sheet.report)
package/dist/compose.d.ts CHANGED
@@ -2,7 +2,8 @@ import { type IdleOptions } from "./idle.ts";
2
2
  import { type Marks } from "./marks.ts";
3
3
  import { buildProject, type LookOptions } from "./project.ts";
4
4
  import type { CursorStyle } from "./render.ts";
5
- import type { ActionRecord, Caption, CursorSample, SpeedRegion, TrimRegion, Viewport, ZoomRegion } from "./types.ts";
5
+ import type { ActionRecord, Caption, CursorSample, SpeedRegion, TrimRegion, Viewport, VoiceCue, ZoomRegion } from "./types.ts";
6
+ import type { VoiceConfig } from "./voice.ts";
6
7
  import { type ZoomOptions } from "./zoom.ts";
7
8
  export declare const TIMELINE_VERSION = 1;
8
9
  /** `timeline.json`: the agent-facing record of a run. Times in ms of the recording. */
@@ -21,12 +22,14 @@ export interface Timeline {
21
22
  look: Partial<LookOptions>;
22
23
  trimIdle: Partial<IdleOptions> | false;
23
24
  cursor?: CursorStyle;
25
+ voice?: Omit<VoiceConfig, "apiKey">;
24
26
  };
25
27
  actions: ActionRecord[];
26
28
  zoomRegions: ZoomRegion[];
27
29
  trimRegions: TrimRegion[];
28
30
  speedRegions: SpeedRegion[];
29
31
  captions: Caption[];
32
+ voiceCues?: VoiceCue[];
30
33
  timings: Record<string, number>;
31
34
  files: {
32
35
  recording: string;
@@ -34,6 +37,7 @@ export interface Timeline {
34
37
  project: string;
35
38
  marks: string;
36
39
  video: string;
40
+ vtt?: string;
37
41
  };
38
42
  /** Recording-clock times of captured frames (visual changes). */
39
43
  frameTimes: number[];
@@ -48,6 +52,7 @@ export interface ComposeInput {
48
52
  frameSize: Viewport;
49
53
  actions: ActionRecord[];
50
54
  captions: Caption[];
55
+ voiceCues?: VoiceCue[];
51
56
  samples: CursorSample[];
52
57
  frameTimes: number[];
53
58
  timings: Record<string, number>;
@@ -55,6 +60,7 @@ export interface ComposeInput {
55
60
  look?: Partial<LookOptions>;
56
61
  trimIdle?: Partial<IdleOptions> | boolean;
57
62
  cursor?: CursorStyle;
63
+ voice?: VoiceConfig;
58
64
  }
59
65
  export interface ComposeResult {
60
66
  timeline: Timeline;
package/dist/compose.js CHANGED
@@ -16,12 +16,14 @@ export function compose(input, opts = {}) {
16
16
  const layout = stageLayout(input.viewport, look);
17
17
  const zoomRegions = deriveZoomRegions(input.actions, input.viewport, input.durationMs, input.zoom, layout);
18
18
  const captions = placeCaptions(input.captions.map(({ position: _p, ...c }) => c), targetRects({ actions: input.actions, viewport: input.viewport, layout, zoomRegions }), look.captionPosition);
19
+ const voiceCues = input.voiceCues ?? [];
19
20
  const idleOpts = input.trimIdle === true ? {} : input.trimIdle || null;
20
21
  const { trimRegions, speedRegions } = idleOpts
21
22
  ? deriveIdleRegions({
22
23
  durationMs: input.durationMs,
23
24
  actions: input.actions,
24
25
  captions: input.captions,
26
+ voiceCues,
25
27
  samples: input.samples,
26
28
  zoomRegions,
27
29
  frameTimes: input.frameTimes,
@@ -53,6 +55,7 @@ export function compose(input, opts = {}) {
53
55
  durationMs: input.durationMs,
54
56
  actions: input.actions,
55
57
  captions,
58
+ voiceCues,
56
59
  zoomRegions,
57
60
  trimRegions,
58
61
  speedRegions,
@@ -61,6 +64,8 @@ export function compose(input, opts = {}) {
61
64
  });
62
65
  const marksPath = path.join(input.outDir, "marks.json");
63
66
  fs.writeFileSync(marksPath, JSON.stringify(marks, null, 1));
67
+ // Never persist secret apiKey into timeline.json.
68
+ const safeVoice = input.voice ? (({ apiKey: _k, ...rest }) => rest)(input.voice) : undefined;
64
69
  const timeline = {
65
70
  version: TIMELINE_VERSION,
66
71
  scenario: input.name,
@@ -75,12 +80,16 @@ export function compose(input, opts = {}) {
75
80
  look: input.look ?? {},
76
81
  trimIdle: idleOpts ?? false,
77
82
  ...(input.cursor ? { cursor: input.cursor } : {}),
83
+ ...(safeVoice ? { voice: safeVoice } : {}),
78
84
  },
79
85
  actions: input.actions.map(roundAction),
80
86
  zoomRegions,
81
87
  trimRegions,
82
88
  speedRegions,
83
89
  captions: captions.map((c) => ({ ...c, startMs: Math.round(c.startMs), endMs: Math.round(c.endMs) })),
90
+ ...(voiceCues.length
91
+ ? { voiceCues: voiceCues.map((c) => ({ ...c, startMs: Math.round(c.startMs), endMs: Math.round(c.endMs) })) }
92
+ : {}),
84
93
  timings: input.timings,
85
94
  files: {
86
95
  recording: path.basename(input.videoPath),
@@ -88,6 +97,7 @@ export function compose(input, opts = {}) {
88
97
  project: path.basename(projectPath),
89
98
  marks: path.basename(marksPath),
90
99
  video: `${input.name}.mp4`,
100
+ ...(voiceCues.length && safeVoice?.captions !== "off" ? { vtt: `${input.name}.vtt` } : {}),
91
101
  },
92
102
  frameTimes: input.frameTimes,
93
103
  };
@@ -137,6 +147,7 @@ export function rezoom(dir, overrides = {}) {
137
147
  frameSize: tl.frameSize,
138
148
  actions: tl.actions,
139
149
  captions: tl.captions,
150
+ voiceCues: tl.voiceCues,
140
151
  samples,
141
152
  frameTimes: tl.frameTimes ?? [],
142
153
  timings: tl.timings,
@@ -144,5 +155,6 @@ export function rezoom(dir, overrides = {}) {
144
155
  look: { ...tl.options?.look, ...overrides.look },
145
156
  trimIdle: trimIdle ?? false,
146
157
  cursor,
158
+ voice: tl.options?.voice,
147
159
  }, { keepProjectFrom: overrides.look ? undefined : projectPath });
148
160
  }
package/dist/idle.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * with OpenScreen trim regions, or speeds them up with speed regions.
5
5
  * Also maps recording times to output times through those regions.
6
6
  */
7
- import type { ActionRecord, Caption, CursorSample, SpeedRegion, TrimRegion, ZoomRegion } from "./types.ts";
7
+ import type { ActionRecord, Caption, CursorSample, SpeedRegion, TrimRegion, VoiceCue, ZoomRegion } from "./types.ts";
8
8
  export interface IdleOptions {
9
9
  /** Idle stretches shorter than this are left alone. */
10
10
  minMs: number;
@@ -23,6 +23,7 @@ export interface IdleInput {
23
23
  durationMs: number;
24
24
  actions: ActionRecord[];
25
25
  captions: Caption[];
26
+ voiceCues?: VoiceCue[];
26
27
  samples: CursorSample[];
27
28
  zoomRegions: ZoomRegion[];
28
29
  /** Screencast frame times; bursts of frames (animation, page load) count as activity. */
package/dist/idle.js CHANGED
@@ -19,12 +19,14 @@ function mergeIntervals(list) {
19
19
  export function busyIntervals(input, opts = {}) {
20
20
  const busy = [];
21
21
  for (const a of input.actions) {
22
- if (a.kind === "pause" || a.kind === "caption")
22
+ if (a.kind === "pause" || a.kind === "caption" || a.kind === "say")
23
23
  continue;
24
24
  busy.push([a.startMs - 150, a.endMs + 250]);
25
25
  }
26
26
  for (const c of input.captions)
27
27
  busy.push([c.startMs - 200, c.endMs + 200]);
28
+ for (const v of input.voiceCues ?? [])
29
+ busy.push([v.startMs - 150, v.endMs + 250]);
28
30
  for (const z of input.zoomRegions) {
29
31
  busy.push([z.startMs - ZOOM_IN_BEFORE_MS, z.startMs + ZOOM_IN_AFTER_MS]);
30
32
  busy.push([z.endMs - 100, z.endMs + ZOOM_OUT_AFTER_MS]);
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /** demoreel: scripted product demo videos (videos as code), rendered by OpenScreen's exporter. */
2
2
  export { type DryRunError, type DryRunOptions, type DryRunResult, type RecordOptions, type RecordResult, type Scenario, type ScenarioContext, defineScenario, dryRunScenario, recordScenario, resolveStorageState, } from "./record.ts";
3
- export { type ActionOptions, applyZoomAnchor, type ClickRippleOptions, DEFAULT_PACING, describeTarget, type HighlightOptions, type PacingOptions, type PressOptions, resolveTarget, Scene, type SceneClock, type Target, type TargetSpec, ZOOM_ATTRIBUTE, type ZoomOptions as SceneZoomOptions, } from "./scene.ts";
3
+ export { type ActionOptions, applyZoomAnchor, type ClickRippleOptions, DEFAULT_PACING, describeTarget, type HighlightOptions, type PacingOptions, type PressOptions, resolveTarget, type SayOptions, Scene, type SceneClock, type Target, type TargetSpec, type VoiceCueHandle, ZOOM_ATTRIBUTE, type ZoomOptions as SceneZoomOptions, } from "./scene.ts";
4
+ export { buildVoiceVtt, createVoiceSynthesizer, DEFAULT_VOICE_GAP_MS, DEFAULT_VOICE_PAD_MS, findWordTiming, formatDryRunVoiceSummary, formatVoiceSummary, lintVoiceCues, muxVoiceTrack, type SayDeliveryOptions, type SynthesizedCue, type VoiceConfig, type VoiceFinding, type VoiceProviderName, type VoiceSynthesizer, } from "./voice.ts";
4
5
  export { DEFAULT_ZOOM_OPTIONS, DEPTH_SCALES, deriveZoomRegions, depthForBox, normalizeDepth, type ZoomOptions } from "./zoom.ts";
5
6
  export { DEFAULT_IDLE_OPTIONS, deriveIdleRegions, idleIntervals, type IdleOptions, sourceToOutputMs } from "./idle.ts";
6
7
  export { buildCursorData, buildProject, type BuildProjectOptions, captionAnnotations, DEFAULT_LOOK, formatKeycap, keycapAnnotations, type KeyHudOptions, type KeyHudPosition, keycapRect, type LookOptions, normalizeSamples, type OpenScreenProject, writeProject, } from "./project.ts";
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /** demoreel: scripted product demo videos (videos as code), rendered by OpenScreen's exporter. */
2
2
  export { defineScenario, dryRunScenario, recordScenario, resolveStorageState, } from "./record.js";
3
3
  export { applyZoomAnchor, DEFAULT_PACING, describeTarget, resolveTarget, Scene, ZOOM_ATTRIBUTE, } from "./scene.js";
4
+ export { buildVoiceVtt, createVoiceSynthesizer, DEFAULT_VOICE_GAP_MS, DEFAULT_VOICE_PAD_MS, findWordTiming, formatDryRunVoiceSummary, formatVoiceSummary, lintVoiceCues, muxVoiceTrack, } from "./voice.js";
4
5
  export { DEFAULT_ZOOM_OPTIONS, DEPTH_SCALES, deriveZoomRegions, depthForBox, normalizeDepth } from "./zoom.js";
5
6
  export { DEFAULT_IDLE_OPTIONS, deriveIdleRegions, idleIntervals, sourceToOutputMs } from "./idle.js";
6
7
  export { buildCursorData, buildProject, captionAnnotations, DEFAULT_LOOK, formatKeycap, keycapAnnotations, keycapRect, normalizeSamples, writeProject, } from "./project.js";
package/dist/marks.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type NormRect, type StageLayout } from "./layout.ts";
2
2
  import { type LookOptions } from "./project.ts";
3
- import type { ActionRecord, Caption, SpeedRegion, TrimRegion, Viewport, ZoomRegion } from "./types.ts";
3
+ import type { ActionRecord, Caption, SpeedRegion, TrimRegion, Viewport, VoiceCue, ZoomRegion } from "./types.ts";
4
4
  export interface MarkPoint {
5
5
  t: number;
6
6
  x: number;
@@ -36,6 +36,7 @@ export interface MarksInput {
36
36
  durationMs: number;
37
37
  actions: ActionRecord[];
38
38
  captions: Caption[];
39
+ voiceCues?: VoiceCue[];
39
40
  zoomRegions: ZoomRegion[];
40
41
  trimRegions?: TrimRegion[];
41
42
  speedRegions?: SpeedRegion[];
package/dist/marks.js CHANGED
@@ -132,6 +132,15 @@ export function buildMarks(input) {
132
132
  for (const s of input.speedRegions ?? []) {
133
133
  marks.regions.push({ start: out(s.startMs), end: out(s.endMs), label: `${s.speed}x`, kind: "speed" });
134
134
  }
135
+ for (const v of input.voiceCues ?? []) {
136
+ const start = out(v.startMs);
137
+ marks.regions.push({
138
+ start,
139
+ end: Math.max(start, Math.min(endS, out(v.endMs))),
140
+ label: `${v.id}: ${v.text}`,
141
+ kind: "voice",
142
+ });
143
+ }
135
144
  for (const cap of input.captions) {
136
145
  const c = captionRect(cap.position ?? input.look.captionPosition);
137
146
  const start = out(cap.startMs);
package/dist/mcp.js CHANGED
@@ -18,6 +18,7 @@ import { loadScenario } from "./load.js";
18
18
  import { dryRunScenario, recordScenario, resolveStorageState } from "./record.js";
19
19
  import { renderProject, validateProject } from "./render.js";
20
20
  import { extractFrame, findFramesheet, reviewSheet } from "./sheet.js";
21
+ import { formatDryRunVoiceSummary, formatVoiceSummary, lintVoiceCues } from "./voice.js";
21
22
  function pngBlock(filePath) {
22
23
  if (!fs.existsSync(filePath))
23
24
  return null;
@@ -64,7 +65,7 @@ const logStderr = (msg) => console.error(msg);
64
65
  /** Creates a configured demoreel `McpServer` instance (connect to stdio or any MCP transport). */
65
66
  export function createMcpServer() {
66
67
  const server = new McpServer({ name: "demoreel", version: readPackageVersion() }, {
67
- instructions: "demoreel records scripted Playwright product demos with smooth cursor motion, auto-zoom, captions, keycap HUDs, and OpenScreen MP4/GIF rendering. Follow the loop: inspect_page -> write scenario -> dry_run_scenario -> run_scenario -> inspect contact sheet (and inspect_frame for dense UI) -> rezoom or refine.",
68
+ instructions: "demoreel records scripted Playwright product demos with smooth cursor motion, auto-zoom, captions, keycap HUDs, voiceover narration (scene.say), and OpenScreen MP4/GIF rendering. Follow the loop: inspect_page -> write scenario -> dry_run_scenario (validates selectors and warms voice cache) -> run_scenario -> inspect contact sheet + voice lint (and inspect_frame for dense UI) -> rezoom or refine.",
68
69
  });
69
70
  server.registerTool("doctor", {
70
71
  title: "Check demoreel environment",
@@ -174,14 +175,27 @@ export function createMcpServer() {
174
175
  scenarioPath: z.string().describe("Path to the scenario file (*.scenario.ts/.mts/.mjs)."),
175
176
  viewport: z.string().optional().describe("Optional WxH viewport override."),
176
177
  state: z.string().optional().describe("Optional Playwright storageState JSON file path."),
178
+ voiceProvider: z.enum(["edge", "openai", "elevenlabs"]).optional().describe("Override voiceover TTS provider."),
179
+ voice: z.string().optional().describe("Override voiceover voice ID."),
180
+ noVoice: z.boolean().optional().describe("Skip TTS synthesis during dry-run."),
177
181
  }),
178
182
  annotations: { readOnlyHint: true, openWorldHint: true },
179
- }, async ({ scenarioPath, viewport, state }) => {
183
+ }, async ({ scenarioPath, viewport, state, voiceProvider, voice, noVoice }) => {
180
184
  const file = path.resolve(scenarioPath);
181
185
  const scenario = await loadScenario(file);
182
186
  const overrides = {};
183
187
  if (viewport)
184
188
  overrides.viewport = parseSize(viewport);
189
+ if (voiceProvider || voice || noVoice) {
190
+ const vc = { ...scenario.voice };
191
+ if (voiceProvider)
192
+ vc.provider = voiceProvider;
193
+ if (voice)
194
+ vc.voice = voice;
195
+ if (noVoice)
196
+ vc.enabled = false;
197
+ overrides.voice = vc;
198
+ }
185
199
  let failureAria = "";
186
200
  const tmpPng = path.join(os.tmpdir(), `demoreel-fail-${Date.now()}.png`);
187
201
  try {
@@ -195,6 +209,9 @@ export function createMcpServer() {
195
209
  },
196
210
  });
197
211
  const lines = res.actions.map((a, i) => `${i}: ok ${a.kind}${a.label ? ` ${a.label}` : ""}`);
212
+ if (res.voiceCues.length) {
213
+ lines.push("", formatDryRunVoiceSummary(res.voiceCues));
214
+ }
198
215
  if (!res.ok && res.error) {
199
216
  lines.push(`FAIL action #${res.error.actionIndex}: ${res.error.message}`);
200
217
  if (failureAria)
@@ -228,6 +245,9 @@ export function createMcpServer() {
228
245
  frames: z.number().int().min(4).max(32).optional().default(12).describe("Number of contact-sheet tiles (default 12)."),
229
246
  state: z.string().optional().describe("Optional Playwright storageState JSON file path."),
230
247
  render: z.boolean().optional().default(true).describe("Render MP4 after recording (default true)."),
248
+ voiceProvider: z.enum(["edge", "openai", "elevenlabs"]).optional().describe("Override voiceover TTS provider."),
249
+ voice: z.string().optional().describe("Override voiceover voice ID."),
250
+ noVoice: z.boolean().optional().describe("Disable voiceover synthesis for this run."),
231
251
  }),
232
252
  annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
233
253
  }, async (args, ctx) => {
@@ -241,6 +261,16 @@ export function createMcpServer() {
241
261
  overrides.pacing = { ...scenario.pacing, speed: args.speed };
242
262
  if (args.trimIdle !== undefined)
243
263
  overrides.trimIdle = args.trimIdle && (scenario.trimIdle || true);
264
+ if (args.voiceProvider || args.voice || args.noVoice) {
265
+ const vc = { ...scenario.voice };
266
+ if (args.voiceProvider)
267
+ vc.provider = args.voiceProvider;
268
+ if (args.voice)
269
+ vc.voice = args.voice;
270
+ if (args.noVoice)
271
+ vc.enabled = false;
272
+ overrides.voice = vc;
273
+ }
244
274
  const outDir = path.resolve(args.outDir ?? path.join("out", scenario.name));
245
275
  progress(5, `Recording "${scenario.name}"...`);
246
276
  const rec = await recordScenario(scenario, {
@@ -282,6 +312,14 @@ export function createMcpServer() {
282
312
  summary.bytes = rendered.bytes;
283
313
  summary.gpu = rendered.gpu;
284
314
  summary.renderMs = rendered.renderMs;
315
+ if (rendered.audioMuxed)
316
+ summary.audioMuxed = true;
317
+ if (rendered.vttPath)
318
+ summary.vttPath = rendered.vttPath;
319
+ if (rec.timeline.voiceCues?.length) {
320
+ summary.voiceFindings = lintVoiceCues(rec.timeline.voiceCues, rec.timeline.outputDurationMs, rec.timeline.trimRegions, rec.timeline.speedRegions);
321
+ summary.voiceSummary = formatVoiceSummary(rec.timeline.voiceCues, rec.timeline.outputDurationMs, rec.timeline.trimRegions, rec.timeline.speedRegions);
322
+ }
285
323
  if (args.gif) {
286
324
  progress(92, "Exporting GIF...");
287
325
  const g = await exportGif(mp4);
package/dist/record.d.ts CHANGED
@@ -4,7 +4,8 @@ import type { IdleOptions } from "./idle.ts";
4
4
  import type { LookOptions } from "./project.ts";
5
5
  import type { CursorStyle } from "./render.ts";
6
6
  import { type ClickRippleOptions, type PacingOptions, Scene } from "./scene.ts";
7
- import type { ActionRecord, RecordingResult, Viewport } from "./types.ts";
7
+ import type { ActionRecord, RecordingResult, Viewport, VoiceCue } from "./types.ts";
8
+ import type { VoiceConfig } from "./voice.ts";
8
9
  import type { ZoomOptions } from "./zoom.ts";
9
10
  export interface ScenarioContext {
10
11
  /** URL of the scenario's `serve` directory ("" if none). */
@@ -38,6 +39,8 @@ export interface Scenario {
38
39
  clickRipple?: boolean | ClickRippleOptions;
39
40
  /** Cut (or speed up) idle stretches with OpenScreen trim/speed regions. */
40
41
  trimIdle?: boolean | Partial<IdleOptions>;
42
+ /** Voiceover TTS configuration for `scene.say()` (defaults to free Microsoft Edge TTS). */
43
+ voice?: VoiceConfig;
41
44
  run(scene: Scene, ctx: ScenarioContext): Promise<void>;
42
45
  }
43
46
  /** Identity helper that gives scenario files type checking and editor completion. */
@@ -82,6 +85,7 @@ export interface DryRunOptions {
82
85
  export interface DryRunResult {
83
86
  ok: boolean;
84
87
  actions: ActionRecord[];
88
+ voiceCues: VoiceCue[];
85
89
  durationMs: number;
86
90
  error?: DryRunError;
87
91
  }
package/dist/record.js CHANGED
@@ -21,7 +21,8 @@ export function resolveStorageState(statePath, baseDir = process.cwd()) {
21
21
  return resolved;
22
22
  }
23
23
  function mergeScenario(input, overrides) {
24
- const scenario = { ...input, ...overrides };
24
+ const voice = input.voice || overrides?.voice ? { ...input.voice, ...overrides?.voice } : undefined;
25
+ const scenario = { ...input, ...overrides, ...(voice ? { voice } : {}) };
25
26
  if (!scenario.name || typeof scenario.run !== "function") {
26
27
  throw new Error("a scenario needs a `name` and an async `run(scene, ctx)` (use defineScenario)");
27
28
  }
@@ -92,12 +93,19 @@ export async function recordScenario(input, opts = {}) {
92
93
  });
93
94
  await recorder.start();
94
95
  return recorder;
95
- }, { seed: session.scenario.seed, pacing: session.scenario.pacing, clickRipple: session.scenario.clickRipple });
96
+ }, {
97
+ seed: session.scenario.seed,
98
+ pacing: session.scenario.pacing,
99
+ clickRipple: session.scenario.clickRipple,
100
+ voice: session.scenario.voice,
101
+ voiceOutDir: path.join(outDir, "voice"),
102
+ });
96
103
  const tRun = Date.now();
97
104
  await session.scenario.run(scene, { baseUrl: session.baseUrl });
98
- // Hold the last frame so the final zoom-out and captions finish.
105
+ // Hold the last frame so the final zoom-out, captions, and voice cues finish.
99
106
  const lastCaptionEnd = Math.max(0, ...scene.captions.map((c) => c.endMs));
100
- await scene.pause(Math.max(900, lastCaptionEnd - scene.now() + 300));
107
+ const lastVoiceEnd = Math.max(0, ...scene.voiceCues.map((c) => c.endMs));
108
+ await scene.pause(Math.max(900, Math.max(lastCaptionEnd, lastVoiceEnd) - scene.now() + 300));
101
109
  timings.scenarioMs = Date.now() - tRun;
102
110
  }
103
111
  catch (e) {
@@ -128,6 +136,7 @@ export async function recordScenario(input, opts = {}) {
128
136
  frameSize: rec.frameSize,
129
137
  actions: scene.actions,
130
138
  captions: scene.captions,
139
+ voiceCues: scene.voiceCues,
131
140
  samples: scene.samples,
132
141
  frameTimes,
133
142
  timings,
@@ -135,6 +144,7 @@ export async function recordScenario(input, opts = {}) {
135
144
  look: session.scenario.look,
136
145
  trimIdle: session.scenario.trimIdle,
137
146
  cursor: session.scenario.cursor,
147
+ voice: session.scenario.voice,
138
148
  });
139
149
  const result = {
140
150
  videoPath,
@@ -144,6 +154,7 @@ export async function recordScenario(input, opts = {}) {
144
154
  samples: scene.samples,
145
155
  actions: scene.actions,
146
156
  captions: scene.captions,
157
+ ...(scene.voiceCues.length ? { voiceCues: scene.voiceCues } : {}),
147
158
  frameTimes,
148
159
  frameCount,
149
160
  timings,
@@ -165,13 +176,14 @@ export async function dryRunScenario(input, opts = {}) {
165
176
  const scene = new Scene(session.page, session.viewport, startClock, {
166
177
  seed: session.scenario.seed,
167
178
  pacing: session.scenario.pacing,
179
+ voice: session.scenario.voice,
168
180
  fast: true,
169
181
  });
170
182
  try {
171
183
  await session.scenario.run(scene, { baseUrl: session.baseUrl });
172
184
  const durationMs = Math.round(performance.now() - t0);
173
185
  await opts.atEnd?.(session.page);
174
- return { ok: true, actions: scene.actions, durationMs };
186
+ return { ok: true, actions: scene.actions, voiceCues: scene.voiceCues, durationMs };
175
187
  }
176
188
  catch (e) {
177
189
  const durationMs = Math.round(performance.now() - t0);
@@ -181,7 +193,7 @@ export async function dryRunScenario(input, opts = {}) {
181
193
  };
182
194
  await opts.onFailure?.(error, session.page);
183
195
  await opts.atEnd?.(session.page);
184
- return { ok: false, actions: scene.actions, durationMs, error };
196
+ return { ok: false, actions: scene.actions, voiceCues: scene.voiceCues, durationMs, error };
185
197
  }
186
198
  }
187
199
  finally {
package/dist/render.d.ts CHANGED
@@ -36,6 +36,8 @@ export interface RenderResult {
36
36
  renderMs: number;
37
37
  setupMs: number;
38
38
  totalMs: number;
39
+ audioMuxed?: boolean;
40
+ vttPath?: string;
39
41
  }
40
42
  /** Resolves the project's screen video (absolute, or relative to the project file). */
41
43
  export declare function projectVideoPath(project: {
package/dist/render.js CHANGED
@@ -9,6 +9,7 @@ import path from "node:path";
9
9
  import { DemoreelError, launchChromium, renderArgs } from "./env.js";
10
10
  import { openscreenProjectApi, rendererDir } from "./openscreen.js";
11
11
  import { sendFile, serveStatic } from "./server.js";
12
+ import { lintVoiceCues, muxVoiceTrack } from "./voice.js";
12
13
  function readProject(projectPath) {
13
14
  if (!fs.existsSync(projectPath))
14
15
  throw new DemoreelError(`project not found: ${projectPath}`);
@@ -97,17 +98,49 @@ export async function renderProject(opts) {
97
98
  quality: opts.quality,
98
99
  cursor: opts.cursor,
99
100
  });
101
+ const warnings = [...(result.warnings ?? [])];
102
+ let bytes = result.bytes;
103
+ let audioMuxed = false;
104
+ let vttPath;
105
+ // If timeline.json next to the project has voiceCues, mux them into the MP4 (stream-copying video).
106
+ const projectDir = path.dirname(projectPath);
107
+ const timelinePath = path.join(projectDir, "timeline.json");
108
+ if (fs.existsSync(timelinePath)) {
109
+ try {
110
+ const tl = JSON.parse(fs.readFileSync(timelinePath, "utf8"));
111
+ if (tl.voiceCues && tl.voiceCues.length > 0) {
112
+ const mux = await muxVoiceTrack(outputPath, tl.voiceCues, projectDir, {
113
+ trims: tl.trimRegions,
114
+ speeds: tl.speedRegions,
115
+ writeVtt: tl.options?.voice?.captions !== "off",
116
+ });
117
+ audioMuxed = mux.audioMuxed;
118
+ vttPath = mux.vttPath;
119
+ if (audioMuxed && fs.existsSync(outputPath)) {
120
+ bytes = fs.statSync(outputPath).size;
121
+ }
122
+ const voiceFindings = lintVoiceCues(tl.voiceCues, tl.outputDurationMs ?? 0, tl.trimRegions, tl.speedRegions);
123
+ for (const f of voiceFindings)
124
+ warnings.push(`[voice:${f.severity}] ${f.message}`);
125
+ }
126
+ }
127
+ catch (e) {
128
+ warnings.push(`voice mux skipped: ${e.message}`);
129
+ }
130
+ }
100
131
  return {
101
132
  outputPath,
102
133
  width: result.width,
103
134
  height: result.height,
104
135
  bitrate: result.bitrate,
105
- bytes: result.bytes,
106
- warnings: result.warnings ?? [],
136
+ bytes,
137
+ warnings,
107
138
  renderMs: result.renderMs,
108
139
  gpu: gl.gpu,
109
140
  setupMs: tReady - t0,
110
141
  totalMs: Date.now() - t0,
142
+ ...(audioMuxed ? { audioMuxed } : {}),
143
+ ...(vttPath ? { vttPath } : {}),
111
144
  };
112
145
  }
113
146
  catch (e) {