demowright 2.1.0 → 2.2.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.
@@ -10,6 +10,9 @@ interface TitleStep {
10
10
  kind: "title";
11
11
  text: string;
12
12
  subtitle?: string;
13
+ /** Optional TTS narration read aloud over the card. When set, card
14
+ * duration becomes max(durationMs, narration audio length). */
15
+ narration?: string;
13
16
  durationMs: number;
14
17
  background?: string;
15
18
  }
@@ -27,6 +30,9 @@ interface OutroStep {
27
30
  kind: "outro";
28
31
  text: string;
29
32
  subtitle?: string;
33
+ /** Optional TTS narration read aloud over the card. When set, card
34
+ * duration becomes max(durationMs, narration audio length). */
35
+ narration?: string;
30
36
  durationMs: number;
31
37
  background?: string;
32
38
  }
@@ -53,6 +59,8 @@ interface VideoScriptResult {
53
59
  }
54
60
  interface TitleOptions {
55
61
  subtitle?: string;
62
+ /** TTS narration read aloud over the card overlay. Duration auto-extends to fit. */
63
+ narration?: string;
56
64
  durationMs?: number;
57
65
  /** CSS background — default: radial gradient */
58
66
  background?: string;
@@ -60,6 +68,8 @@ interface TitleOptions {
60
68
  interface OutroOptions {
61
69
  text?: string;
62
70
  subtitle?: string;
71
+ /** TTS narration read aloud over the card overlay. Duration auto-extends to fit. */
72
+ narration?: string;
63
73
  durationMs?: number;
64
74
  background?: string;
65
75
  }
@@ -89,7 +99,7 @@ declare class VideoScriptImpl {
89
99
  private static ttsCache;
90
100
  /**
91
101
  * Add a title card — full-screen overlay with text + optional subtitle.
92
- * No TTS narration by default (silent title card).
102
+ * Pass `narration` in opts to have TTS voiceover during the card.
93
103
  */
94
104
  title(text: string, opts?: TitleOptions): this;
95
105
  /**
@@ -104,6 +114,7 @@ declare class VideoScriptImpl {
104
114
  transition(type?: TransitionType, durationMs?: number): this;
105
115
  /**
106
116
  * Add an outro card — full-screen overlay, similar to title.
117
+ * Pass `narration` in opts to have TTS voiceover during the card.
107
118
  */
108
119
  outro(opts?: OutroOptions): this;
109
120
  /**
@@ -267,13 +267,14 @@ var init_video_script = __esmMin((() => {
267
267
  static ttsCache = /* @__PURE__ */ new Map();
268
268
  /**
269
269
  * Add a title card — full-screen overlay with text + optional subtitle.
270
- * No TTS narration by default (silent title card).
270
+ * Pass `narration` in opts to have TTS voiceover during the card.
271
271
  */
272
272
  title(text, opts) {
273
273
  this.steps.push({
274
274
  kind: "title",
275
275
  text,
276
276
  subtitle: opts?.subtitle,
277
+ narration: opts?.narration,
277
278
  durationMs: opts?.durationMs ?? 4e3,
278
279
  background: opts?.background
279
280
  });
@@ -305,12 +306,14 @@ var init_video_script = __esmMin((() => {
305
306
  }
306
307
  /**
307
308
  * Add an outro card — full-screen overlay, similar to title.
309
+ * Pass `narration` in opts to have TTS voiceover during the card.
308
310
  */
309
311
  outro(opts) {
310
312
  this.steps.push({
311
313
  kind: "outro",
312
314
  text: opts?.text ?? "Thanks for watching!",
313
315
  subtitle: opts?.subtitle,
316
+ narration: opts?.narration,
314
317
  durationMs: opts?.durationMs ?? 4e3,
315
318
  background: opts?.background
316
319
  });
@@ -326,11 +329,20 @@ var init_video_script = __esmMin((() => {
326
329
  else if (typeof pageOrProvider === "function" || typeof pageOrProvider === "string") provider = pageOrProvider;
327
330
  else provider = getTtsProvider(pageOrProvider);
328
331
  if (!provider) return;
329
- const segmentSteps = this.steps.filter((s) => s.kind === "segment").map((s, i) => ({
330
- ...s,
331
- id: `step-${i}`
332
- }));
333
- const results = await Promise.allSettled(segmentSteps.map(async (step) => {
332
+ const ttsSteps = [];
333
+ let segIdx2 = 0;
334
+ for (let i = 0; i < this.steps.length; i++) {
335
+ const s = this.steps[i];
336
+ if (s.kind === "segment") ttsSteps.push({
337
+ id: `step-${segIdx2++}`,
338
+ text: s.text
339
+ });
340
+ else if ((s.kind === "title" || s.kind === "outro") && s.narration) ttsSteps.push({
341
+ id: `card-${i}`,
342
+ text: s.narration
343
+ });
344
+ }
345
+ const results = await Promise.allSettled(ttsSteps.map(async (step) => {
334
346
  const cached = VideoScriptImpl.ttsCache.get(step.text);
335
347
  if (cached) return {
336
348
  id: step.id,
@@ -352,7 +364,7 @@ var init_video_script = __esmMin((() => {
352
364
  durationMs: r.value.durationMs
353
365
  };
354
366
  this.prepared.set(r.value.id, seg);
355
- const step = segmentSteps[idx];
367
+ const step = ttsSteps[idx];
356
368
  if (step) VideoScriptImpl.ttsCache.set(step.text, seg);
357
369
  }
358
370
  idx++;
@@ -450,14 +462,28 @@ var init_video_script = __esmMin((() => {
450
462
  const stepStartMs = Date.now();
451
463
  if (step.kind === "title" || step.kind === "outro") {
452
464
  const bg = step.background ?? DEFAULT_BG;
453
- if (active) showCard(page, step.text, step.subtitle, step.durationMs, bg).catch(() => {});
454
- await page.waitForTimeout(step.durationMs);
465
+ const cardTts = step.narration ? this.prepared.get(`card-${i}`) : void 0;
466
+ const effectiveDuration = cardTts ? Math.max(step.durationMs, cardTts.durationMs + 500) : step.durationMs;
467
+ if (active) showCard(page, step.text, step.subtitle, effectiveDuration, bg).catch(() => {});
468
+ if (active && cardTts) {
469
+ const offsetMs = Date.now() - planStartMs;
470
+ audioSegments.push({
471
+ offsetMs,
472
+ wavBuf: cardTts.wavBuf
473
+ });
474
+ storeAudioSegment(page, {
475
+ timestampMs: Date.now(),
476
+ wavBuf: cardTts.wavBuf
477
+ });
478
+ showCaption(page, step.narration, cardTts.durationMs).catch(() => {});
479
+ }
480
+ await page.waitForTimeout(effectiveDuration);
455
481
  timeline.push({
456
482
  id: stepIds[i],
457
483
  kind: step.kind,
458
- text: step.text,
484
+ text: step.narration ?? step.text,
459
485
  startMs: stepStartMs - planStartMs,
460
- durationMs: step.durationMs,
486
+ durationMs: effectiveDuration,
461
487
  actionMs: 0,
462
488
  overrunMs: 0
463
489
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "demowright",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Playwright video production plugin — cursor overlay, keystroke badges, TTS narration, and narration-driven video scripts for test recordings",
5
5
  "license": "MIT",
6
6
  "repository": {