@slidevideo/cli 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +3 -3
- package/addons/slidevideo/geometry.ts +334 -1
- package/addons/slidevideo/global-top.vue +57 -6
- package/addons/slidevideo/preview.ts +242 -25
- package/assets/fonts/OFL-LICENSES.txt +95 -0
- package/assets/fonts/instrument-serif-latin-2.woff2 +0 -0
- package/assets/fonts/instrument-serif-latin-ext-1.woff2 +0 -0
- package/assets/fonts/jetbrains-mono-latin-4.woff2 +0 -0
- package/assets/fonts/jetbrains-mono-latin-ext-3.woff2 +0 -0
- package/assets/fonts/plus-jakarta-sans-latin-6.woff2 +0 -0
- package/assets/fonts/plus-jakarta-sans-latin-ext-5.woff2 +0 -0
- package/dist/adapters/edge.d.ts +1 -0
- package/dist/adapters/edge.js +4 -3
- package/dist/adapters/elevenlabs.d.ts +1 -0
- package/dist/adapters/elevenlabs.js +4 -3
- package/dist/adapters/powerpoint-preview.d.ts +1 -1
- package/dist/adapters/powerpoint-preview.js +13 -2
- package/dist/adapters/powerpoint.js +91 -14
- package/dist/adapters/slidev-inspection.js +7 -2
- package/dist/annotation-paint.d.ts +195 -5
- package/dist/annotation-paint.js +1188 -2
- package/dist/annotations.d.ts +26 -2
- package/dist/annotations.js +1117 -29
- package/dist/assembly.js +143 -37
- package/dist/captions.d.ts +6 -0
- package/dist/captions.js +320 -0
- package/dist/cli.js +59 -19
- package/dist/compositor.d.ts +17 -2
- package/dist/compositor.js +108 -26
- package/dist/contracts.d.ts +254 -14
- package/dist/media.js +24 -1
- package/dist/pipeline.d.ts +6 -1
- package/dist/pipeline.js +68 -20
- package/dist/preview/contracts.d.ts +15 -0
- package/dist/preview/player.js +527 -34
- package/dist/preview/server.d.ts +1 -1
- package/dist/preview/server.js +125 -4
- package/dist/preview/view.d.ts +1 -1
- package/dist/preview/view.js +26 -7
- package/dist/run.d.ts +1 -0
- package/dist/run.js +20 -0
- package/dist/speech.d.ts +13 -3
- package/dist/speech.js +164 -45
- package/dist/stamp-fonts.d.ts +17 -0
- package/dist/stamp-fonts.js +202 -0
- package/dist/storyboard.js +60 -3
- package/dist/timing.d.ts +4 -1
- package/dist/timing.js +322 -14
- package/dist/update-check-worker.js +43 -11
- package/dist/update-check.js +14 -10
- package/package.json +12 -1
- package/schemas/annotation-geometry.v1.json +111 -0
- package/schemas/schedule.v1.json +1672 -84
- package/schemas/storyboard.v1.json +3725 -85
- package/skills/slidevideo/SKILL.md +5 -5
- package/skills/slidevideo/references/decks.md +6 -4
- package/skills/slidevideo/references/production.md +12 -11
- package/skills/slidevideo/references/storyboard.md +268 -5
- package/tools/powerpoint/powerpoint.ps1 +155 -6
- package/tools/powerpoint/preview.ps1 +68 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnnotationGeometry, ResolvedAnnotation, Schedule, ScheduledAction } from '../../dist/contracts.js'
|
|
2
|
-
import { annotationPaint, findTargetGeometry, geometryRequests, underlineFragmentsVisible, type PaintableEffect } from '../../dist/annotation-paint.js'
|
|
2
|
+
import { annotationPaint, findTargetGeometry, geometryRequests, laserPaint, laserVisible, spotlightAperturesVisible, stampPaint, stampVisible, underlineFragmentsVisible, zoomTransformVisible, type PaintableEffect } from '../../dist/annotation-paint.js'
|
|
3
3
|
import { playbackEntries } from './playback-entries'
|
|
4
4
|
import { geometryCollector } from './geometry'
|
|
5
5
|
|
|
@@ -11,6 +11,7 @@ export function createPreview(
|
|
|
11
11
|
parentOrigin: string,
|
|
12
12
|
prepare: (schedule: Schedule, hashes: Record<string, string>) => Promise<void>,
|
|
13
13
|
apply: (item: ScheduledAction) => Promise<void>,
|
|
14
|
+
navigateTo: (slideTarget: string, visitId: string, click: number) => Promise<void>,
|
|
14
15
|
position: () => Position,
|
|
15
16
|
render: (effects: PaintableEffect[], timeMs: number) => void,
|
|
16
17
|
) {
|
|
@@ -19,24 +20,41 @@ export function createPreview(
|
|
|
19
20
|
let offset = 0
|
|
20
21
|
let origin = 0
|
|
21
22
|
let generation = 0
|
|
23
|
+
let nextIndex = 0
|
|
22
24
|
let frame = 0
|
|
23
25
|
let lastNotification = 0
|
|
24
26
|
let timer: ReturnType<typeof setTimeout> | undefined
|
|
25
27
|
let wake: (() => void) | undefined
|
|
26
28
|
let running: Promise<void> | undefined
|
|
27
|
-
let
|
|
29
|
+
let completedSeekId = 0
|
|
28
30
|
let collector: ReturnType<typeof geometryCollector> | undefined
|
|
29
31
|
const geometry: AnnotationGeometry[] = []
|
|
30
32
|
const active = new Map<string, ResolvedAnnotation>()
|
|
31
33
|
const media = new Set<HTMLMediaElement>()
|
|
32
34
|
const animations = new Set<Animation>()
|
|
35
|
+
const allGeometryRequests = geometryRequests(schedule)
|
|
33
36
|
const entries: (ReturnType<typeof playbackEntries>[number] | { at: number; order: number; type: 'media-end'; id: string })[] = playbackEntries(schedule)
|
|
34
37
|
for (const item of schedule.actions) if (item.action.type === 'play') entries.push({ at: item.end_ms, order: 0, type: 'media-end', id: item.action.media })
|
|
35
38
|
entries.sort((a, b) => a.at - b.at || a.order - b.order)
|
|
36
39
|
|
|
37
40
|
const elapsed = () => Math.min(schedule.duration_ms, status === 'playing' ? offset + performance.now() - origin : offset)
|
|
41
|
+
function firstEntryAfter(targetMs: number) {
|
|
42
|
+
let index = 0
|
|
43
|
+
while (index < entries.length && entries[index].at <= targetMs) index++
|
|
44
|
+
return index
|
|
45
|
+
}
|
|
46
|
+
function seekMediaElement(element: HTMLMediaElement, seconds: number) {
|
|
47
|
+
return new Promise<void>(resolve => {
|
|
48
|
+
if (Math.abs(element.currentTime - seconds) < 0.005) { resolve(); return }
|
|
49
|
+
let settled = false
|
|
50
|
+
const done = () => { if (!settled) { settled = true; clearTimeout(timeout); resolve() } }
|
|
51
|
+
const timeout = setTimeout(done, 500)
|
|
52
|
+
element.addEventListener('seeked', done, { once: true })
|
|
53
|
+
element.currentTime = seconds
|
|
54
|
+
})
|
|
55
|
+
}
|
|
38
56
|
function notify() {
|
|
39
|
-
window.parent.postMessage({ type: 'slidevideo-preview-state', status, elapsedMs: elapsed(), durationMs: schedule.duration_ms, ...(message ? { message } : {}) }, parentOrigin)
|
|
57
|
+
window.parent.postMessage({ type: 'slidevideo-preview-state', status, elapsedMs: elapsed(), durationMs: schedule.duration_ms, seekId: completedSeekId, ...(message ? { message } : {}) }, parentOrigin)
|
|
40
58
|
}
|
|
41
59
|
function interruptWait() {
|
|
42
60
|
clearTimeout(timer); timer = undefined
|
|
@@ -56,19 +74,56 @@ export function createPreview(
|
|
|
56
74
|
offset = elapsed(); status = 'error'; message = error instanceof Error ? error.message : String(error)
|
|
57
75
|
freeze(); stop(); notify()
|
|
58
76
|
}
|
|
77
|
+
let measureCtx: CanvasRenderingContext2D | null = null
|
|
78
|
+
const measureText = (font: string, text: string) => {
|
|
79
|
+
measureCtx ??= document.createElement('canvas').getContext('2d')
|
|
80
|
+
if (!measureCtx) return text.length * 12
|
|
81
|
+
measureCtx.font = font
|
|
82
|
+
return measureCtx.measureText(text).width
|
|
83
|
+
}
|
|
59
84
|
function paint() {
|
|
60
85
|
const output: PaintableEffect[] = []
|
|
61
86
|
for (const annotation of schedule.annotations) {
|
|
62
87
|
if (!active.has(annotation.id)) continue
|
|
63
88
|
switch (annotation.effect) {
|
|
64
89
|
case 'highlight':
|
|
65
|
-
case 'underline':
|
|
90
|
+
case 'underline':
|
|
91
|
+
case 'spotlight':
|
|
92
|
+
case 'zoom': {
|
|
66
93
|
const record = findTargetGeometry(geometry, annotation, annotation.target)
|
|
67
94
|
if (!record) throw new Error(`Annotation ${annotation.id}: preview geometry is unavailable`)
|
|
68
95
|
const painted = annotationPaint(annotation, record)
|
|
69
96
|
if (painted.effect === 'underline' && !underlineFragmentsVisible(painted)) {
|
|
70
97
|
throw new Error(`Annotation ${annotation.id}: underline is clipped outside the slide-content rectangle`)
|
|
71
98
|
}
|
|
99
|
+
if (painted.effect === 'spotlight' && !spotlightAperturesVisible(painted)) {
|
|
100
|
+
throw new Error(`Annotation ${annotation.id}: spotlight aperture is clipped outside the slide-content rectangle`)
|
|
101
|
+
}
|
|
102
|
+
if (painted.effect === 'zoom' && !zoomTransformVisible(painted)) {
|
|
103
|
+
throw new Error(`Annotation ${annotation.id}: zoom target and padding leave no magnification room inside the slide-content rectangle`)
|
|
104
|
+
}
|
|
105
|
+
output.push(painted)
|
|
106
|
+
break
|
|
107
|
+
}
|
|
108
|
+
case 'laser': {
|
|
109
|
+
const slideRecord = findTargetGeometry(geometry, annotation, { type: 'slide' })
|
|
110
|
+
if (!slideRecord) throw new Error(`Annotation ${annotation.id}: preview slide geometry is unavailable`)
|
|
111
|
+
const painted = laserPaint(annotation, slideRecord, target => findTargetGeometry(geometry, annotation, target)?.fragments)
|
|
112
|
+
if (!laserVisible(painted)) {
|
|
113
|
+
throw new Error(`Annotation ${annotation.id}: laser path has no visible pointer inside the slide-content rectangle`)
|
|
114
|
+
}
|
|
115
|
+
output.push(painted)
|
|
116
|
+
break
|
|
117
|
+
}
|
|
118
|
+
case 'stamp': {
|
|
119
|
+
const target = annotation.target.type === 'point' ? { type: 'slide' as const } : annotation.target
|
|
120
|
+
const record = findTargetGeometry(geometry, annotation, target)
|
|
121
|
+
if (!record) throw new Error(`Annotation ${annotation.id}: preview geometry is unavailable`)
|
|
122
|
+
const painted = stampPaint(annotation, record, measureText)
|
|
123
|
+
if (painted.overflow_error) throw new Error(`Annotation ${annotation.id}: ${painted.overflow_error}`)
|
|
124
|
+
if (!stampVisible(painted)) {
|
|
125
|
+
throw new Error(`Annotation ${annotation.id}: stamp is clipped outside the slide-content rectangle`)
|
|
126
|
+
}
|
|
72
127
|
output.push(painted)
|
|
73
128
|
break
|
|
74
129
|
}
|
|
@@ -93,10 +148,77 @@ export function createPreview(
|
|
|
93
148
|
if (performance.now() - lastNotification > 200) { notify(); lastNotification = performance.now() }
|
|
94
149
|
frame = requestAnimationFrame(tick)
|
|
95
150
|
}
|
|
96
|
-
|
|
151
|
+
function activateCollectorAt(targetMs: number, keepRunning: boolean) {
|
|
152
|
+
geometry.length = 0
|
|
153
|
+
active.clear()
|
|
154
|
+
collector?.stop()
|
|
155
|
+
collector = geometryCollector(allGeometryRequests, geometry, position, elapsed, fail)
|
|
156
|
+
for (const request of allGeometryRequests) {
|
|
157
|
+
if (request.start_ms <= targetMs && targetMs < request.end_ms) collector.start(request)
|
|
158
|
+
}
|
|
159
|
+
for (const annotation of schedule.annotations) {
|
|
160
|
+
if (annotation.start_ms <= targetMs && targetMs < annotation.end_ms) active.set(annotation.id, annotation)
|
|
161
|
+
}
|
|
162
|
+
paint()
|
|
163
|
+
if (!keepRunning) {
|
|
164
|
+
collector.stop()
|
|
165
|
+
collector = undefined
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async function reconstructState(targetMs: number, shouldPlay: boolean) {
|
|
169
|
+
let slideTarget = ''
|
|
170
|
+
let visitId = ''
|
|
171
|
+
let click = 0
|
|
172
|
+
let lastVisualStartMs = 0
|
|
173
|
+
for (const item of schedule.actions) {
|
|
174
|
+
if (item.start_ms > targetMs) break
|
|
175
|
+
if (item.action.type === 'slide') { slideTarget = item.action.target; visitId = item.id; click = 0; lastVisualStartMs = item.start_ms }
|
|
176
|
+
else if (item.action.type === 'reveal') { click = item.action.click; lastVisualStartMs = item.start_ms }
|
|
177
|
+
}
|
|
178
|
+
if (slideTarget) {
|
|
179
|
+
await navigateTo(slideTarget, visitId, click)
|
|
180
|
+
const elapsedSinceVisual = Math.max(0, targetMs - lastVisualStartMs)
|
|
181
|
+
for (const animation of document.getAnimations()) {
|
|
182
|
+
if (animation.playState !== 'running' && !animation.pending) continue
|
|
183
|
+
const timing = animation.effect?.getComputedTiming()
|
|
184
|
+
const endTime = typeof timing?.endTime === 'number' ? timing.endTime : Number.POSITIVE_INFINITY
|
|
185
|
+
if (Number.isFinite(endTime) && elapsedSinceVisual >= endTime) {
|
|
186
|
+
try { animation.finish() } catch {}
|
|
187
|
+
} else {
|
|
188
|
+
if (elapsedSinceVisual > 0) { try { animation.currentTime = elapsedSinceVisual } catch {} }
|
|
189
|
+
if (!shouldPlay) { animation.pause(); animations.add(animation) }
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
for (const element of media) element.pause()
|
|
194
|
+
media.clear()
|
|
195
|
+
for (const clip of schedule.media) {
|
|
196
|
+
const element = document.getElementById(clip.id)
|
|
197
|
+
if (element instanceof HTMLMediaElement) element.pause()
|
|
198
|
+
}
|
|
199
|
+
for (const item of schedule.actions) {
|
|
200
|
+
if (item.action.type !== 'play') continue
|
|
201
|
+
if (item.start_ms <= targetMs && targetMs < item.end_ms) {
|
|
202
|
+
const element = document.getElementById(item.action.media)
|
|
203
|
+
if (element instanceof HTMLMediaElement) {
|
|
204
|
+
const rate = item.action.rate ?? 1
|
|
205
|
+
const mediaMs = (item.action.trim_start_ms ?? 0) + (targetMs - item.start_ms) * rate
|
|
206
|
+
element.muted = true
|
|
207
|
+
element.playbackRate = rate
|
|
208
|
+
await seekMediaElement(element, mediaMs / 1000)
|
|
209
|
+
media.add(element)
|
|
210
|
+
if (shouldPlay) await element.play()
|
|
211
|
+
else element.pause()
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
activateCollectorAt(targetMs, shouldPlay)
|
|
216
|
+
}
|
|
217
|
+
async function run(current: number, startIndex: number) {
|
|
97
218
|
try {
|
|
98
|
-
collector = geometryCollector(
|
|
99
|
-
for (
|
|
219
|
+
if (!collector) collector = geometryCollector(allGeometryRequests, geometry, position, elapsed, fail)
|
|
220
|
+
for (let index = startIndex; index < entries.length; index++) {
|
|
221
|
+
const entry = entries[index]
|
|
100
222
|
if (!await waitUntil(entry.at, current)) return
|
|
101
223
|
if (entry.type === 'geometry-start') collector!.start(entry.request)
|
|
102
224
|
else if (entry.type === 'geometry-end') collector!.end(entry.request)
|
|
@@ -114,56 +236,151 @@ export function createPreview(
|
|
|
114
236
|
}
|
|
115
237
|
if (status === 'paused') freeze()
|
|
116
238
|
}
|
|
239
|
+
nextIndex = index + 1
|
|
117
240
|
}
|
|
118
241
|
if (!await waitUntil(schedule.duration_ms, current)) return
|
|
119
|
-
collector!.complete()
|
|
120
242
|
offset = schedule.duration_ms; status = 'ended'; stop(); notify()
|
|
121
243
|
} catch (error) { if (current === generation) fail(error) }
|
|
244
|
+
finally { if (current === generation) running = undefined }
|
|
122
245
|
}
|
|
123
|
-
async function
|
|
124
|
-
stop(); await running
|
|
246
|
+
async function doReset() {
|
|
247
|
+
stop(); await running; running = undefined
|
|
125
248
|
for (const animation of animations) animation.cancel()
|
|
126
249
|
animations.clear(); geometry.length = 0
|
|
127
|
-
offset = 0; status = 'loading'; message = ''; notify()
|
|
250
|
+
offset = 0; nextIndex = 0; status = 'loading'; message = ''; notify()
|
|
128
251
|
await prepare(schedule, hashes)
|
|
129
252
|
const first = schedule.actions[0]
|
|
130
253
|
if (first?.action.type === 'slide') await apply(first)
|
|
131
254
|
status = 'ready'; notify()
|
|
132
255
|
}
|
|
133
|
-
async function
|
|
134
|
-
if (
|
|
135
|
-
|
|
256
|
+
async function doSeek(rawMs: number, seekId?: number) {
|
|
257
|
+
if (status === 'error') await doReset()
|
|
258
|
+
const targetMs = Math.max(0, Math.min(schedule.duration_ms, Number.isFinite(rawMs) ? rawMs : 0))
|
|
259
|
+
const wasPlaying = status === 'playing' && targetMs < schedule.duration_ms
|
|
260
|
+
stop(); await running; running = undefined
|
|
261
|
+
const current = generation
|
|
262
|
+
for (const animation of animations) animation.cancel()
|
|
263
|
+
animations.clear()
|
|
264
|
+
offset = targetMs
|
|
265
|
+
status = targetMs >= schedule.duration_ms ? 'ended' : targetMs === 0 && !wasPlaying ? 'ready' : 'paused'
|
|
266
|
+
await reconstructState(targetMs, wasPlaying)
|
|
267
|
+
if (current !== generation) return
|
|
268
|
+
nextIndex = firstEntryAfter(targetMs)
|
|
269
|
+
if (seekId !== undefined) completedSeekId = seekId
|
|
270
|
+
if (targetMs >= schedule.duration_ms) {
|
|
271
|
+
stop()
|
|
272
|
+
notify()
|
|
273
|
+
return
|
|
274
|
+
}
|
|
275
|
+
if (wasPlaying) {
|
|
276
|
+
origin = performance.now()
|
|
277
|
+
status = 'playing'
|
|
278
|
+
frame = requestAnimationFrame(tick)
|
|
279
|
+
running = run(generation, nextIndex)
|
|
280
|
+
} else {
|
|
281
|
+
freeze()
|
|
282
|
+
}
|
|
283
|
+
notify()
|
|
136
284
|
}
|
|
137
|
-
async function
|
|
138
|
-
await
|
|
139
|
-
if (status === 'ended' || status === 'error') await restart()
|
|
285
|
+
async function doPlay() {
|
|
286
|
+
if (status === 'ended' || status === 'error') await doReset()
|
|
140
287
|
if (status !== 'ready' && status !== 'paused') return
|
|
141
|
-
const
|
|
288
|
+
const hadRunner = running !== undefined
|
|
289
|
+
if (!hadRunner && nextIndex > 0) activateCollectorAt(offset, true)
|
|
142
290
|
origin = performance.now(); status = 'playing'
|
|
143
291
|
for (const animation of animations) animation.play()
|
|
144
292
|
animations.clear()
|
|
145
293
|
try { for (const element of media) await element.play() } catch (error) { fail(error); return }
|
|
146
294
|
interruptWait(); notify()
|
|
147
|
-
if (!
|
|
295
|
+
if (!hadRunner) { frame = requestAnimationFrame(tick); running = run(generation, nextIndex) }
|
|
148
296
|
}
|
|
149
|
-
function
|
|
297
|
+
function doPause() {
|
|
150
298
|
if (status !== 'playing') return
|
|
151
299
|
offset = elapsed(); status = 'paused'; freeze(); interruptWait(); notify()
|
|
152
300
|
}
|
|
301
|
+
|
|
302
|
+
type OpPayload =
|
|
303
|
+
| { type: 'reset' }
|
|
304
|
+
| { type: 'play' }
|
|
305
|
+
| { type: 'pause' }
|
|
306
|
+
| { type: 'seek'; positionMs: number; seekId?: number }
|
|
307
|
+
type QueuedOp = { payload: OpPayload; resolve: () => void }
|
|
308
|
+
const cmdQueue: QueuedOp[] = []
|
|
309
|
+
let processing = false
|
|
310
|
+
let disposed = false
|
|
311
|
+
|
|
312
|
+
function clearQueue() {
|
|
313
|
+
while (cmdQueue.length) cmdQueue.shift()!.resolve()
|
|
314
|
+
}
|
|
315
|
+
function enqueue(payload: OpPayload): Promise<void> {
|
|
316
|
+
if (disposed) return Promise.resolve()
|
|
317
|
+
if (payload.type === 'seek' && cmdQueue.at(-1)?.payload.type === 'seek') {
|
|
318
|
+
const tail = cmdQueue.at(-1)!
|
|
319
|
+
tail.payload = payload
|
|
320
|
+
return new Promise<void>(resolve => {
|
|
321
|
+
const prev = tail.resolve
|
|
322
|
+
tail.resolve = () => { prev(); resolve() }
|
|
323
|
+
})
|
|
324
|
+
}
|
|
325
|
+
return new Promise<void>(resolve => {
|
|
326
|
+
cmdQueue.push({ payload, resolve })
|
|
327
|
+
void pumpQueue()
|
|
328
|
+
})
|
|
329
|
+
}
|
|
330
|
+
async function pumpQueue() {
|
|
331
|
+
if (processing) return
|
|
332
|
+
processing = true
|
|
333
|
+
try {
|
|
334
|
+
while (cmdQueue.length && !disposed) {
|
|
335
|
+
const op = cmdQueue.shift()!
|
|
336
|
+
try {
|
|
337
|
+
const p = op.payload
|
|
338
|
+
if (p.type === 'reset') await doReset()
|
|
339
|
+
else if (p.type === 'play') await doPlay()
|
|
340
|
+
else if (p.type === 'pause') doPause()
|
|
341
|
+
else if (p.type === 'seek') await doSeek(p.positionMs, p.seekId)
|
|
342
|
+
} catch (error) {
|
|
343
|
+
fail(error)
|
|
344
|
+
clearQueue()
|
|
345
|
+
} finally {
|
|
346
|
+
op.resolve()
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
} finally {
|
|
350
|
+
processing = false
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const play = () => enqueue({ type: 'play' })
|
|
355
|
+
const pause = () => {
|
|
356
|
+
if (!processing && cmdQueue.length === 0) { doPause(); return }
|
|
357
|
+
void enqueue({ type: 'pause' })
|
|
358
|
+
}
|
|
359
|
+
const restart = () => {
|
|
360
|
+
clearQueue()
|
|
361
|
+
return enqueue({ type: 'reset' })
|
|
362
|
+
}
|
|
363
|
+
const seek = (targetMs: number, seekId?: number) => enqueue({ type: 'seek', positionMs: targetMs, seekId })
|
|
364
|
+
|
|
153
365
|
function receive(event: MessageEvent) {
|
|
154
366
|
if (event.source !== window.parent || event.origin !== parentOrigin || event.data?.type !== 'slidevideo-preview') return
|
|
155
367
|
if (event.data.action === 'hello') notify()
|
|
156
|
-
if (event.data.action === 'play') void play()
|
|
368
|
+
if (event.data.action === 'play') void play()
|
|
157
369
|
if (event.data.action === 'pause') pause()
|
|
158
|
-
if (event.data.action === 'restart')
|
|
370
|
+
if (event.data.action === 'restart') {
|
|
371
|
+
clearQueue()
|
|
372
|
+
void enqueue({ type: 'reset' })
|
|
373
|
+
void enqueue({ type: 'play' })
|
|
374
|
+
}
|
|
375
|
+
if (event.data.action === 'seek' && typeof event.data.positionMs === 'number') void seek(event.data.positionMs, typeof event.data.seekId === 'number' ? event.data.seekId : undefined)
|
|
159
376
|
}
|
|
160
377
|
window.addEventListener('message', receive)
|
|
161
378
|
return {
|
|
162
379
|
get status() { return status },
|
|
163
380
|
get elapsedMs() { return elapsed() },
|
|
164
381
|
durationMs: schedule.duration_ms,
|
|
165
|
-
play, pause, restart,
|
|
166
|
-
initialize:
|
|
167
|
-
dispose() { stop(); window.removeEventListener('message', receive) },
|
|
382
|
+
play, pause, restart, seek,
|
|
383
|
+
initialize: () => enqueue({ type: 'reset' }),
|
|
384
|
+
dispose() { disposed = true; clearQueue(); stop(); window.removeEventListener('message', receive) },
|
|
168
385
|
}
|
|
169
386
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Copyright 2020 The Plus Jakarta Sans Project Authors (https://github.com/tokotype/PlusJakartaSans)
|
|
2
|
+
Copyright 2022 The Instrument Serif Project Authors (https://github.com/Instrument/instrument-serif)
|
|
3
|
+
Copyright 2020 The JetBrains Mono Project Authors (https://github.com/JetBrains/JetBrainsMono)
|
|
4
|
+
|
|
5
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
6
|
+
This license is copied below, and is also available with a FAQ at:
|
|
7
|
+
https://openfontlicense.org/
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
12
|
+
-----------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
PREAMBLE
|
|
15
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
16
|
+
development of collaborative font projects, to support the font creation
|
|
17
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
18
|
+
open framework in which fonts may be shared and improved in partnership
|
|
19
|
+
with others.
|
|
20
|
+
|
|
21
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
22
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
23
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
24
|
+
redistributed and/or sold with any software provided that any reserved
|
|
25
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
26
|
+
however, cannot be released under any other type of license. The
|
|
27
|
+
requirement for fonts to remain under this license does not apply
|
|
28
|
+
to any document created using the fonts or their derivatives.
|
|
29
|
+
|
|
30
|
+
DEFINITIONS
|
|
31
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
32
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
33
|
+
include source files, build scripts and documentation.
|
|
34
|
+
|
|
35
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
36
|
+
copyright statement(s).
|
|
37
|
+
|
|
38
|
+
"Original Version" refers to the collection of Font Software components as
|
|
39
|
+
distributed by the Copyright Holder(s).
|
|
40
|
+
|
|
41
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
42
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
43
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
44
|
+
new environment.
|
|
45
|
+
|
|
46
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
47
|
+
writer or other person who contributed to the Font Software.
|
|
48
|
+
|
|
49
|
+
PERMISSION & CONDITIONS
|
|
50
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
51
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
52
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
53
|
+
Software, subject to the following conditions:
|
|
54
|
+
|
|
55
|
+
1) Neither the Font Software nor any of its individual components,
|
|
56
|
+
in Original or Modified Versions, may be sold by itself.
|
|
57
|
+
|
|
58
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
59
|
+
redistributed and/or sold with any software, provided that each copy
|
|
60
|
+
contains the above copyright notice and this license. These can be
|
|
61
|
+
included either as stand-alone text files, human-readable headers or
|
|
62
|
+
in the appropriate machine-readable metadata fields within text or
|
|
63
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
64
|
+
|
|
65
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
66
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
67
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
68
|
+
presented to the users.
|
|
69
|
+
|
|
70
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
71
|
+
Software shall not be used to promote, endorse or advertise any
|
|
72
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
73
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
74
|
+
permission.
|
|
75
|
+
|
|
76
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
77
|
+
must be distributed entirely under this license, and must not be
|
|
78
|
+
distributed under any other license. The requirement for fonts to
|
|
79
|
+
remain under this license does not apply to any document created
|
|
80
|
+
using the Font Software.
|
|
81
|
+
|
|
82
|
+
TERMINATION
|
|
83
|
+
This license becomes null and void if any of the above conditions are
|
|
84
|
+
not met.
|
|
85
|
+
|
|
86
|
+
DISCLAIMER
|
|
87
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
88
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
89
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
90
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
91
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
92
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
93
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
94
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
95
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/adapters/edge.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Narration, SpeechAsset, TtsAdapter, Voice } from '../contracts.js'
|
|
|
2
2
|
export declare class EdgeAdapter implements TtsAdapter {
|
|
3
3
|
id: string;
|
|
4
4
|
version: string;
|
|
5
|
+
concurrency: number;
|
|
5
6
|
validate(voice: Voice): void;
|
|
6
7
|
synthesize(segment: Narration, voice: Voice, destination: string): Promise<Omit<SpeechAsset, 'key'>>;
|
|
7
8
|
}
|
package/dist/adapters/edge.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { rm } from 'node:fs/promises';
|
|
2
|
-
import { execute, saveJson, probe,
|
|
2
|
+
import { execute, saveJson, probe, hashFile, audioDuration } from '../media.js';
|
|
3
3
|
import { ProductionError, requireCondition } from '../errors.js';
|
|
4
4
|
import { packagePath } from '../installation.js';
|
|
5
5
|
import { executable } from '../executables.js';
|
|
6
6
|
export class EdgeAdapter {
|
|
7
7
|
id = 'edge-tts';
|
|
8
8
|
version = '7.3.1-adapter-1';
|
|
9
|
+
concurrency = 3;
|
|
9
10
|
validate(voice) {
|
|
10
11
|
for (const [key, value] of Object.entries(voice.options ?? {})) {
|
|
11
12
|
requireCondition(['rate', 'volume', 'pitch'].includes(key), 'VOICE_OPTION', `Edge TTS does not support option ${key}`, 3);
|
|
@@ -33,11 +34,11 @@ export class EdgeAdapter {
|
|
|
33
34
|
cursor = start + word.text.length;
|
|
34
35
|
return { ...word, start, end: cursor };
|
|
35
36
|
});
|
|
36
|
-
await decode(destination);
|
|
37
37
|
const properties = await probe(destination);
|
|
38
38
|
requireCondition(properties.has_audio && properties.duration_ms > 0, 'TTS_AUDIO', `Edge returned invalid audio for ${segment.id}`, 4);
|
|
39
|
+
const duration_ms = await audioDuration(destination);
|
|
39
40
|
return {
|
|
40
|
-
id: segment.id, audio: destination, sha256: await hashFile(destination), format: 'mp3', duration_ms
|
|
41
|
+
id: segment.id, audio: destination, sha256: await hashFile(destination), format: 'mp3', duration_ms,
|
|
41
42
|
transcript: { original: segment.text, normalized: segment.text },
|
|
42
43
|
alignment: { form: 'original', granularity: 'word', text: segment.text, units },
|
|
43
44
|
provenance: { adapter: this.id, version: this.version, provider: this.id, voice: voice.voice, options: voice.options ?? {}, generated_at: new Date().toISOString() },
|
|
@@ -3,6 +3,7 @@ export declare function elevenLabsApiKey(environment?: NodeJS.ProcessEnv): strin
|
|
|
3
3
|
export declare class ElevenLabsAdapter implements TtsAdapter {
|
|
4
4
|
id: string;
|
|
5
5
|
version: string;
|
|
6
|
+
concurrency: number;
|
|
6
7
|
validate(voice: Voice): void;
|
|
7
8
|
synthesize(segment: Narration, voice: Voice, destination: string): Promise<Omit<SpeechAsset, 'key'>>;
|
|
8
9
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { writeFile } from 'node:fs/promises';
|
|
2
2
|
import { configuredElevenLabsKey } from '../executables.js';
|
|
3
3
|
import { requireCondition, ProductionError } from '../errors.js';
|
|
4
|
-
import {
|
|
4
|
+
import { hashFile, probe, executionSignal, audioDuration } from '../media.js';
|
|
5
5
|
export function elevenLabsApiKey(environment = process.env) {
|
|
6
6
|
return environment.ELEVENLABS_API_KEY ?? environment.ELEVENLABS_KEY ?? configuredElevenLabsKey();
|
|
7
7
|
}
|
|
8
8
|
export class ElevenLabsAdapter {
|
|
9
9
|
id = 'elevenlabs';
|
|
10
10
|
version = '1';
|
|
11
|
+
concurrency = 2;
|
|
11
12
|
validate(voice) {
|
|
12
13
|
const options = voice.options ?? {};
|
|
13
14
|
for (const key of Object.keys(options))
|
|
@@ -50,11 +51,11 @@ export class ElevenLabsAdapter {
|
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
53
|
await writeFile(destination, Buffer.from(data.audio_base64, 'base64'));
|
|
53
|
-
await decode(destination);
|
|
54
54
|
const properties = await probe(destination);
|
|
55
55
|
requireCondition(properties.has_audio && properties.duration_ms > 0, 'TTS_AUDIO', `Invalid generated speech ${segment.id}`, 4);
|
|
56
|
+
const duration_ms = await audioDuration(destination);
|
|
56
57
|
return {
|
|
57
|
-
id: segment.id, audio: destination, sha256: await hashFile(destination), format: 'mp3', duration_ms
|
|
58
|
+
id: segment.id, audio: destination, sha256: await hashFile(destination), format: 'mp3', duration_ms,
|
|
58
59
|
transcript: { original: segment.text, normalized: data.normalized_alignment?.characters.join('') ?? segment.text }, alignment,
|
|
59
60
|
provenance: { adapter: this.id, version: this.version, provider: this.id, voice: voice.voice, options, generated_at: new Date().toISOString() },
|
|
60
61
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { NativePreview } from '../preview/contracts.js';
|
|
2
|
-
export declare function nativePreview(command: (command: string) => Promise<unknown>): NativePreview;
|
|
2
|
+
export declare function nativePreview(command: (command: string, positionMs?: number) => Promise<unknown>): NativePreview;
|
|
@@ -4,13 +4,24 @@ export function nativePreview(command) {
|
|
|
4
4
|
const url = new URL(req.url ?? '/', 'http://localhost');
|
|
5
5
|
const control = url.searchParams.get('command');
|
|
6
6
|
const action = req.method === 'GET' && url.pathname === '/native/frame' ? 'frame'
|
|
7
|
-
: req.method === 'POST' && url.pathname === '/native/control' && ['play', 'pause', 'restart'].includes(control ?? '') ? control : undefined;
|
|
7
|
+
: req.method === 'POST' && url.pathname === '/native/control' && ['play', 'pause', 'restart', 'seek'].includes(control ?? '') ? control : undefined;
|
|
8
8
|
if (!action) {
|
|
9
9
|
res.writeHead(404);
|
|
10
10
|
res.end();
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
let positionMs;
|
|
14
|
+
if (action === 'seek') {
|
|
15
|
+
const raw = url.searchParams.get('position_ms');
|
|
16
|
+
const parsed = raw !== null ? Number(raw) : Number.NaN;
|
|
17
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
18
|
+
res.writeHead(400, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
19
|
+
res.end('Invalid seek position');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
positionMs = parsed;
|
|
23
|
+
}
|
|
24
|
+
const state = await command(action, positionMs);
|
|
14
25
|
res.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'no-store' });
|
|
15
26
|
res.end(JSON.stringify(state));
|
|
16
27
|
},
|