@lincyaw/kernel 1.0.0-rc.29 → 1.0.0-rc.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lincyaw/kernel",
3
- "version": "1.0.0-rc.29",
3
+ "version": "1.0.0-rc.30",
4
4
  "description": "Presmium's shared kernel: the IR and plugin contracts, the service registry, anchors and checks",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -194,8 +194,14 @@ export interface Production {
194
194
  cueTimings?: Record<string, { pauseMs: number }>
195
195
  /** Stale mappings remain inspectable but never retime audio or replace changed narration. */
196
196
  captionTimings?: Record<StepId, CaptionTiming>
197
+ /** How large the captions are, in the presentation and burned into a lecture video; absent is the default size. */
198
+ captions?: CaptionStyle
197
199
  mediaClips: MediaClip[]
198
200
  }
201
+ /** `scale` multiplies the captions' default size, from `CAPTION_SCALE_MIN` to `CAPTION_SCALE_MAX` (Studio offers tenths). */
202
+ export interface CaptionStyle { scale: number }
203
+ export const CAPTION_SCALE_MIN = 0.7
204
+ export const CAPTION_SCALE_MAX = 1.6
199
205
 
200
206
  /** A stable rich-text/code ID, or `page:${sectionId}` reserved for an existing section title. */
201
207
  export interface DocumentTextPoint { blockId: string, offset: number }
@@ -103,6 +103,15 @@ export interface VoiceCloneStatus {
103
103
  message?: string
104
104
  }
105
105
 
