@softure-ai/marketing-kit 0.1.12 → 0.3.1

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 (118) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +109 -4
  3. package/dist/cli/footage.d.ts +6 -0
  4. package/dist/cli/footage.d.ts.map +1 -0
  5. package/dist/cli/footage.js +95 -0
  6. package/dist/cli/footage.js.map +1 -0
  7. package/dist/cli/main.js +21 -5
  8. package/dist/cli/main.js.map +1 -1
  9. package/dist/cli/options.d.ts +18 -3
  10. package/dist/cli/options.d.ts.map +1 -1
  11. package/dist/cli/options.js +41 -2
  12. package/dist/cli/options.js.map +1 -1
  13. package/dist/compose/compose.d.ts.map +1 -1
  14. package/dist/compose/compose.js +1 -22
  15. package/dist/compose/compose.js.map +1 -1
  16. package/dist/compose/html.d.ts +6 -0
  17. package/dist/compose/html.d.ts.map +1 -0
  18. package/dist/compose/html.js +24 -0
  19. package/dist/compose/html.js.map +1 -0
  20. package/dist/config/actions-schema.d.ts +14 -14
  21. package/dist/config/config.d.ts +19 -3
  22. package/dist/config/config.d.ts.map +1 -1
  23. package/dist/config/config.js +90 -2
  24. package/dist/config/config.js.map +1 -1
  25. package/dist/config/schema.d.ts +152 -70
  26. package/dist/config/schema.d.ts.map +1 -1
  27. package/dist/config/schema.js +140 -10
  28. package/dist/config/schema.js.map +1 -1
  29. package/dist/config/shot-steps.d.ts +16 -16
  30. package/dist/footage/cache.d.ts +23 -0
  31. package/dist/footage/cache.d.ts.map +1 -0
  32. package/dist/footage/cache.js +51 -0
  33. package/dist/footage/cache.js.map +1 -0
  34. package/dist/footage/compose.d.ts +50 -0
  35. package/dist/footage/compose.d.ts.map +1 -0
  36. package/dist/footage/compose.js +166 -0
  37. package/dist/footage/compose.js.map +1 -0
  38. package/dist/footage/edl.d.ts +83 -0
  39. package/dist/footage/edl.d.ts.map +1 -0
  40. package/dist/footage/edl.js +166 -0
  41. package/dist/footage/edl.js.map +1 -0
  42. package/dist/footage/elevenlabs.d.ts +31 -0
  43. package/dist/footage/elevenlabs.d.ts.map +1 -0
  44. package/dist/footage/elevenlabs.js +140 -0
  45. package/dist/footage/elevenlabs.js.map +1 -0
  46. package/dist/footage/fake.d.ts +38 -0
  47. package/dist/footage/fake.d.ts.map +1 -0
  48. package/dist/footage/fake.js +66 -0
  49. package/dist/footage/fake.js.map +1 -0
  50. package/dist/footage/film.d.ts +103 -0
  51. package/dist/footage/film.d.ts.map +1 -0
  52. package/dist/footage/film.js +29 -0
  53. package/dist/footage/film.js.map +1 -0
  54. package/dist/footage/music.d.ts +37 -0
  55. package/dist/footage/music.d.ts.map +1 -0
  56. package/dist/footage/music.js +63 -0
  57. package/dist/footage/music.js.map +1 -0
  58. package/dist/footage/normalize.d.ts +41 -0
  59. package/dist/footage/normalize.d.ts.map +1 -0
  60. package/dist/footage/normalize.js +114 -0
  61. package/dist/footage/normalize.js.map +1 -0
  62. package/dist/footage/pipeline.d.ts +105 -0
  63. package/dist/footage/pipeline.d.ts.map +1 -0
  64. package/dist/footage/pipeline.js +385 -0
  65. package/dist/footage/pipeline.js.map +1 -0
  66. package/dist/footage/probe.d.ts +64 -0
  67. package/dist/footage/probe.d.ts.map +1 -0
  68. package/dist/footage/probe.js +138 -0
  69. package/dist/footage/probe.js.map +1 -0
  70. package/dist/footage/providers.d.ts +61 -0
  71. package/dist/footage/providers.d.ts.map +1 -0
  72. package/dist/footage/providers.js +13 -0
  73. package/dist/footage/providers.js.map +1 -0
  74. package/dist/footage/render.d.ts +20 -0
  75. package/dist/footage/render.d.ts.map +1 -0
  76. package/dist/footage/render.js +76 -0
  77. package/dist/footage/render.js.map +1 -0
  78. package/dist/index.d.ts +14 -2
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +16 -3
  81. package/dist/index.js.map +1 -1
  82. package/dist/messages/index.d.ts +10 -22
  83. package/dist/messages/index.d.ts.map +1 -1
  84. package/dist/messages/index.js +8 -6
  85. package/dist/messages/index.js.map +1 -1
  86. package/dist/render/render.d.ts +6 -0
  87. package/dist/render/render.d.ts.map +1 -1
  88. package/dist/render/render.js +1 -1
  89. package/dist/render/render.js.map +1 -1
  90. package/package.json +1 -1
  91. package/schema/marketing.schema.json +339 -3
  92. package/src/cli/footage.ts +87 -0
  93. package/src/cli/main.ts +20 -5
  94. package/src/cli/options.ts +51 -4
  95. package/src/compose/compose.ts +1 -25
  96. package/src/compose/html.ts +28 -0
  97. package/src/config/config.ts +101 -5
  98. package/src/config/schema.ts +146 -12
  99. package/src/footage/cache.ts +66 -0
  100. package/src/footage/compose.ts +213 -0
  101. package/src/footage/edl.ts +204 -0
  102. package/src/footage/elevenlabs.ts +154 -0
  103. package/src/footage/fake.ts +92 -0
  104. package/src/footage/film.ts +111 -0
  105. package/src/footage/music.ts +86 -0
  106. package/src/footage/normalize.ts +133 -0
  107. package/src/footage/pipeline.ts +447 -0
  108. package/src/footage/probe.ts +172 -0
  109. package/src/footage/providers.ts +71 -0
  110. package/src/footage/render.ts +82 -0
  111. package/src/index.ts +110 -3
  112. package/src/messages/index.ts +16 -8
  113. package/src/render/render.ts +1 -1
  114. package/dist/messages/pl.d.ts +0 -3
  115. package/dist/messages/pl.d.ts.map +0 -1
  116. package/dist/messages/pl.js +0 -21
  117. package/dist/messages/pl.js.map +0 -1
  118. package/src/messages/pl.ts +0 -22
