@softure-ai/marketing-kit 0.15.0 → 0.17.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/CHANGELOG.md +91 -0
- package/README.md +138 -16
- package/dist/config/schema.d.ts +2 -1
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +7 -0
- package/dist/config/schema.js.map +1 -1
- package/dist/footage/clip-sound.d.ts +58 -0
- package/dist/footage/clip-sound.d.ts.map +1 -0
- package/dist/footage/clip-sound.js +103 -0
- package/dist/footage/clip-sound.js.map +1 -0
- package/dist/footage/declick.d.ts +1 -1
- package/dist/footage/declick.d.ts.map +1 -1
- package/dist/footage/declick.js +3 -4
- package/dist/footage/declick.js.map +1 -1
- package/dist/footage/draft.d.ts +19 -5
- package/dist/footage/draft.d.ts.map +1 -1
- package/dist/footage/draft.js +92 -22
- package/dist/footage/draft.js.map +1 -1
- package/dist/footage/elevenlabs.d.ts +5 -0
- package/dist/footage/elevenlabs.d.ts.map +1 -1
- package/dist/footage/elevenlabs.js +10 -3
- package/dist/footage/elevenlabs.js.map +1 -1
- package/dist/footage/failure.d.ts +12 -1
- package/dist/footage/failure.d.ts.map +1 -1
- package/dist/footage/failure.js +10 -1
- package/dist/footage/failure.js.map +1 -1
- package/dist/footage/fake.d.ts +10 -1
- package/dist/footage/fake.d.ts.map +1 -1
- package/dist/footage/fake.js +19 -4
- package/dist/footage/fake.js.map +1 -1
- package/dist/footage/hyperframes-capture.d.ts +30 -0
- package/dist/footage/hyperframes-capture.d.ts.map +1 -0
- package/dist/footage/hyperframes-capture.js +80 -0
- package/dist/footage/hyperframes-capture.js.map +1 -0
- package/dist/footage/isolate-ranges.d.ts +34 -6
- package/dist/footage/isolate-ranges.d.ts.map +1 -1
- package/dist/footage/isolate-ranges.js +90 -23
- package/dist/footage/isolate-ranges.js.map +1 -1
- package/dist/footage/loudness.d.ts +16 -2
- package/dist/footage/loudness.d.ts.map +1 -1
- package/dist/footage/loudness.js +10 -7
- package/dist/footage/loudness.js.map +1 -1
- package/dist/footage/paid.d.ts +12 -2
- package/dist/footage/paid.d.ts.map +1 -1
- package/dist/footage/paid.js +8 -3
- package/dist/footage/paid.js.map +1 -1
- package/dist/footage/pipeline.d.ts +14 -2
- package/dist/footage/pipeline.d.ts.map +1 -1
- package/dist/footage/pipeline.js +55 -46
- package/dist/footage/pipeline.js.map +1 -1
- package/dist/footage/providers.d.ts +5 -0
- package/dist/footage/providers.d.ts.map +1 -1
- package/dist/footage/providers.js.map +1 -1
- package/dist/footage/render.d.ts +1 -1
- package/dist/footage/render.d.ts.map +1 -1
- package/dist/footage/render.js +4 -3
- package/dist/footage/render.js.map +1 -1
- package/dist/footage/speech-ranges.d.ts +79 -11
- package/dist/footage/speech-ranges.d.ts.map +1 -1
- package/dist/footage/speech-ranges.js +137 -17
- package/dist/footage/speech-ranges.js.map +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/og/index.d.ts +2 -0
- package/dist/og/index.d.ts.map +1 -1
- package/dist/og/index.js +2 -0
- package/dist/og/index.js.map +1 -1
- package/dist/og/photo-cover.d.ts +74 -0
- package/dist/og/photo-cover.d.ts.map +1 -0
- package/dist/og/photo-cover.js +357 -0
- package/dist/og/photo-cover.js.map +1 -0
- package/dist/og/photo.d.ts +51 -0
- package/dist/og/photo.d.ts.map +1 -0
- package/dist/og/photo.js +154 -0
- package/dist/og/photo.js.map +1 -0
- package/dist/voice/provider-failure.d.ts +41 -0
- package/dist/voice/provider-failure.d.ts.map +1 -0
- package/dist/voice/provider-failure.js +68 -0
- package/dist/voice/provider-failure.js.map +1 -0
- package/dist/voice/provider.d.ts +7 -1
- package/dist/voice/provider.d.ts.map +1 -1
- package/dist/voice/provider.js +1 -1
- package/dist/voice/provider.js.map +1 -1
- package/package.json +2 -1
- package/schema/marketing.schema.json +6 -0
- package/src/config/schema.ts +7 -0
- package/src/footage/clip-sound.ts +124 -0
- package/src/footage/declick.ts +3 -4
- package/src/footage/draft.ts +123 -22
- package/src/footage/elevenlabs.ts +11 -3
- package/src/footage/failure.ts +14 -1
- package/src/footage/fake.ts +28 -4
- package/src/footage/hyperframes-capture.ts +100 -0
- package/src/footage/isolate-ranges.ts +124 -29
- package/src/footage/loudness.ts +17 -8
- package/src/footage/paid.ts +25 -3
- package/src/footage/pipeline.ts +68 -47
- package/src/footage/providers.ts +5 -0
- package/src/footage/render.ts +4 -3
- package/src/footage/speech-ranges.ts +184 -19
- package/src/index.ts +49 -1
- package/src/og/index.ts +28 -0
- package/src/og/photo-cover.ts +442 -0
- package/src/og/photo.ts +177 -0
- package/src/voice/provider-failure.ts +98 -0
- package/src/voice/provider.ts +7 -2
package/src/og/photo.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { err, ok, type OgResult } from "./result.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What a photo's header says, read without decoding it: the format, the stored pixel size and the EXIF orientation.
|
|
5
|
+
* resvg draws a JPEG or PNG as stored and ignores EXIF orientation, so a cover applies the orientation itself
|
|
6
|
+
* (`getOrientationMatrix`).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type PhotoFormat = "jpeg" | "png";
|
|
10
|
+
|
|
11
|
+
/** EXIF orientation 1-8: 1 is upright, 5-8 swap width and height. */
|
|
12
|
+
export type PhotoOrientation = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
13
|
+
|
|
14
|
+
export interface PhotoInfo {
|
|
15
|
+
format: PhotoFormat;
|
|
16
|
+
/** The stored size, before orientation. */
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
orientation: PhotoOrientation;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
23
|
+
const EXIF_HEADER = Buffer.from("Exif\0\0", "latin1");
|
|
24
|
+
const ORIENTATION_TAG = 0x0112;
|
|
25
|
+
const SHORT_TYPE = 3;
|
|
26
|
+
|
|
27
|
+
function isOrientation(value: number): value is PhotoOrientation {
|
|
28
|
+
return Number.isInteger(value) && value >= 1 && value <= 8;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The orientation in a TIFF block (an EXIF payload after `Exif\0\0`, or a PNG `eXIf` chunk); 1 when absent. */
|
|
32
|
+
export function readTiffOrientation(tiff: Buffer): PhotoOrientation {
|
|
33
|
+
if (tiff.length < 8) return 1;
|
|
34
|
+
const order = tiff.toString("latin1", 0, 2);
|
|
35
|
+
if (order !== "II" && order !== "MM") return 1;
|
|
36
|
+
const isLittle = order === "II";
|
|
37
|
+
const u16 = (offset: number) => (isLittle ? tiff.readUInt16LE(offset) : tiff.readUInt16BE(offset));
|
|
38
|
+
const u32 = (offset: number) => (isLittle ? tiff.readUInt32LE(offset) : tiff.readUInt32BE(offset));
|
|
39
|
+
if (u16(2) !== 42) return 1;
|
|
40
|
+
const ifd = u32(4);
|
|
41
|
+
if (ifd + 2 > tiff.length) return 1;
|
|
42
|
+
const count = u16(ifd);
|
|
43
|
+
for (let index = 0; index < count; index += 1) {
|
|
44
|
+
const entry = ifd + 2 + index * 12;
|
|
45
|
+
if (entry + 12 > tiff.length) return 1;
|
|
46
|
+
if (u16(entry) !== ORIENTATION_TAG) continue;
|
|
47
|
+
if (u16(entry + 2) !== SHORT_TYPE) return 1;
|
|
48
|
+
const value = u16(entry + 8);
|
|
49
|
+
return isOrientation(value) ? value : 1;
|
|
50
|
+
}
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** SOFn markers carry the frame size; C4 (DHT), C8 (JPG) and CC (DAC) share the range but are not frames. */
|
|
55
|
+
function isStartOfFrame(marker: number): boolean {
|
|
56
|
+
return marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function readJpegInfo(bytes: Buffer): OgResult<PhotoInfo> {
|
|
60
|
+
let orientation: PhotoOrientation = 1;
|
|
61
|
+
let offset = 2;
|
|
62
|
+
while (offset + 4 <= bytes.length) {
|
|
63
|
+
if (bytes[offset] !== 0xff) return err("the JPEG's markers are damaged");
|
|
64
|
+
const marker = bytes[offset + 1] ?? 0;
|
|
65
|
+
// Fill bytes and markers without a length (RSTn, TEM) carry no segment.
|
|
66
|
+
if (marker === 0xff) {
|
|
67
|
+
offset += 1;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7)) {
|
|
71
|
+
offset += 2;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (marker === 0xd9 || marker === 0xda) break;
|
|
75
|
+
const length = bytes.readUInt16BE(offset + 2);
|
|
76
|
+
const start = offset + 4;
|
|
77
|
+
const end = offset + 2 + length;
|
|
78
|
+
if (length < 2 || end > bytes.length) return err("the JPEG ends inside a segment");
|
|
79
|
+
if (marker === 0xe1 && bytes.subarray(start, start + EXIF_HEADER.length).equals(EXIF_HEADER)) {
|
|
80
|
+
orientation = readTiffOrientation(bytes.subarray(start + EXIF_HEADER.length, end));
|
|
81
|
+
}
|
|
82
|
+
if (isStartOfFrame(marker)) {
|
|
83
|
+
if (length < 7) return err("the JPEG's frame header is too short");
|
|
84
|
+
const height = bytes.readUInt16BE(start + 1);
|
|
85
|
+
const width = bytes.readUInt16BE(start + 3);
|
|
86
|
+
if (width === 0 || height === 0) return err("the JPEG has no pixel size");
|
|
87
|
+
return ok({ format: "jpeg", width, height, orientation });
|
|
88
|
+
}
|
|
89
|
+
offset = end;
|
|
90
|
+
}
|
|
91
|
+
return err("the JPEG has no frame header");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function readPngInfo(bytes: Buffer): OgResult<PhotoInfo> {
|
|
95
|
+
if (bytes.length < 33 || bytes.toString("latin1", 12, 16) !== "IHDR") return err("the PNG has no IHDR chunk");
|
|
96
|
+
const width = bytes.readUInt32BE(16);
|
|
97
|
+
const height = bytes.readUInt32BE(20);
|
|
98
|
+
if (width === 0 || height === 0) return err("the PNG has no pixel size");
|
|
99
|
+
let orientation: PhotoOrientation = 1;
|
|
100
|
+
let offset = 8;
|
|
101
|
+
while (offset + 8 <= bytes.length) {
|
|
102
|
+
const length = bytes.readUInt32BE(offset);
|
|
103
|
+
const type = bytes.toString("latin1", offset + 4, offset + 8);
|
|
104
|
+
const end = offset + 12 + length;
|
|
105
|
+
if (end > bytes.length) break;
|
|
106
|
+
if (type === "eXIf") orientation = readTiffOrientation(bytes.subarray(offset + 8, offset + 8 + length));
|
|
107
|
+
if (type === "IDAT" || type === "IEND") break;
|
|
108
|
+
offset = end;
|
|
109
|
+
}
|
|
110
|
+
return ok({ format: "png", width, height, orientation });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The format, stored size and orientation of a JPEG or PNG; anything else is an error naming what is wrong. */
|
|
114
|
+
export function readPhotoInfo(bytes: Buffer): OgResult<PhotoInfo> {
|
|
115
|
+
if (bytes.length >= 3 && bytes[0] === 0xff && bytes[1] === 0xd8 && bytes[2] === 0xff) return readJpegInfo(bytes);
|
|
116
|
+
if (bytes.subarray(0, PNG_SIGNATURE.length).equals(PNG_SIGNATURE)) return readPngInfo(bytes);
|
|
117
|
+
return err("it is neither a JPEG nor a PNG");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The size a viewer shows: orientations 5-8 turn the photo a quarter, swapping width and height. */
|
|
121
|
+
export function getOrientedSize(info: Pick<PhotoInfo, "width" | "height" | "orientation">): { width: number; height: number } {
|
|
122
|
+
return info.orientation >= 5 ? { width: info.height, height: info.width } : { width: info.width, height: info.height };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The SVG `matrix(a b c d e f)` that maps the stored pixels (`width` × `height`) onto the upright photo, so that
|
|
127
|
+
* `x' = a·x + c·y + e` and `y' = b·x + d·y + f`.
|
|
128
|
+
*/
|
|
129
|
+
export function getOrientationMatrix(orientation: PhotoOrientation, width: number, height: number): readonly [number, number, number, number, number, number] {
|
|
130
|
+
switch (orientation) {
|
|
131
|
+
case 1:
|
|
132
|
+
return [1, 0, 0, 1, 0, 0];
|
|
133
|
+
case 2:
|
|
134
|
+
return [-1, 0, 0, 1, width, 0];
|
|
135
|
+
case 3:
|
|
136
|
+
return [-1, 0, 0, -1, width, height];
|
|
137
|
+
case 4:
|
|
138
|
+
return [1, 0, 0, -1, 0, height];
|
|
139
|
+
case 5:
|
|
140
|
+
return [0, 1, 1, 0, 0, 0];
|
|
141
|
+
case 6:
|
|
142
|
+
return [0, 1, -1, 0, height, 0];
|
|
143
|
+
case 7:
|
|
144
|
+
return [0, -1, -1, 0, height, width];
|
|
145
|
+
case 8:
|
|
146
|
+
return [0, -1, 1, 0, 0, width];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** A point of the photo as fractions of its upright width and height, 0..1. */
|
|
151
|
+
export interface FocusPoint {
|
|
152
|
+
x: number;
|
|
153
|
+
y: number;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** How the upright photo is scaled and shifted to cover the frame. */
|
|
157
|
+
export interface CoverCrop {
|
|
158
|
+
scale: number;
|
|
159
|
+
/** The scaled photo's offset from the frame's top-left corner, zero or negative. */
|
|
160
|
+
x: number;
|
|
161
|
+
y: number;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Scales the upright photo to cover `frame` and shifts it so the focus point sits as near the frame's centre as the
|
|
166
|
+
* photo allows: an edge of the photo never comes inside the frame.
|
|
167
|
+
*/
|
|
168
|
+
export function getCoverCrop(photo: { width: number; height: number }, frame: readonly [number, number], focus: FocusPoint): CoverCrop {
|
|
169
|
+
const [width, height] = frame;
|
|
170
|
+
const scale = Math.max(width / photo.width, height / photo.height);
|
|
171
|
+
const place = (length: number, target: number, at: number) => {
|
|
172
|
+
const scaled = length * scale;
|
|
173
|
+
const offset = target / 2 - at * scaled;
|
|
174
|
+
return Math.min(0, Math.max(target - scaled, offset));
|
|
175
|
+
};
|
|
176
|
+
return { scale, x: place(photo.width, width, focus.x), y: place(photo.height, height, focus.y) };
|
|
177
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why a paid provider call failed, as values an app can log and act on (issue #1141). Every field is safe to log:
|
|
3
|
+
* no key, path, transcript or audio content. `message` is the provider's own message, truncated.
|
|
4
|
+
* - `refused`: the provider answered a 4xx other than 408 and 429 (a bad input, key or balance). Asking again fails
|
|
5
|
+
* the same way.
|
|
6
|
+
* - `rate_limited`: 429. `unavailable`: 5xx. `timeout`: 408 or the request timed out. `connection`: no answer.
|
|
7
|
+
*/
|
|
8
|
+
export interface ProviderFailure {
|
|
9
|
+
kind: ProviderFailureKind;
|
|
10
|
+
/** The HTTP status; null when the provider never answered. */
|
|
11
|
+
status: number | null;
|
|
12
|
+
/** The provider's error code (e.g. `audio_too_short`); null when it gave none. */
|
|
13
|
+
code: string | null;
|
|
14
|
+
/** The provider's message, at most `PROVIDER_MESSAGE_LENGTH` characters; null when it gave none. */
|
|
15
|
+
message: string | null;
|
|
16
|
+
/** The provider's request id (header `request-id` or `x-request-id`, or the body's `request_id`). */
|
|
17
|
+
requestId: string | null;
|
|
18
|
+
/** True for 5xx, 408, 429, a timeout and a failed connection: asking again may succeed. */
|
|
19
|
+
isRetryable: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type ProviderFailureKind = "refused" | "rate_limited" | "unavailable" | "timeout" | "connection";
|
|
23
|
+
|
|
24
|
+
export const PROVIDER_MESSAGE_LENGTH = 300;
|
|
25
|
+
|
|
26
|
+
const REQUEST_ID_HEADERS = ["request-id", "x-request-id"];
|
|
27
|
+
|
|
28
|
+
/** The kind of an HTTP status the provider answered (not 2xx). */
|
|
29
|
+
export function getProviderFailureKind(status: number): ProviderFailureKind {
|
|
30
|
+
if (status === 429) return "rate_limited";
|
|
31
|
+
if (status === 408) return "timeout";
|
|
32
|
+
if (status >= 500) return "unavailable";
|
|
33
|
+
return "refused";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const isRetryableKind = (kind: ProviderFailureKind): boolean => kind !== "refused";
|
|
37
|
+
|
|
38
|
+
const truncate = (text: string): string | null => {
|
|
39
|
+
const trimmed = text.trim();
|
|
40
|
+
return trimmed.length === 0 ? null : trimmed.slice(0, PROVIDER_MESSAGE_LENGTH);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const readString = (value: unknown): string | null => (typeof value === "string" && value.trim().length > 0 ? value.trim() : null);
|
|
44
|
+
|
|
45
|
+
interface ErrorBody {
|
|
46
|
+
code: string | null;
|
|
47
|
+
message: string | null;
|
|
48
|
+
requestId: string | null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The provider's code, message and request id from an error body: `{ detail: { code | status, message, request_id } }`, `{ detail: "…" }` or text. */
|
|
52
|
+
export function readProviderErrorBody(text: string): ErrorBody {
|
|
53
|
+
let body: unknown;
|
|
54
|
+
try {
|
|
55
|
+
body = JSON.parse(text) as unknown;
|
|
56
|
+
} catch {
|
|
57
|
+
return { code: null, message: truncate(text), requestId: null };
|
|
58
|
+
}
|
|
59
|
+
const root = typeof body === "object" && body !== null ? (body as Record<string, unknown>) : {};
|
|
60
|
+
const detail = root.detail ?? root.error ?? root;
|
|
61
|
+
if (typeof detail === "string") return { code: null, message: truncate(detail), requestId: readString(root.request_id) };
|
|
62
|
+
const fields = typeof detail === "object" && detail !== null ? (detail as Record<string, unknown>) : {};
|
|
63
|
+
const message = readString(fields.message);
|
|
64
|
+
return {
|
|
65
|
+
code: readString(fields.code) ?? readString(fields.status) ?? readString(fields.type),
|
|
66
|
+
message: message === null ? null : truncate(message),
|
|
67
|
+
requestId: readString(fields.request_id) ?? readString(root.request_id),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The failure of a response that is not 2xx, from its status, headers and body text. */
|
|
72
|
+
export function getProviderFailure(response: Response, text: string): ProviderFailure {
|
|
73
|
+
const body = readProviderErrorBody(text);
|
|
74
|
+
const header = REQUEST_ID_HEADERS.map((name) => readString(response.headers.get(name))).find((value) => value !== null) ?? null;
|
|
75
|
+
const kind = getProviderFailureKind(response.status);
|
|
76
|
+
return { kind, status: response.status, code: body.code, message: body.message, requestId: header ?? body.requestId, isRetryable: isRetryableKind(kind) };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The failure of a request that got no answer: `timeout` when it timed out, `connection` otherwise. */
|
|
80
|
+
export function getConnectionFailure(error: unknown): ProviderFailure {
|
|
81
|
+
const kind: ProviderFailureKind = error instanceof Error && error.name === "TimeoutError" ? "timeout" : "connection";
|
|
82
|
+
return { kind, status: null, code: null, message: null, requestId: null, isRetryable: true };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** A failure the kit decides before any request (e.g. a missing key): `refused`, with the kit's own code. */
|
|
86
|
+
export function getLocalRefusal(code: string): ProviderFailure {
|
|
87
|
+
return { kind: "refused", status: null, code, message: null, requestId: null, isRetryable: false };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The failure in one line for a log: kind, status, code, request id and message. */
|
|
91
|
+
export function describeProviderFailure(failure: ProviderFailure): string {
|
|
92
|
+
const parts: string[] = [failure.kind];
|
|
93
|
+
if (failure.status !== null) parts.push(String(failure.status));
|
|
94
|
+
if (failure.code !== null) parts.push(failure.code);
|
|
95
|
+
if (failure.requestId !== null) parts.push(`request ${failure.requestId}`);
|
|
96
|
+
const head = parts.join(", ");
|
|
97
|
+
return failure.message === null ? head : `${head}: ${failure.message}`;
|
|
98
|
+
}
|
package/src/voice/provider.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ProviderFailure } from "./provider-failure.js";
|
|
1
2
|
import type { TimedWord } from "./voiceover.js";
|
|
2
3
|
|
|
3
4
|
/** What a provider speaks: the text in one voice, model and language. */
|
|
@@ -26,7 +27,11 @@ export interface TtsEstimate {
|
|
|
26
27
|
unit: string;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
/**
|
|
31
|
+
* A provider's answer. A failure carries `error`, the sentence for logs, and, when the provider answered (or the kit
|
|
32
|
+
* refused before asking), `providerFailure`: what an app logs and reads to decide whether to ask again (#1141).
|
|
33
|
+
*/
|
|
34
|
+
export type TtsResult<T> = { ok: true; value: T } | { ok: false; error: string; providerFailure?: ProviderFailure };
|
|
30
35
|
|
|
31
36
|
/**
|
|
32
37
|
* A text-to-speech service. `estimate` is free and needs no credentials; `synthesize` may spend
|
|
@@ -39,4 +44,4 @@ export interface TtsProvider {
|
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
export const ok = <T>(value: T): TtsResult<T> => ({ ok: true, value });
|
|
42
|
-
export const err = <T>(error: string): TtsResult<T> => ({ ok: false, error });
|
|
47
|
+
export const err = <T>(error: string, providerFailure?: ProviderFailure): TtsResult<T> => (providerFailure === undefined ? { ok: false, error } : { ok: false, error, providerFailure });
|