106
+ export interface SpeechCachePrune {
107
+ /** Entries some request uses. */
108
+ kept: number
109
+ /** Entries no request uses, with the bytes of their files. */
110
+ unused: { key: string, bytes: number }[]
111
+ /** Whether the unused entries were deleted. */
112
+ removed: boolean
113
+ }
114
+
106
115
  export interface TranscriptionRequest {
107
116
  engine?: string
108
117
  audio: Blob
@@ -124,6 +133,13 @@ export interface SpeechService {
124
133
  cached?(key: string, signal?: AbortSignal): Promise<Synthesis | undefined>
125
134
  alignWords?(key: string, options: { lang: string, transcribe?: boolean }, signal?: AbortSignal): Promise<SpeechWord[] | undefined>
126
135
  pruneLock?(keep: ReadonlySet<string>): Promise<number>
136
+ /**
137
+ * The document's cached audio that no request of `keep` (every sentence the document says) uses: kept is any entry
138
+ * made for the same request under any configuration of the voice service. With `remove`, deletes the unused entries
139
+ * with their alignments and speech lock entries. Throws `speech-prune-engine-unknown` when a request names no engine
140
+ * and no default engine is configured, since its entries cannot be told apart then.
141
+ */
142
+ pruneCache?(keep: readonly SynthesisRequest[], options?: { remove?: boolean, signal?: AbortSignal }): Promise<SpeechCachePrune>
127
143
  transcribe(request: TranscriptionRequest, signal?: AbortSignal): Promise<Transcript>
128
144
  /** Registers the consent, then starts training; only for the document's owner. Absent: the service cannot clone. */
129
145
  cloneVoice?(request: VoiceCloneRequest, signal?: AbortSignal): Promise<VoiceCloneStatus>
@@ -1,9 +1,31 @@
1
1
  import type { CanonicalSource } from '../ir.ts'
2
2
  import type { Member } from './server.ts'
3
- import type { VoiceoverCancellation, VoiceoverJob, VoiceoverRequest, VoiceoverSnapshot, VoicePreviewAnswer, VoicePreviewQuery, VoicePreviewQuote, VoicePreviewRequest } from './voice.ts'
3
+ import type { SpeechVoice, SynthesisRequest } from './speech.ts'
4
+ import type { VoiceoverCancellation, VoiceoverJob, VoiceoverRequest, VoiceoverSnapshot, VoicePreviewAnswer, VoicePreviewQuery, VoicePreviewQuote, VoicePreviewRequest, VoiceTarget } from './voice.ts'
4
5
  import { defineService } from './service.ts'
5
6
 
6
7
  export interface VoiceoverStatusQuery { source?: CanonicalSource, revision?: string }
8
+ export interface VoiceoverSentencesQuery extends VoiceoverStatusQuery {
9
+ /** Answer as if this were the document's default voice: sentences that inherit the default, or have no voice, use it. */
10
+ defaultVoice?: SpeechVoice
11
+ }
12
+ /** One sentence that a document-scope generation processes, in reading order. */
13
+ export interface VoiceoverSentence {
14
+ section: string
15
+ step: number
16
+ stepId?: string
17
+ /** The step binding for a `steps` scope; absent when the sentence cannot be generated by step (it crosses steps). */
18
+ target?: VoiceTarget
19
+ /** The spoken text, which the voice service receives (and a cloud provider charges for). */
20
+ text: string
21
+ /** The exact synthesis request; absent when the sentence has no usable voice. */
22
+ request?: SynthesisRequest
23
+ /** Exact audio for the request is in the speech cache. */
24
+ cached: boolean
25
+ /** Why it cannot be generated now: no voice, or the voice service or voice is unavailable. */
26
+ reason?: string
27
+ }
28
+ export interface VoiceoverSentences { source: CanonicalSource, revision: string, sentences: VoiceoverSentence[] }
7
29
  export type VoiceoverStart = Omit<VoiceoverRequest, 'confirmed'>
8
30
  export type VoicePreviewStart = Omit<VoicePreviewRequest, 'confirmed'>
9
31
  export type VoicePreviewCheck = VoicePreviewQuery & { source?: CanonicalSource }
@@ -23,6 +45,8 @@ export interface VoicePreviewMedia extends Omit<VoicePreviewAnswer, 'audio'> { b
23
45
  /** Stateless plugin execution. The host owns intents and jobs; discovery creates neither. */
24
46
  export interface VoiceoverExecution {
25
47
  status(query: VoiceoverStatusQuery, signal: AbortSignal): Promise<Omit<VoiceoverSnapshot, 'jobs'>>
48
+ /** Every sentence with its request and cache state; reads the cache and the voice catalog, never generates. */
49
+ sentences?(query: VoiceoverSentencesQuery, signal: AbortSignal): Promise<VoiceoverSentences>
26
50
  prepare(request: VoiceoverStart, signal: AbortSignal): Promise<PreparedVoiceover>
27
51
  quote(query: VoicePreviewCheck, signal: AbortSignal): Promise<VoicePreviewQuote>
28
52
  preview(request: VoicePreviewStart, signal: AbortSignal): Promise<VoicePreviewMedia>
@@ -0,0 +1,17 @@
1
+ import { CAPTION_SCALE_MAX, CAPTION_SCALE_MIN } from './contracts/document.ts'
2
+ import type { Production, TeachingDocument } from './contracts/document.ts'
3
+
4
+ /** The caption size a document sets (`production.captions.scale`); 1 when it sets none or one out of range. */
5
+ export function captionScale(production: Pick<Production, 'captions'> | undefined): number {
6
+ const scale = production?.captions?.scale
7
+ return typeof scale === 'number' && scale >= CAPTION_SCALE_MIN && scale <= CAPTION_SCALE_MAX ? scale : 1
8
+ }
9
+
10
+ /** Sets the caption size, kept in range and rounded to a tenth; the default size 1 removes the setting. */
11
+ export function changeDocumentCaptionScale(document: TeachingDocument, scale: number): TeachingDocument {
12
+ if (!Number.isFinite(scale)) throw new Error('document-caption-scale')
13
+ const value = Math.round(Math.min(CAPTION_SCALE_MAX, Math.max(CAPTION_SCALE_MIN, scale)) * 10) / 10
14
+ if (value === captionScale(document.production)) return document
15
+ const { captions: _captions, ...production } = document.production
16
+ return { ...document, production: value === 1 ? production : { ...production, captions: { scale: value } } }
17
+ }
@@ -1,5 +1,5 @@
1
1
  import type { Schema } from '@cfworker/json-schema'
2
- import { ASSET_TITLE_MAX_LENGTH, DOCUMENT_SCHEMA_VERSION } from './contracts/document.ts'
2
+ import { ASSET_TITLE_MAX_LENGTH, CAPTION_SCALE_MAX, CAPTION_SCALE_MIN, DOCUMENT_SCHEMA_VERSION } from './contracts/document.ts'
3
3
 
4
4
  const ref = (name: string): Schema => ({ $ref: `#/$defs/${name}` })
5
5
  const string: Schema = { type: 'string' }
@@ -77,7 +77,7 @@ export const DOCUMENT_JSON_SCHEMA: Schema = {
77
77
  StepProduction: object({ narrationStart: { enum: ['with-animation', 'after-animation'] }, minimumHoldMs: nonnegative, trailingPauseMs: nonnegative, voiceSource: ref('VoiceSource') }, []),
78
78
  MediaClip: object({ id, assetId: id, sourceRange: object({ startMs: nonnegative, endMs: nonnegative }), attachment: object({ stepId: id, offsetMs: nonnegative }), volume: { type: 'number', minimum: 0, maximum: 1 }, muted: { type: 'boolean' } }, ['id', 'assetId', 'sourceRange', 'attachment', 'volume']),
79
79
  CaptionTiming: object({ narrationIds: ids, sourceFingerprint: { type: 'string', pattern: '^[a-f0-9]{16}$' }, playbackFingerprint: { type: 'string', pattern: '^[a-f0-9]{16}$' }, durationMs: { type: 'integer', minimum: 1 }, segments: { type: 'array', minItems: 1, maxItems: 32, items: object({ id, from: integer, to: integer, startMs: integer, endMs: integer }) } }),
80
- Production: object({ defaults: ref('StepProduction'), sectionOverrides: record(ref('StepProduction')), stepOverrides: record(ref('StepProduction')), narrationOverrides: record(object({ narrationStart: { enum: ['with-animation', 'after-animation'] } })), cueTimings: record(object({ pauseMs: nonnegative })), captionTimings: record(ref('CaptionTiming')), mediaClips: list(ref('MediaClip')) }, ['defaults', 'stepOverrides', 'mediaClips']),
80
+ Production: object({ defaults: ref('StepProduction'), sectionOverrides: record(ref('StepProduction')), stepOverrides: record(ref('StepProduction')), narrationOverrides: record(object({ narrationStart: { enum: ['with-animation', 'after-animation'] } })), cueTimings: record(object({ pauseMs: nonnegative })), captionTimings: record(ref('CaptionTiming')), captions: object({ scale: { type: 'number', minimum: CAPTION_SCALE_MIN, maximum: CAPTION_SCALE_MAX } }), mediaClips: list(ref('MediaClip')) }, ['defaults', 'stepOverrides', 'mediaClips']),
81
81
  TextPoint: object({ blockId: { type: 'string', minLength: 1, maxLength: 205 }, offset: integer }),
82
82
  Comment: object({ id, type: tag('comment'), userId: id, createdAt: string, updatedAt: string, deletedAt: string, content: list(ref('RichTextNode')), metadata: ref('JsonObject'), reactions: list(object({ emoji: string, createdAt: string, userIds: ids })) }, ['id', 'type', 'userId', 'createdAt', 'updatedAt', 'reactions']),
83
83
  Thread: object({ id, type: tag('thread'), createdAt: string, updatedAt: string, resolved: { type: 'boolean' }, resolvedUpdatedAt: string, resolvedBy: id, metadata: ref('JsonObject'), deletedAt: string, anchor: { oneOf: [object({ from: ref('TextPoint'), to: ref('TextPoint') }), object({ blockId: id, stepId: id }, ['blockId'])] }, comments: list(ref('Comment')) }, ['id', 'type', 'createdAt', 'updatedAt', 'resolved', 'comments']),
package/src/index.ts CHANGED
@@ -34,6 +34,7 @@ export { hostName, localRequestRefusal } from './requests.ts'
34
34
  export type { RequestHeaders } from './requests.ts'
35
35
  export { fingerprint, fnv1a64 } from './fingerprint.ts'
36
36
  export { applyDocumentCaptionTiming, captionSourceFingerprint, captionTimingProblem, stepCaptionText, narrationCaptionText, CAPTION_TIMING_MAX_SEGMENTS, DocumentCaptionTimingError } from './document-caption-timings.ts'
37
+ export { captionScale, changeDocumentCaptionScale } from './document-caption-scale.ts'
37
38
  export type { DocumentCaptionTimingAction } from './document-caption-timings.ts'
38
39
  export { backSection, followedPlace } from './follow.ts'
39
40
  export type { FollowAnchor } from './follow.ts'