@@ -0,0 +1,83 @@
1
+ import { z } from "zod";
2
+ import type { TimedWord } from "../voice/voiceover.js";
3
+ import { type ClipRole, type CutOptions, type CutTransition, type FootageTransitions } from "./film.js";
4
+ /**
5
+ * The edit decision list: which parts of which clips the film keeps, in order, and how each part starts. Built from
6
+ * the transcript (`buildEdl`), written as plain JSON next to the build so a person or an agent can check or change it
7
+ * before the render, and read back through `edlSchema`.
8
+ */
9
+ export declare const SEGMENT_MOTIONS: readonly ["none", "kenburns"];
10
+ export type SegmentMotion = (typeof SEGMENT_MOTIONS)[number];
11
+ export interface EdlSegment {
12
+ /** The clip's id. */
13
+ clip: string;
14
+ /** Seconds in the trimmed clip. */
15
+ start: number;
16
+ end: number;
17
+ transition: CutTransition;
18
+ /** `kenburns`: a slow zoom over a segment without speech. */
19
+ motion: SegmentMotion;
20
+ }
21
+ export interface Edl {
22
+ version: 1;
23
+ film: string;
24
+ segments: EdlSegment[];
25
+ }
26
+ export declare const edlSchema: z.ZodObject<{
27
+ version: z.ZodLiteral<1>;
28
+ film: z.ZodString;
29
+ segments: z.ZodArray<z.ZodObject<{
30
+ clip: z.ZodString;
31
+ start: z.ZodNumber;
32
+ end: z.ZodNumber;
33
+ transition: z.ZodEnum<{
34
+ fade: "fade";
35
+ cut: "cut";
36
+ zoom: "zoom";
37
+ whoosh: "whoosh";
38
+ }>;
39
+ motion: z.ZodEnum<{
40
+ none: "none";
41
+ kenburns: "kenburns";
42
+ }>;
43
+ }, z.core.$strict>>;
44
+ }, z.core.$strict>;
45
+ /** A clip as the cut sees it: its role, its trimmed length and its transcript (times from the trimmed start). */
46
+ export interface EdlClip {
47
+ id: string;
48
+ role: ClipRole;
49
+ duration: number;
50
+ words: TimedWord[];
51
+ }
52
+ /** Shortest segment kept, in seconds: anything shorter reads as a glitch. */
53
+ export declare const MIN_SEGMENT_SECONDS = 0.25;
54
+ /** A word reduced for comparison: lower case, letters and digits only, repeated letters collapsed (`Yyyy,` → `y`). */
55
+ export declare function normalizeWord(text: string): string;
56
+ /** Whether the word is one of the fillers (compared as `normalizeWord` writes both). */
57
+ export declare function isFiller(text: string, fillers: readonly string[]): boolean;
58
+ /**
59
+ * The cut from the transcripts. A talking clip keeps its runs of words: fillers are cut out, a pause longer than
60
+ * `pauseSeconds` is cut, `padSeconds` stays around each cut. A talking clip without words, and every b-roll clip, is
61
+ * kept whole (b-roll with a slow zoom). The first segment starts with a cut; later ones with `transitions.jump`
62
+ * inside one clip and `transitions.clip` between clips.
63
+ */
64
+ export declare function buildEdl(filmId: string, clips: EdlClip[], options: CutOptions, transitions: FootageTransitions): Edl;
65
+ /** What makes an EDL (a hand-edited one above all) unusable with these clips; empty when it is fine. */
66
+ export declare function findEdlProblems(edl: Edl, clips: Pick<EdlClip, "id" | "duration">[], filmId: string): string[];
67
+ /** Reads an EDL file's JSON; an error names the first problems by path. */
68
+ export declare function readEdl(json: unknown): {
69
+ ok: true;
70
+ edl: Edl;
71
+ } | {
72
+ ok: false;
73
+ error: string;
74
+ };
75
+ export declare function getEdlDuration(edl: Edl): number;
76
+ /** Where each segment starts in the film, in seconds. */
77
+ export declare function getSegmentStarts(edl: Edl): number[];
78
+ /**
79
+ * The words the film says, in film time: each clip's words that fall in a kept segment (by their middle), shifted by
80
+ * where the segment lands; fillers left out. Every cut shifts every later word.
81
+ */
82
+ export declare function remapWords(edl: Edl, words: Record<string, TimedWord[]>, fillers: readonly string[]): TimedWord[];
83
+ //# sourceMappingURL=edl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edl.d.ts","sourceRoot":"","sources":["../../src/footage/edl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAmB,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEzH;;;;GAIG;AAEH,eAAO,MAAM,eAAe,+BAAgC,CAAC;AAE7D,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7D,MAAM,WAAW,UAAU;IACzB,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,aAAa,CAAC;IAC1B,6DAA6D;IAC7D,MAAM,EAAE,aAAa,CAAC;CACvB;AAED,MAAM,WAAW,GAAG;IAClB,OAAO,E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GAAG,GAAG,MAAM,EAAE,CAQnD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAAE,CAYhH"}
@@ -0,0 +1,166 @@
1
+ import { z } from "zod";
2
+ import { CUT_TRANSITIONS } from "./film.js";
3
+ /**
4
+ * The edit decision list: which parts of which clips the film keeps, in order, and how each part starts. Built from
5
+ * the transcript (`buildEdl`), written as plain JSON next to the build so a person or an agent can check or change it
6
+ * before the render, and read back through `edlSchema`.
7
+ */
8
+ export const SEGMENT_MOTIONS = ["none", "kenburns"];
9
+ export const edlSchema = z.strictObject({
10
+ version: z.literal(1),
11
+ film: z.string().min(1),
12
+ segments: z
13
+ .array(z.strictObject({
14
+ clip: z.string().min(1),
15
+ start: z.number().min(0),
16
+ end: z.number().positive(),
17
+ transition: z.enum(CUT_TRANSITIONS),
18
+ motion: z.enum(SEGMENT_MOTIONS),
19
+ }))
20
+ .min(1, "the cut needs at least one segment"),
21
+ });
22
+ /** Shortest segment kept, in seconds: anything shorter reads as a glitch. */
23
+ export const MIN_SEGMENT_SECONDS = 0.25;
24
+ const r3 = (value) => Math.round(value * 1000) / 1000 || 0;
25
+ /** A word reduced for comparison: lower case, letters and digits only, repeated letters collapsed (`Yyyy,` → `y`). */
26
+ export function normalizeWord(text) {
27
+ return text
28
+ .toLowerCase()
29
+ .replace(/[^\p{L}\p{N}]/gu, "")
30
+ .replace(/(.)\1+/gu, "$1");
31
+ }
32
+ /** Whether the word is one of the fillers (compared as `normalizeWord` writes both). */
33
+ export function isFiller(text, fillers) {
34
+ const word = normalizeWord(text);
35
+ return word.length > 0 && fillers.some((filler) => normalizeWord(filler) === word);
36
+ }
37
+ /** The kept spans of a talking clip: runs of spoken words split at fillers and long pauses, padded, never into a neighbour word. */
38
+ function getTalkSpans(clip, options) {
39
+ const runs = [];
40
+ let run = [];
41
+ const words = [...clip.words].sort((a, b) => a.start - b.start);
42
+ words.forEach((word, index) => {
43
+ const previous = words[index - 1];
44
+ if (isFiller(word.text, options.fillers)) {
45
+ if (run.length > 0)
46
+ runs.push(run);
47
+ run = [];
48
+ return;
49
+ }
50
+ if (run.length > 0 && previous !== undefined && word.start - previous.end > options.pauseSeconds) {
51
+ runs.push(run);
52
+ run = [];
53
+ }
54
+ run.push(word);
55
+ });
56
+ if (run.length > 0)
57
+ runs.push(run);
58
+ const spans = [];
59
+ for (const kept of runs) {
60
+ const first = kept[0];
61
+ const last = kept[kept.length - 1];
62
+ const before = words[words.indexOf(first) - 1];
63
+ const after = words[words.indexOf(last) + 1];
64
+ const start = Math.max(0, first.start - options.padSeconds, before?.end ?? 0);
65
+ const end = Math.min(clip.duration, last.end + options.padSeconds, after?.start ?? clip.duration);
66
+ const previous = spans.at(-1);
67
+ if (previous !== undefined && start <= previous.end + 0.01)
68
+ previous.end = Math.max(previous.end, end);
69
+ else
70
+ spans.push({ start, end });
71
+ }
72
+ return spans.filter((span) => span.end - span.start >= MIN_SEGMENT_SECONDS);
73
+ }
74
+ /** Cuts the segments to `maxSeconds`: the last one that crosses it is shortened, later ones dropped. */
75
+ function limitLength(segments, maxSeconds) {
76
+ if (maxSeconds === null)
77
+ return segments;
78
+ const kept = [];
79
+ let total = 0;
80
+ for (const segment of segments) {
81
+ const left = maxSeconds - total;
82
+ if (left < MIN_SEGMENT_SECONDS)
83
+ break;
84
+ const length = segment.end - segment.start;
85
+ kept.push(length <= left ? segment : { ...segment, end: r3(segment.start + left) });
86
+ total += Math.min(length, left);
87
+ }
88
+ return kept;
89
+ }
90
+ /**
91
+ * The cut from the transcripts. A talking clip keeps its runs of words: fillers are cut out, a pause longer than
92
+ * `pauseSeconds` is cut, `padSeconds` stays around each cut. A talking clip without words, and every b-roll clip, is
93
+ * kept whole (b-roll with a slow zoom). The first segment starts with a cut; later ones with `transitions.jump`
94
+ * inside one clip and `transitions.clip` between clips.
95
+ */
96
+ export function buildEdl(filmId, clips, options, transitions) {
97
+ const segments = [];
98
+ for (const clip of clips) {
99
+ const spans = clip.role === "talk" ? getTalkSpans(clip, options) : [];
100
+ const kept = spans.length > 0 ? spans : [{ start: 0, end: clip.duration }];
101
+ for (const span of kept) {
102
+ const previous = segments.at(-1);
103
+ const transition = previous === undefined ? "cut" : previous.clip === clip.id ? transitions.jump : transitions.clip;
104
+ segments.push({ clip: clip.id, start: r3(span.start), end: r3(span.end), transition, motion: clip.role === "broll" ? "kenburns" : "none" });
105
+ }
106
+ }
107
+ return { version: 1, film: filmId, segments: limitLength(segments, options.maxSeconds) };
108
+ }
109
+ /** What makes an EDL (a hand-edited one above all) unusable with these clips; empty when it is fine. */
110
+ export function findEdlProblems(edl, clips, filmId) {
111
+ const problems = [];
112
+ if (edl.film !== filmId)
113
+ problems.push(`it belongs to film "${edl.film}", not "${filmId}"`);
114
+ const durations = new Map(clips.map((clip) => [clip.id, clip.duration]));
115
+ edl.segments.forEach((segment, index) => {
116
+ const duration = durations.get(segment.clip);
117
+ const at = `segments[${index}]`;
118
+ if (duration === undefined)
119
+ problems.push(`${at}.clip: no clip "${segment.clip}" in the film`);
120
+ else if (segment.end > duration + 0.05)
121
+ problems.push(`${at}.end: ${segment.end} s is past the clip's end (${duration.toFixed(2)} s)`);
122
+ if (segment.end - segment.start < MIN_SEGMENT_SECONDS)
123
+ problems.push(`${at}: shorter than ${MIN_SEGMENT_SECONDS} s (start ${segment.start}, end ${segment.end})`);
124
+ });
125
+ return problems;
126
+ }
127
+ /** Reads an EDL file's JSON; an error names the first problems by path. */
128
+ export function readEdl(json) {
129
+ const parsed = edlSchema.safeParse(json);
130
+ if (parsed.success)
131
+ return { ok: true, edl: parsed.data };
132
+ const issues = parsed.error.issues.slice(0, 5).map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`);
133
+ return { ok: false, error: issues.join("; ") };
134
+ }
135
+ export function getEdlDuration(edl) {
136
+ return r3(edl.segments.reduce((sum, segment) => sum + (segment.end - segment.start), 0));
137
+ }
138
+ /** Where each segment starts in the film, in seconds. */
139
+ export function getSegmentStarts(edl) {
140
+ const starts = [];
141
+ let time = 0;
142
+ for (const segment of edl.segments) {
143
+ starts.push(r3(time));
144
+ time += segment.end - segment.start;
145
+ }
146
+ return starts;
147
+ }
148
+ /**
149
+ * The words the film says, in film time: each clip's words that fall in a kept segment (by their middle), shifted by
150
+ * where the segment lands; fillers left out. Every cut shifts every later word.
151
+ */
152
+ export function remapWords(edl, words, fillers) {
153
+ const starts = getSegmentStarts(edl);
154
+ const film = [];
155
+ edl.segments.forEach((segment, index) => {
156
+ const offset = starts[index] - segment.start;
157
+ for (const word of words[segment.clip] ?? []) {
158
+ const middle = (word.start + word.end) / 2;
159
+ if (middle < segment.start || middle >= segment.end || isFiller(word.text, fillers))
160
+ continue;
161
+ film.push({ text: word.text, start: r3(Math.max(word.start, segment.start) + offset), end: r3(Math.min(word.end, segment.end) + offset) });
162
+ }
163
+ });
164
+ return film;
165
+ }
166
+ //# sourceMappingURL=edl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edl.js","sourceRoot":"","sources":["../../src/footage/edl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,eAAe,EAA+E,MAAM,WAAW,CAAC;AAEzH;;;;GAIG;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAM,EAAE,UAAU,CAAU,CAAC;AAqB7D,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,YAAY,CAAC;IACtC,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACrB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,QAAQ,EAAE,CAAC;SACR,KAAK,CACJ,CAAC,CAAC,YAAY,CAAC;QACb,IAAI,EAAE,CAAC,CAAC,MA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EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;QAC7I,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { type TtsResult } from "../voice/provider.js";
2
+ import type { IsolationProvider, MusicProvider, SttProvider, SttTranscript } from "./providers.js";
3
+ /**
4
+ * ElevenLabs behind the footage providers (API reference checked 2026-10-29): Scribe speech to text
5
+ * (`/v1/speech-to-text`, word timestamps), Voice Isolator (`/v1/audio-isolation`), Music (`/v1/music`) and Video to
6
+ * Music (`/v1/music/video-to-music`). Each takes an injected `fetch`, so tests reach no network.
7
+ */
8
+ export declare const ELEVENLABS_STT_MODEL = "scribe_v2";
9
+ export declare const ELEVENLABS_MUSIC_MODEL = "music_v1";
10
+ export interface ElevenLabsFootageOptions {
11
+ /** The API key; a missing one fails the call, never the estimate. */
12
+ apiKey: string | undefined;
13
+ fetch?: typeof globalThis.fetch;
14
+ /** Scribe's model; `scribe_v2` by default. */
15
+ sttModel?: string;
16
+ musicModel?: string;
17
+ }
18
+ /** Scribe's response read as timed words: entries of type `word` only (no spacing, no sound events). */
19
+ export declare function readScribeResponse(body: unknown, language: string): TtsResult<SttTranscript>;
20
+ export declare function createElevenLabsSttProvider(options: ElevenLabsFootageOptions): SttProvider;
21
+ export declare function createElevenLabsIsolationProvider(options: ElevenLabsFootageOptions): IsolationProvider;
22
+ /** The length ElevenLabs Music is asked for: the film's, within the service's 3 s to 10 min. */
23
+ export declare function getMusicLengthMs(seconds: number): number;
24
+ export declare function createElevenLabsMusicProvider(options: ElevenLabsFootageOptions): MusicProvider;
25
+ /** The ElevenLabs footage providers with the key from the environment (read, never logged). */
26
+ export declare function createElevenLabsFootageProviders(env: Record<string, string | undefined>, fetch?: typeof globalThis.fetch): {
27
+ stt: SttProvider;
28
+ isolation: IsolationProvider;
29
+ music: MusicProvider;
30
+ };
31
+ //# sourceMappingURL=elevenlabs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elevenlabs.d.ts","sourceRoot":"","sources":["../../src/footage/elevenlabs.ts"],"names":[],"mappings":"AAMA,OAAO,EAAW,KAAK,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEnG;;;;GAIG;AAEH,eAAO,MAAM,oBAAoB,cAAc,CAAC;AAChD,eAAO,MAAM,sBAAsB,aAAa,CAAC;AAMjD,MAAM,WAAW,wBAAwB;IACvC,qEAAqE;IACrE,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AASD,wGAAwG;AACxG,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC,aAAa,CAAC,CAW5F;AA+BD,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,wBAAwB,GAAG,WAAW,CAuB1F;AAED,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,wBAAwB,GAAG,iBAAiB,CAUtG;AAED,gGAAgG;AAChG,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa,CAuB9F;AAED,+FAA+F;AAC/F,wBAAgB,gCAAgC,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK;;;;EAGxH"}
@@ -0,0 +1,140 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { basename } from "node:path";
3
+ import { z } from "zod";
4
+ import { ELEVENLABS_API_KEY_ENV } from "../voice/elevenlabs.js";
5
+ import { err, ok } from "../voice/provider.js";
6
+ import { ELEVENLABS_API_URL } from "../voice/voiceover.js";
7
+ /**
8
+ * ElevenLabs behind the footage providers (API reference checked 2026-10-29): Scribe speech to text
9
+ * (`/v1/speech-to-text`, word timestamps), Voice Isolator (`/v1/audio-isolation`), Music (`/v1/music`) and Video to
10
+ * Music (`/v1/music/video-to-music`). Each takes an injected `fetch`, so tests reach no network.
11
+ */
12
+ export const ELEVENLABS_STT_MODEL = "scribe_v2";
13
+ export const ELEVENLABS_MUSIC_MODEL = "music_v1";
14
+ const ERROR_DETAIL_LENGTH = 300;
15
+ /** ElevenLabs Music takes 3 s to 10 min. */
16
+ const MUSIC_MIN_MS = 3000;
17
+ const MUSIC_MAX_MS = 600_000;
18
+ const scribeSchema = z.looseObject({
19
+ language_code: z.string().optional(),
20
+ words: z.array(z.looseObject({ text: z.string(), start: z.number().nullish(), end: z.number().nullish(), type: z.string().optional() })),
21
+ });
22
+ const round = (value) => Math.round(value * 1000) / 1000 || 0;
23
+ /** Scribe's response read as timed words: entries of type `word` only (no spacing, no sound events). */
24
+ export function readScribeResponse(body, language) {
25
+ const parsed = scribeSchema.safeParse(body);
26
+ if (!parsed.success)
27
+ return err("ElevenLabs speech to text: the response has no words list.");
28
+ const words = [];
29
+ for (const word of parsed.data.words) {
30
+ if ((word.type ?? "word") !== "word")
31
+ continue;
32
+ const text = word.text.trim();
33
+ if (text.length === 0 || word.start == null || word.end == null)
34
+ continue;
35
+ words.push({ text, start: round(word.start), end: round(word.end) });
36
+ }
37
+ return ok({ words, language: parsed.data.language_code ?? language });
38
+ }
39
+ function fileBlob(path) {
40
+ return new Blob([readFileSync(path)]);
41
+ }
42
+ async function send(options, label, path, init) {
43
+ if (options.apiKey === undefined || options.apiKey.length === 0)
44
+ return err(`no ${ELEVENLABS_API_KEY_ENV} in the environment.`);
45
+ const request = options.fetch ?? globalThis.fetch;
46
+ let response;
47
+ try {
48
+ response = await request(`${ELEVENLABS_API_URL}${path}`, { ...init, headers: { ...init.headers, "xi-api-key": options.apiKey } });
49
+ }
50
+ catch (error) {
51
+ return err(`ElevenLabs ${label}: the connection failed (${String(error)}).`);
52
+ }
53
+ if (!response.ok) {
54
+ const detail = await response.text().catch((error) => `(unreadable body: ${String(error)})`);
55
+ return err(`ElevenLabs ${label} answered ${response.status}: ${detail.slice(0, ERROR_DETAIL_LENGTH)}`);
56
+ }
57
+ return ok(response);
58
+ }
59
+ async function readAudio(label, response) {
60
+ try {
61
+ const audio = Buffer.from(await response.arrayBuffer());
62
+ return audio.length > 0 ? ok(audio) : err(`ElevenLabs ${label}: the response has no audio.`);
63
+ }
64
+ catch (error) {
65
+ return err(`ElevenLabs ${label}: reading the audio failed (${String(error)}).`);
66
+ }
67
+ }
68
+ export function createElevenLabsSttProvider(options) {
69
+ const model = options.sttModel ?? ELEVENLABS_STT_MODEL;
70
+ return {
71
+ id: "elevenlabs",
72
+ model,
73
+ async transcribe(input) {
74
+ const form = new FormData();
75
+ form.append("model_id", model);
76
+ form.append("file", fileBlob(input.audio), basename(input.audio));
77
+ form.append("language_code", input.language);
78
+ form.append("timestamps_granularity", "word");
79
+ form.append("tag_audio_events", "false");
80
+ const response = await send(options, "speech to text", "/v1/speech-to-text", { method: "POST", body: form });
81
+ if (!response.ok)
82
+ return response;
83
+ let body;
84
+ try {
85
+ body = (await response.value.json());
86
+ }
87
+ catch (error) {
88
+ return err(`ElevenLabs speech to text: the response is not JSON (${String(error)}).`);
89
+ }
90
+ return readScribeResponse(body, input.language);
91
+ },
92
+ };
93
+ }
94
+ export function createElevenLabsIsolationProvider(options) {
95
+ return {
96
+ id: "elevenlabs",
97
+ async isolate(input) {
98
+ const form = new FormData();
99
+ form.append("audio", fileBlob(input.audio), basename(input.audio));
100
+ const response = await send(options, "voice isolation", "/v1/audio-isolation", { method: "POST", body: form });
101
+ return response.ok ? readAudio("voice isolation", response.value) : response;
102
+ },
103
+ };
104
+ }
105
+ /** The length ElevenLabs Music is asked for: the film's, within the service's 3 s to 10 min. */
106
+ export function getMusicLengthMs(seconds) {
107
+ return Math.min(MUSIC_MAX_MS, Math.max(MUSIC_MIN_MS, Math.ceil(seconds * 1000)));
108
+ }
109
+ export function createElevenLabsMusicProvider(options) {
110
+ const model = options.musicModel ?? ELEVENLABS_MUSIC_MODEL;
111
+ return {
112
+ id: "elevenlabs",
113
+ model,
114
+ async compose(input) {
115
+ const body = { prompt: input.prompt, music_length_ms: getMusicLengthMs(input.seconds), model_id: model, force_instrumental: true };
116
+ const response = await send(options, "music", "/v1/music?output_format=mp3_44100_128", {
117
+ method: "POST",
118
+ headers: { "Content-Type": "application/json" },
119
+ body: JSON.stringify(body),
120
+ });
121
+ return response.ok ? readAudio("music", response.value) : response;
122
+ },
123
+ async scoreVideo(input) {
124
+ const form = new FormData();
125
+ form.append("videos", fileBlob(input.video), basename(input.video));
126
+ if (input.description.length > 0)
127
+ form.append("description", input.description);
128
+ for (const tag of input.tags)
129
+ form.append("tags", tag);
130
+ const response = await send(options, "video to music", "/v1/music/video-to-music?output_format=mp3_44100_128", { method: "POST", body: form });
131
+ return response.ok ? readAudio("video to music", response.value) : response;
132
+ },
133
+ };
134
+ }
135
+ /** The ElevenLabs footage providers with the key from the environment (read, never logged). */
136
+ export function createElevenLabsFootageProviders(env, fetch) {
137
+ const options = { apiKey: env[ELEVENLABS_API_KEY_ENV], ...(fetch === undefined ? {} : { fetch }) };
138
+ return { stt: createElevenLabsSttProvider(options), isolation: createElevenLabsIsolationProvider(options), music: createElevenLabsMusicProvider(options) };
139
+ }
140
+ //# sourceMappingURL=elevenlabs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elevenlabs.js","sourceRoot":"","sources":["../../src/footage/elevenlabs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,C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C,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IAC7H,OAAO,EAAE,GAAG,EAAE,2BAA2B,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,iCAAiC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,6BAA6B,CAAC,OAAO,CAAC,EAAE,CAAC;AAC7J,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { TimedWord } from "../voice/voiceover.js";
2
+ import type { IsolationProvider, MusicProvider, SttInput, SttProvider } from "./providers.js";
3
+ /** Providers that spend nothing and reach no network, for tests of the footage pipeline and of a project's own flows. */
4
+ export interface FakeSttOptions {
5
+ /** Words per audio file, by the file's name up to its first dot (the pipeline names a clip's audio `<clip id>.*`). */
6
+ transcripts?: Record<string, TimedWord[]>;
7
+ /** Makes every call fail with this message. */
8
+ failWith?: string;
9
+ }
10
+ export interface FakeSttProvider extends SttProvider {
11
+ readonly calls: SttInput[];
12
+ }
13
+ export declare function createFakeSttProvider(options?: FakeSttOptions): FakeSttProvider;
14
+ export interface FakeIsolationProvider extends IsolationProvider {
15
+ readonly calls: string[];
16
+ }
17
+ /** Returns the input file's bytes unchanged: a valid audio file, so a pipeline with it still renders. */
18
+ export declare function createFakeIsolationProvider(): FakeIsolationProvider;
19
+ export interface FakeMusicProvider extends MusicProvider {
20
+ readonly calls: ({
21
+ kind: "compose";
22
+ prompt: string;
23
+ seconds: number;
24
+ } | {
25
+ kind: "video";
26
+ video: string;
27
+ description: string;
28
+ tags: string[];
29
+ })[];
30
+ }
31
+ /** Returns `audio` (by default a few bytes that are not audio: enough for tests that never decode it). */
32
+ export declare function createFakeMusicProvider(audio?: Buffer): FakeMusicProvider;
33
+ /**
34
+ * The free stand-in transcript of `--placeholder`: the script's words spread evenly over the clip, each lasting 80 %
35
+ * of its slot. No script, no words: the clip is kept whole.
36
+ */
37
+ export declare function makePlaceholderTranscript(script: string | null, duration: number): TimedWord[];
38
+ //# sourceMappingURL=fake.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AM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,CAS9F"}
@@ -0,0 +1,66 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { basename } from "node:path";
3
+ import { ok } from "../voice/provider.js";
4
+ export function createFakeSttProvider(options = {}) {
5
+ const calls = [];
6
+ return {
7
+ id: "fake",
8
+ model: "fake-stt",
9
+ calls,
10
+ transcribe(input) {
11
+ calls.push(input);
12
+ if (options.failWith !== undefined)
13
+ return Promise.resolve({ ok: false, error: options.failWith });
14
+ const name = basename(input.audio).split(".")[0] ?? "";
15
+ return Promise.resolve(ok({ words: options.transcripts?.[name] ?? [], language: input.language }));
16
+ },
17
+ };
18
+ }
19
+ /** Returns the input file's bytes unchanged: a valid audio file, so a pipeline with it still renders. */
20
+ export function createFakeIsolationProvider() {
21
+ const calls = [];
22
+ return {
23
+ id: "fake",
24
+ calls,
25
+ isolate(input) {
26
+ calls.push(input.audio);
27
+ return Promise.resolve(ok(readFileSync(input.audio)));
28
+ },
29
+ };
30
+ }
31
+ /** Returns `audio` (by default a few bytes that are not audio: enough for tests that never decode it). */
32
+ export function createFakeMusicProvider(audio = Buffer.from("fake music")) {
33
+ const calls = [];
34
+ return {
35
+ id: "fake",
36
+ model: "fake-music",
37
+ calls,
38
+ compose(input) {
39
+ calls.push({ kind: "compose", ...input });
40
+ return Promise.resolve(ok(audio));
41
+ },
42
+ scoreVideo(input) {
43
+ calls.push({ kind: "video", ...input });
44
+ return Promise.resolve(ok(audio));
45
+ },
46
+ };
47
+ }
48
+ const round = (value) => Math.round(value * 1000) / 1000 || 0;
49
+ /** Silence kept before the first and after the last placeholder word. */
50
+ const PLACEHOLDER_MARGIN = 0.3;
51
+ /**
52
+ * The free stand-in transcript of `--placeholder`: the script's words spread evenly over the clip, each lasting 80 %
53
+ * of its slot. No script, no words: the clip is kept whole.
54
+ */
55
+ export function makePlaceholderTranscript(script, duration) {
56
+ const texts = (script ?? "").trim().split(/\s+/).filter((text) => text.length > 0);
57
+ const span = duration - 2 * PLACEHOLDER_MARGIN;
58
+ if (texts.length === 0 || span <= 0)
59
+ return [];
60
+ const slot = span / texts.length;
61
+ return texts.map((text, index) => {
62
+ const start = PLACEHOLDER_MARGIN + index * slot;
63
+ return { text, start: round(start), end: round(start + slot * 0.8) };
64
+ });
65
+ }
66
+ //# sourceMappingURL=fake.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fake.js","sourceRoot":"","sources":["../../src/footage/fake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,EAAE,EAAkB,MAAM,sBAAsB,CAAC;AAiB1D,MAAM,UAAU,qBAAqB,CAAC,UAA0B,EAAE;IAChE,MAAM,KAAK,GAAe,EAAE,CAAC;IAC7B,OAAO;QACL,EAAE,EAAE,MAAM;QACV,KAAK,EAAE,UAAU;QACjB,KAAK;QACL,UAAU,CAAC,KAAK;YACd,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAClB,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS;gBAAE,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;YACnG,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YACvD,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QACrG,CAAC;KACF,CAAC;AACJ,CAAC;AAMD,yGAAyG;AACzG,MAAM,UAAU,2BA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