@morshoto/framekit 0.2.2 → 0.2.4
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/dist-package/adapters/final-cut/typescript/src/analyzers.d.ts +58 -0
- package/dist-package/adapters/final-cut/typescript/src/analyzers.js +52 -13
- package/dist-package/adapters/final-cut/typescript/src/assets.d.ts +24 -0
- package/dist-package/adapters/final-cut/typescript/src/background-export.d.ts +98 -0
- package/dist-package/adapters/final-cut/typescript/src/background-materialization.d.ts +47 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical-recovery-guard.d.ts +32 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical-recovery.d.ts +22 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical-verification.d.ts +11 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical.d.ts +184 -0
- package/dist-package/adapters/final-cut/typescript/src/canonical.js +33 -1
- package/dist-package/adapters/final-cut/typescript/src/connection.d.ts +103 -0
- package/dist-package/adapters/final-cut/typescript/src/disposable-native.d.ts +90 -0
- package/dist-package/adapters/final-cut/typescript/src/documents.d.ts +3 -0
- package/dist-package/adapters/final-cut/typescript/src/documents.js +3 -0
- package/dist-package/adapters/final-cut/typescript/src/experimental.d.ts +8 -0
- package/dist-package/adapters/final-cut/typescript/src/export.d.ts +125 -0
- package/dist-package/adapters/final-cut/typescript/src/fcpxml-console-experiment.d.ts +54 -0
- package/dist-package/adapters/final-cut/typescript/src/fcpxml.d.ts +75 -0
- package/dist-package/adapters/final-cut/typescript/src/fcpxml.js +6 -1
- package/dist-package/adapters/final-cut/typescript/src/index.d.ts +22 -0
- package/dist-package/adapters/final-cut/typescript/src/library-inspection.d.ts +101 -0
- package/dist-package/adapters/final-cut/typescript/src/live.d.ts +101 -0
- package/dist-package/adapters/final-cut/typescript/src/live.js +8 -0
- package/dist-package/adapters/final-cut/typescript/src/media.d.ts +12 -0
- package/dist-package/adapters/final-cut/typescript/src/native-operation.d.ts +6 -0
- package/dist-package/adapters/final-cut/typescript/src/native-recovery-inspection.d.ts +77 -0
- package/dist-package/adapters/final-cut/typescript/src/native-session.d.ts +130 -0
- package/dist-package/adapters/final-cut/typescript/src/native.d.ts +828 -0
- package/dist-package/adapters/final-cut/typescript/src/native.js +274 -107
- package/dist-package/adapters/final-cut/typescript/src/pasteboard-snapshot.d.ts +114 -0
- package/dist-package/adapters/final-cut/typescript/src/publish-readback.d.ts +26 -0
- package/dist-package/adapters/final-cut/typescript/src/publish-readback.js +18 -2
- package/dist-package/adapters/final-cut/typescript/src/publisher.d.ts +215 -0
- package/dist-package/adapters/final-cut/typescript/src/session.d.ts +43 -0
- package/dist-package/adapters/final-cut/typescript/src/shadow-mutation.d.ts +51 -0
- package/dist-package/adapters/final-cut/typescript/src/sqlite-experiment.d.ts +156 -0
- package/dist-package/adapters/final-cut/typescript/src/sqlite-inspection.d.ts +134 -0
- package/dist-package/adapters/final-cut/typescript/src/sqlite-materialization.d.ts +110 -0
- package/dist-package/adapters/final-cut/typescript/src/sqlite-wal-observation.d.ts +132 -0
- package/dist-package/adapters/final-cut/typescript/src/timeline-ir-fcpxml.d.ts +61 -0
- package/dist-package/adapters/final-cut/typescript/src/timeline-ir-fcpxml.js +28 -4
- package/dist-package/adapters/final-cut/typescript/src/unattended-editing.d.ts +54 -0
- package/dist-package/adapters/headless/typescript/src/audio-output.d.ts +3 -0
- package/dist-package/adapters/headless/typescript/src/ffmpeg-media-probe.d.ts +11 -0
- package/dist-package/adapters/headless/typescript/src/ffmpeg-media-probe.js +26 -2
- package/dist-package/adapters/headless/typescript/src/ffmpeg-renderer.d.ts +27 -0
- package/dist-package/adapters/headless/typescript/src/ffmpeg-renderer.js +7 -2
- package/dist-package/adapters/headless/typescript/src/ffmpeg-storyboard.d.ts +28 -0
- package/dist-package/adapters/headless/typescript/src/ffmpeg-storyboard.js +120 -0
- package/dist-package/adapters/headless/typescript/src/ffmpeg-verifier.d.ts +15 -0
- package/dist-package/adapters/headless/typescript/src/index.d.ts +4 -0
- package/dist-package/adapters/headless/typescript/src/index.js +1 -0
- package/dist-package/apps/cli/src/dev-doctor.d.ts +25 -0
- package/dist-package/apps/cli/src/headless-projects.d.ts +3 -0
- package/dist-package/apps/cli/src/main.d.ts +10 -0
- package/dist-package/apps/mcp-server/runtime/ffmpeg-audio-backend.py +129 -0
- package/dist-package/apps/mcp-server/runtime/whisper-speech-backend.py +92 -2
- package/dist-package/apps/mcp-server/src/build-alignment.d.ts +10 -0
- package/dist-package/apps/mcp-server/src/build-identity.d.ts +7 -0
- package/dist-package/apps/mcp-server/src/build-identity.json +2 -2
- package/dist-package/apps/mcp-server/src/canonical-native-snapshot.d.ts +8 -0
- package/dist-package/apps/mcp-server/src/final-cut-runtime-config.d.ts +5 -0
- package/dist-package/apps/mcp-server/src/headless-project-snapshot.d.ts +3 -0
- package/dist-package/apps/mcp-server/src/headless-sessions.d.ts +89 -0
- package/dist-package/apps/mcp-server/src/main.d.ts +1 -0
- package/dist-package/apps/mcp-server/src/main.js +2 -1
- package/dist-package/apps/mcp-server/src/materialization-jobs.d.ts +204 -0
- package/dist-package/apps/mcp-server/src/readback-policy.d.ts +18 -0
- package/dist-package/apps/mcp-server/src/routing.d.ts +90 -0
- package/dist-package/apps/mcp-server/src/server.d.ts +75 -0
- package/dist-package/apps/mcp-server/src/server.js +93 -9
- package/dist-package/apps/mcp-server/src/tools/skills/catalog.d.ts +19 -0
- package/dist-package/apps/mcp-server/src/tools/skills/metadata.d.ts +37 -0
- package/dist-package/apps/mcp-server/src/tools/skills/register.d.ts +11 -0
- package/dist-package/apps/mcp-server/src/version.d.ts +4 -0
- package/dist-package/packages/headless-application/src/external-edit.d.ts +30 -0
- package/dist-package/packages/headless-application/src/external-edit.js +72 -0
- package/dist-package/packages/headless-application/src/headless-projects.d.ts +259 -0
- package/dist-package/packages/headless-application/src/headless-projects.js +15 -2
- package/dist-package/packages/headless-application/src/index.d.ts +2 -0
- package/dist-package/packages/headless-application/src/index.js +1 -0
- package/dist-package/packages/runtime/src/application/duration-policy-service.d.ts +4 -0
- package/dist-package/packages/runtime/src/application/local-media.d.ts +46 -0
- package/dist-package/packages/runtime/src/application/media-analysis-service.d.ts +40 -0
- package/dist-package/packages/runtime/src/application/media-analysis-service.js +105 -15
- package/dist-package/packages/runtime/src/application/project-service.d.ts +35 -0
- package/dist-package/packages/runtime/src/application/project-store.d.ts +56 -0
- package/dist-package/packages/runtime/src/application/project-transactions.d.ts +51 -0
- package/dist-package/packages/runtime/src/application/runtime-options.d.ts +15 -0
- package/dist-package/packages/runtime/src/application/semantic-media-index-store.d.ts +28 -0
- package/dist-package/packages/runtime/src/application/transaction-store.d.ts +10 -0
- package/dist-package/packages/runtime/src/audio/analysis.d.ts +3 -0
- package/dist-package/packages/runtime/src/audio/analysis.js +95 -0
- package/dist-package/packages/runtime/src/audio/dialogue-normalization.d.ts +47 -0
- package/dist-package/packages/runtime/src/audio/noise-reduction.d.ts +34 -0
- package/dist-package/packages/runtime/src/capabilities.d.ts +45 -0
- package/dist-package/packages/runtime/src/color-correction.d.ts +33 -0
- package/dist-package/packages/runtime/src/context/context-engine.d.ts +28 -0
- package/dist-package/packages/runtime/src/context/context-service.d.ts +20 -0
- package/dist-package/packages/runtime/src/context/project-catalog.d.ts +12 -0
- package/dist-package/packages/runtime/src/context/revision.d.ts +2 -0
- package/dist-package/packages/runtime/src/domain/capabilities.d.ts +170 -0
- package/dist-package/packages/runtime/src/domain/context.d.ts +179 -0
- package/dist-package/packages/runtime/src/domain/diff.d.ts +104 -0
- package/dist-package/packages/runtime/src/domain/duration.d.ts +63 -0
- package/dist-package/packages/runtime/src/domain/editing.d.ts +227 -0
- package/dist-package/packages/runtime/src/domain/incremental-sync.d.ts +67 -0
- package/dist-package/packages/runtime/src/domain/index.d.ts +14 -0
- package/dist-package/packages/runtime/src/domain/media.d.ts +406 -0
- package/dist-package/packages/runtime/src/domain/ports.d.ts +62 -0
- package/dist-package/packages/runtime/src/domain/primitives.d.ts +21 -0
- package/dist-package/packages/runtime/src/domain/project.d.ts +119 -0
- package/dist-package/packages/runtime/src/domain/rough-cut.d.ts +27 -0
- package/dist-package/packages/runtime/src/domain/skills.d.ts +145 -0
- package/dist-package/packages/runtime/src/domain/timeline-target.d.ts +57 -0
- package/dist-package/packages/runtime/src/domain/timeline-target.js +19 -1
- package/dist-package/packages/runtime/src/domain/types.d.ts +5 -0
- package/dist-package/packages/runtime/src/domain/verification.d.ts +92 -0
- package/dist-package/packages/runtime/src/editing/dialogue-normalization-service.d.ts +18 -0
- package/dist-package/packages/runtime/src/editing/duration-policy.d.ts +3 -0
- package/dist-package/packages/runtime/src/editing/edit-service.d.ts +44 -0
- package/dist-package/packages/runtime/src/editing/filler-removal-service.d.ts +23 -0
- package/dist-package/packages/runtime/src/editing/intent.d.ts +97 -0
- package/dist-package/packages/runtime/src/editing/music-service.d.ts +9 -0
- package/dist-package/packages/runtime/src/index.d.ts +32 -0
- package/dist-package/packages/runtime/src/index.js +1 -0
- package/dist-package/packages/runtime/src/planning/rough-cut.d.ts +3 -0
- package/dist-package/packages/runtime/src/render/render-and-verify.d.ts +71 -0
- package/dist-package/packages/runtime/src/render/render-contract.d.ts +96 -0
- package/dist-package/packages/runtime/src/runtime.d.ts +85 -0
- package/dist-package/packages/runtime/src/skills/builtin.d.ts +2 -0
- package/dist-package/packages/runtime/src/skills/index.d.ts +3 -0
- package/dist-package/packages/runtime/src/skills/registry.d.ts +10 -0
- package/dist-package/packages/runtime/src/skills/requirements.d.ts +38 -0
- package/dist-package/packages/runtime/src/skills/runtime.d.ts +38 -0
- package/dist-package/packages/runtime/src/speech/analysis.d.ts +18 -0
- package/dist-package/packages/runtime/src/speech/analysis.js +67 -0
- package/dist-package/packages/runtime/src/speech/filler-detector.d.ts +49 -0
- package/dist-package/packages/runtime/src/speech/filler-removal.d.ts +37 -0
- package/dist-package/packages/runtime/src/speech/mapping.d.ts +56 -0
- package/dist-package/packages/runtime/src/speech/mapping.js +27 -4
- package/dist-package/packages/runtime/src/speech/safe-cut-resolver.d.ts +52 -0
- package/dist-package/packages/runtime/src/timeline/drift-reconciliation.d.ts +42 -0
- package/dist-package/packages/runtime/src/timeline/editing-session.d.ts +271 -0
- package/dist-package/packages/runtime/src/timeline/editing-session.js +32 -2
- package/dist-package/packages/runtime/src/timeline/fast-observation.d.ts +77 -0
- package/dist-package/packages/runtime/src/timeline/rational-time.d.ts +11 -0
- package/dist-package/packages/runtime/src/timeline/reorder-preview.d.ts +32 -0
- package/dist-package/packages/runtime/src/timeline/reorder-preview.js +202 -0
- package/dist-package/packages/runtime/src/timeline/snapshot-diff.d.ts +3 -0
- package/dist-package/packages/runtime/src/timeline/snapshot-diff.js +1 -0
- package/dist-package/packages/runtime/src/timeline/snapshot-digest.d.ts +3 -0
- package/dist-package/packages/runtime/src/timeline/snapshot-digest.js +1 -1
- package/dist-package/packages/runtime/src/verification/verification.d.ts +6 -0
- package/dist-package/packages/testkit/src/fixture-analyzers.d.ts +37 -0
- package/dist-package/packages/testkit/src/in-memory-editor.d.ts +55 -0
- package/dist-package/packages/testkit/src/index.d.ts +4 -0
- package/dist-package/packages/testkit/src/sender-lifecycle-fixture.d.ts +47 -0
- package/dist-package/packages/testkit/src/skill-fixtures.d.ts +3 -0
- package/package.json +17 -12
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { sameMediaSourceIdentity } from "../domain/media.js";
|
|
2
2
|
import { planRoughCut } from "../planning/rough-cut.js";
|
|
3
3
|
import { bindSpeechAnalysis } from "../speech/analysis.js";
|
|
4
|
+
import { validateAudioAnalysisPayload, validateAudioAnalysisRange } from "../audio/analysis.js";
|
|
4
5
|
import { parseRational } from "../timeline/rational-time.js";
|
|
5
6
|
export class MediaAnalysisService {
|
|
6
7
|
project;
|
|
@@ -43,15 +44,17 @@ export class MediaAnalysisService {
|
|
|
43
44
|
throw new Error(`TARGET_MISMATCH: occurrence ${occurrenceId} does not reference media ${mediaId}`);
|
|
44
45
|
}
|
|
45
46
|
const media = findMedia(project, mediaId);
|
|
46
|
-
const sourceStart = clip.sourceStart ?? 0;
|
|
47
|
-
const
|
|
48
|
-
const
|
|
47
|
+
const sourceStart = clip.sourceStartTime ? rationalSeconds(clip.sourceStartTime) : clip.sourceStart ?? 0;
|
|
48
|
+
const duration = clip.durationTime ? rationalSeconds(clip.durationTime) : clip.duration;
|
|
49
|
+
const requestedRange = { start: sourceStart, end: sourceStart + duration };
|
|
50
|
+
const analysis = await this.analyzeAudioForProject(project, media, requestedRange, occurrenceId);
|
|
49
51
|
const measuredRange = analysis.measuredRange ?? requestedRange;
|
|
50
52
|
const analyzedDurationSeconds = analysis.analyzedDurationSeconds ?? measuredRange.end - measuredRange.start;
|
|
51
53
|
if (Math.abs(analyzedDurationSeconds - (measuredRange.end - measuredRange.start)) > 0.000001) {
|
|
52
54
|
throw new Error("ANALYSIS_INVALID: audio measured duration does not match its measured range");
|
|
53
55
|
}
|
|
54
|
-
const
|
|
56
|
+
const signalScope = analysis.signalScope ?? "source";
|
|
57
|
+
const valid = signalScope === "occurrence" && analysis.valid !== false
|
|
55
58
|
&& Number.isFinite(analysis.integratedLufs)
|
|
56
59
|
&& Number.isFinite(analysis.truePeakDb)
|
|
57
60
|
&& Number.isFinite(analysis.silenceMs)
|
|
@@ -60,6 +63,10 @@ export class MediaAnalysisService {
|
|
|
60
63
|
return {
|
|
61
64
|
mediaId,
|
|
62
65
|
occurrenceId,
|
|
66
|
+
signalScope,
|
|
67
|
+
sourceIdentity: sourceIdentityOf(media),
|
|
68
|
+
...(analysis.sourceTimebase ? { sourceTimebase: structuredClone(analysis.sourceTimebase) } : {}),
|
|
69
|
+
...(analysis.signalFormat ? { signalFormat: structuredClone(analysis.signalFormat) } : {}),
|
|
63
70
|
requestedRange,
|
|
64
71
|
measuredRange,
|
|
65
72
|
revision: project.revision,
|
|
@@ -71,7 +78,9 @@ export class MediaAnalysisService {
|
|
|
71
78
|
silenceMs: analysis.silenceMs,
|
|
72
79
|
analyzedDurationSeconds,
|
|
73
80
|
valid,
|
|
74
|
-
...(
|
|
81
|
+
...(signalScope === "source"
|
|
82
|
+
? { invalidReason: "OCCURRENCE_SIGNAL_UNAVAILABLE" }
|
|
83
|
+
: analysis.invalidReason ? { invalidReason: analysis.invalidReason } : {}),
|
|
75
84
|
};
|
|
76
85
|
}
|
|
77
86
|
async measureNoise(mediaId, occurrenceId) {
|
|
@@ -134,7 +143,15 @@ export class MediaAnalysisService {
|
|
|
134
143
|
const input = { project, media };
|
|
135
144
|
const [speechResult, audioResult, noiseResult, visualResult, metadataResult] = await Promise.all([
|
|
136
145
|
settle(() => this.options.speechAnalyzer ? this.analyzeSpeechForProject(project, media) : undefined),
|
|
137
|
-
settle(() =>
|
|
146
|
+
settle(async () => {
|
|
147
|
+
if (!this.options.audioAnalyzer)
|
|
148
|
+
return undefined;
|
|
149
|
+
const result = await this.analyzeAudioForProject(project, media);
|
|
150
|
+
if (result.valid === false) {
|
|
151
|
+
throw new Error(`ANALYSIS_INVALID: ${result.invalidReason?.trim() || "audio provider rejected the measurement"}`);
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}),
|
|
138
155
|
settle(() => this.options.noiseAnalyzer?.analyze(input)),
|
|
139
156
|
settle(() => this.options.visualAnalyzer?.analyze(input)),
|
|
140
157
|
settle(() => this.options.metadataAnalyzer?.analyze(input)),
|
|
@@ -390,19 +407,21 @@ export class MediaAnalysisService {
|
|
|
390
407
|
provider: analyzer.descriptor,
|
|
391
408
|
});
|
|
392
409
|
}
|
|
393
|
-
async analyzeAudioForProject(project, media, range) {
|
|
410
|
+
async analyzeAudioForProject(project, media, range, occurrenceId) {
|
|
394
411
|
const analyzer = this.options.audioAnalyzer;
|
|
395
412
|
if (!analyzer)
|
|
396
413
|
throw new Error("CAPABILITY_UNAVAILABLE: audio analysis");
|
|
397
414
|
const requestedRange = range ?? (media.duration === undefined ? undefined : { start: 0, end: media.duration });
|
|
398
415
|
validateRequestedAudioRange(requestedRange, media.duration, "requested audio range");
|
|
399
|
-
const analysis = await analyzer.analyze({ project, media }, requestedRange);
|
|
416
|
+
const analysis = await analyzer.analyze({ project, media, ...(occurrenceId ? { occurrenceId } : {}) }, requestedRange);
|
|
417
|
+
validateAudioAnalysisPayload(analysis);
|
|
400
418
|
validateAudioProvenance(analysis, {
|
|
401
419
|
media,
|
|
402
420
|
mediaId: media.mediaId,
|
|
403
421
|
project,
|
|
404
422
|
provider: analyzer.descriptor,
|
|
405
423
|
requestedRange,
|
|
424
|
+
occurrenceId,
|
|
406
425
|
});
|
|
407
426
|
const measuredRange = analysis.measuredRange ?? (requestedRange ? structuredClone(requestedRange) : undefined);
|
|
408
427
|
if (measuredRange && requestedRange)
|
|
@@ -418,6 +437,7 @@ export class MediaAnalysisService {
|
|
|
418
437
|
}
|
|
419
438
|
return {
|
|
420
439
|
...structuredClone(analysis),
|
|
440
|
+
signalScope: analysis.signalScope ?? "source",
|
|
421
441
|
schemaVersion: 1,
|
|
422
442
|
mediaId: media.mediaId,
|
|
423
443
|
sourceIdentity: sourceIdentityOf(media),
|
|
@@ -442,6 +462,12 @@ function mergeSpeechAnalyses(previous, analyses, updatedRanges, context) {
|
|
|
442
462
|
const latest = analyses[analyses.length - 1];
|
|
443
463
|
if (!latest)
|
|
444
464
|
throw new Error("ANALYSIS_INVALID: speech reanalysis returned no results");
|
|
465
|
+
if (analyses.some((analysis) => !sameDescriptor(analysis.provider, latest.provider))) {
|
|
466
|
+
throw new Error("ANALYSIS_INVALID: speech evidence providers cannot be combined");
|
|
467
|
+
}
|
|
468
|
+
if (analyses.some((analysis) => !sameRational(analysis.sourceTimebase, latest.sourceTimebase))) {
|
|
469
|
+
throw new Error("ANALYSIS_INVALID: speech evidence timebases cannot be combined");
|
|
470
|
+
}
|
|
445
471
|
if (previous?.provider && !sameDescriptor(previous.provider, latest.provider)) {
|
|
446
472
|
throw new Error("ANALYSIS_INVALID: speech evidence providers cannot be combined");
|
|
447
473
|
}
|
|
@@ -452,14 +478,28 @@ function mergeSpeechAnalyses(previous, analyses, updatedRanges, context) {
|
|
|
452
478
|
...(previous?.requestedRange ? [previous.requestedRange] : []),
|
|
453
479
|
...analyses.map((analysis) => analysis.requestedRange),
|
|
454
480
|
]);
|
|
455
|
-
const
|
|
456
|
-
...(previous?.observedRange ?
|
|
481
|
+
const observedRanges = mergeRanges([
|
|
482
|
+
...(previous?.observedRange ? subtractObservedRanges(previous.observedRange, updatedRanges) : []),
|
|
457
483
|
...analyses.map((analysis) => analysis.observedRange),
|
|
458
484
|
]);
|
|
485
|
+
if (observedRanges.length !== 1) {
|
|
486
|
+
throw new Error("ANALYSIS_INVALID: speech observation coverage has gaps");
|
|
487
|
+
}
|
|
488
|
+
const observedRange = observedRanges[0];
|
|
459
489
|
const words = mergeSpeechEvidence(previous?.words, analyses.map((analysis) => analysis.words), updatedRanges);
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
|
|
490
|
+
const vadCoverage = [
|
|
491
|
+
...speechVadCoverage(previous).flatMap((span) => subtractVadCoverage(span, updatedRanges)),
|
|
492
|
+
...analyses.flatMap((analysis) => speechVadCoverage(analysis)),
|
|
493
|
+
].sort((left, right) => left.start - right.start || left.end - right.end);
|
|
494
|
+
let vadCursor = observedRange.start;
|
|
495
|
+
const completeVad = vadCoverage.length > 0 && vadCoverage.every((span) => {
|
|
496
|
+
if (span.status !== "available" || span.start !== vadCursor)
|
|
497
|
+
return false;
|
|
498
|
+
vadCursor = span.end;
|
|
499
|
+
return true;
|
|
500
|
+
}) && vadCursor === observedRange.end;
|
|
501
|
+
const vadSegments = completeVad
|
|
502
|
+
? vadCoverage.flatMap((span) => span.status === "available" ? span.segments : [])
|
|
463
503
|
: undefined;
|
|
464
504
|
const hasSilence = previous?.silenceSegments !== undefined || analyses.some((analysis) => analysis.silenceSegments !== undefined);
|
|
465
505
|
const silenceSegments = hasSilence
|
|
@@ -469,17 +509,59 @@ function mergeSpeechAnalyses(previous, analyses, updatedRanges, context) {
|
|
|
469
509
|
const protectedSegments = hasProtected
|
|
470
510
|
? mergeSpeechEvidence(previous?.protectedSegments, analyses.map((analysis) => analysis.protectedSegments ?? []), updatedRanges)
|
|
471
511
|
: undefined;
|
|
512
|
+
const { vadSegments: _segments, vadUnavailableReason: _reason, vadCoverage: _coverage, capability: _capability, ...latestWithoutVad } = latest;
|
|
472
513
|
return bindSpeechAnalysis({
|
|
473
|
-
...
|
|
514
|
+
...latestWithoutVad,
|
|
474
515
|
requestedRange,
|
|
475
516
|
observedRange,
|
|
476
|
-
capability:
|
|
517
|
+
capability: completeVad ? "transcription-plus-vad" : "transcription-only",
|
|
477
518
|
words,
|
|
478
519
|
...(vadSegments ? { vadSegments } : {}),
|
|
520
|
+
...(vadCoverage.length ? { vadCoverage } : {}),
|
|
521
|
+
...(!completeVad ? { vadUnavailableReason: "VAD_INCOMPLETE_COVERAGE" } : {}),
|
|
479
522
|
...(silenceSegments ? { silenceSegments } : {}),
|
|
480
523
|
...(protectedSegments ? { protectedSegments } : {}),
|
|
481
524
|
}, context);
|
|
482
525
|
}
|
|
526
|
+
function speechVadCoverage(analysis) {
|
|
527
|
+
if (!analysis)
|
|
528
|
+
return [];
|
|
529
|
+
if (analysis.vadCoverage !== undefined)
|
|
530
|
+
return structuredClone(analysis.vadCoverage);
|
|
531
|
+
if (!analysis.observedRange) {
|
|
532
|
+
if (analysis.vadSegments !== undefined || analysis.vadUnavailableReason !== undefined) {
|
|
533
|
+
throw new Error("ANALYSIS_INVALID: cannot combine VAD without an observed range");
|
|
534
|
+
}
|
|
535
|
+
return [];
|
|
536
|
+
}
|
|
537
|
+
const { start, end } = analysis.observedRange;
|
|
538
|
+
return analysis.vadSegments !== undefined
|
|
539
|
+
? [{ start, end, status: "available", segments: structuredClone(analysis.vadSegments) }]
|
|
540
|
+
: [{ start, end, status: "unavailable", reason: analysis.vadUnavailableReason ?? "VAD_NOT_REPORTED" }];
|
|
541
|
+
}
|
|
542
|
+
function subtractObservedRanges(observed, updatedRanges) {
|
|
543
|
+
let ranges = [{ start: observed.start, end: observed.end }];
|
|
544
|
+
for (const update of updatedRanges) {
|
|
545
|
+
ranges = ranges.flatMap((range) => {
|
|
546
|
+
if (!rangesOverlap(range, update))
|
|
547
|
+
return [range];
|
|
548
|
+
return [
|
|
549
|
+
...(range.start < update.start ? [{ start: range.start, end: Math.min(range.end, update.start) }] : []),
|
|
550
|
+
...(range.end > update.end ? [{ start: Math.max(range.start, update.end), end: range.end }] : []),
|
|
551
|
+
];
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
return ranges;
|
|
555
|
+
}
|
|
556
|
+
function subtractVadCoverage(span, updatedRanges) {
|
|
557
|
+
const ranges = subtractObservedRanges(span, updatedRanges);
|
|
558
|
+
return ranges.map((range) => span.status === "unavailable"
|
|
559
|
+
? { ...range, status: "unavailable", reason: span.reason }
|
|
560
|
+
: { ...range, status: "available", segments: span.segments.flatMap((segment) => {
|
|
561
|
+
const start = Math.max(segment.start, range.start), end = Math.min(segment.end, range.end);
|
|
562
|
+
return start < end ? [{ ...segment, start, end }] : [];
|
|
563
|
+
}) });
|
|
564
|
+
}
|
|
483
565
|
function mergeSpeechEvidence(previous, fresh, updatedRanges) {
|
|
484
566
|
return [
|
|
485
567
|
...(previous ?? []).filter((evidence) => !updatedRanges.some((range) => rangesOverlap(evidence, range))),
|
|
@@ -801,6 +883,13 @@ function findMedia(project, mediaId) {
|
|
|
801
883
|
return media;
|
|
802
884
|
}
|
|
803
885
|
function validateAudioProvenance(analysis, expected) {
|
|
886
|
+
if (analysis.signalScope !== undefined && analysis.signalScope !== "source" && analysis.signalScope !== "occurrence") {
|
|
887
|
+
throw new Error("ANALYSIS_INVALID: unsupported audio signal scope");
|
|
888
|
+
}
|
|
889
|
+
if (analysis.signalScope === "occurrence"
|
|
890
|
+
&& (!expected.occurrenceId || analysis.occurrenceId !== expected.occurrenceId)) {
|
|
891
|
+
throw new Error("TARGET_MISMATCH: audio occurrence signal does not match the requested occurrence");
|
|
892
|
+
}
|
|
804
893
|
if (analysis.schemaVersion !== undefined && analysis.schemaVersion !== 1) {
|
|
805
894
|
throw new Error("ANALYSIS_INVALID: unsupported audio analysis schema version");
|
|
806
895
|
}
|
|
@@ -838,6 +927,7 @@ function validateRequestedAudioRange(range, duration, label) {
|
|
|
838
927
|
|| (duration !== undefined && range.end > duration)) {
|
|
839
928
|
throw new Error(`ANALYSIS_INVALID: ${label} must be finite, positive, and inside the source duration`);
|
|
840
929
|
}
|
|
930
|
+
validateAudioAnalysisRange(range, label);
|
|
841
931
|
}
|
|
842
932
|
function sameContextRevision(left, right) {
|
|
843
933
|
return left.id === right.id && left.sequence === right.sequence && left.timestamp === right.timestamp;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ContextEngine } from "../context/context-engine.js";
|
|
2
|
+
import type { AssetSearchQuery, EditorAsset, EditorPort, ManagedArtifact } from "../domain/ports.js";
|
|
3
|
+
import type { MediaContext } from "../domain/media.js";
|
|
4
|
+
import type { ProjectCatalog, ProjectSelection, ProjectSelectionResult } from "../domain/context.js";
|
|
5
|
+
import type { CapabilityInspectionOptions } from "../domain/capabilities.js";
|
|
6
|
+
import type { RationalTime } from "../domain/primitives.js";
|
|
7
|
+
import type { ProjectSnapshot } from "../domain/project.js";
|
|
8
|
+
import type { TimelineFrameCapture } from "../domain/media.js";
|
|
9
|
+
import type { RuntimeOptions } from "./runtime-options.js";
|
|
10
|
+
export declare class ProjectService {
|
|
11
|
+
private readonly adapter;
|
|
12
|
+
private readonly context;
|
|
13
|
+
private readonly options;
|
|
14
|
+
constructor(adapter: EditorPort, context: ContextEngine, options: RuntimeOptions);
|
|
15
|
+
inspectProject(): Promise<ProjectSnapshot>;
|
|
16
|
+
private inspectProjectInScope;
|
|
17
|
+
inspectTimeline(): Promise<ProjectSnapshot["timeline"]>;
|
|
18
|
+
inspectArtifact(): Promise<ManagedArtifact>;
|
|
19
|
+
captureFrame(position: RationalTime, options?: {
|
|
20
|
+
analyze?: boolean;
|
|
21
|
+
}): Promise<TimelineFrameCapture>;
|
|
22
|
+
listProjects(): Promise<ProjectCatalog>;
|
|
23
|
+
selectProject(selection: ProjectSelection): Promise<ProjectSelectionResult>;
|
|
24
|
+
inspectEditor(options?: CapabilityInspectionOptions): Promise<{
|
|
25
|
+
identity: import("../domain/capabilities.js").EditorIdentity;
|
|
26
|
+
capabilities: {
|
|
27
|
+
editor: import("../domain/capabilities.js").EditorCapabilities;
|
|
28
|
+
analyzers: import("../domain/capabilities.js").AnalyzerCapabilities;
|
|
29
|
+
schemaVersion: typeof import("../domain/capabilities.js").CAPABILITY_SCHEMA_VERSION;
|
|
30
|
+
families: import("../domain/capabilities.js").CapabilityFamilies;
|
|
31
|
+
};
|
|
32
|
+
}>;
|
|
33
|
+
listAssets(query?: AssetSearchQuery): Promise<EditorAsset[]>;
|
|
34
|
+
searchMedia(query: string): Promise<MediaContext[]>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ContextRevision } from "../domain/primitives.js";
|
|
2
|
+
import { type TimelineIr } from "../timeline/editing-session.js";
|
|
3
|
+
export declare const FRAMEKIT_PROJECT_SCHEMA_VERSION: 1;
|
|
4
|
+
export interface FramekitProjectMetadata {
|
|
5
|
+
createdAt: string;
|
|
6
|
+
updatedAt: string;
|
|
7
|
+
}
|
|
8
|
+
/** The persisted envelope owns metadata; the Timeline IR remains the canonical model. */
|
|
9
|
+
export interface FramekitProjectDocument {
|
|
10
|
+
schemaVersion: typeof FRAMEKIT_PROJECT_SCHEMA_VERSION;
|
|
11
|
+
metadata: FramekitProjectMetadata;
|
|
12
|
+
timeline: TimelineIr;
|
|
13
|
+
}
|
|
14
|
+
export interface ProjectStore {
|
|
15
|
+
create(project: FramekitProjectDocument): Promise<FramekitProjectDocument>;
|
|
16
|
+
load(): Promise<FramekitProjectDocument>;
|
|
17
|
+
save(project: FramekitProjectDocument, expectedRevision?: ContextRevision): Promise<FramekitProjectDocument>;
|
|
18
|
+
}
|
|
19
|
+
export interface ProjectStoreFileSystem {
|
|
20
|
+
mkdir(path: string, options: {
|
|
21
|
+
recursive: true;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
readFile(path: string, encoding: "utf8"): Promise<string>;
|
|
24
|
+
writeFile(path: string, data: string, options: {
|
|
25
|
+
encoding: "utf8";
|
|
26
|
+
flag: "wx";
|
|
27
|
+
}): Promise<void>;
|
|
28
|
+
link(from: string, to: string): Promise<void>;
|
|
29
|
+
rename(from: string, to: string): Promise<void>;
|
|
30
|
+
unlink(path: string): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export type ProjectPersistenceErrorCode = "PROJECT_NOT_FOUND" | "PROJECT_ALREADY_EXISTS" | "PROJECT_INVALID" | "PROJECT_CORRUPT" | "PROJECT_SCHEMA_UNSUPPORTED" | "PROJECT_STALE_REVISION" | "PROJECT_SAVE_FAILED";
|
|
33
|
+
export declare class ProjectPersistenceError extends Error {
|
|
34
|
+
readonly code: ProjectPersistenceErrorCode;
|
|
35
|
+
readonly details?: Readonly<Record<string, unknown>>;
|
|
36
|
+
constructor(code: ProjectPersistenceErrorCode, message: string, details?: Readonly<Record<string, unknown>>, options?: ErrorOptions);
|
|
37
|
+
}
|
|
38
|
+
export interface FramekitProjectMigration {
|
|
39
|
+
fromSchemaVersion: number;
|
|
40
|
+
toSchemaVersion: number;
|
|
41
|
+
migrate(input: unknown): unknown;
|
|
42
|
+
}
|
|
43
|
+
export declare class FramekitProjectStore implements ProjectStore {
|
|
44
|
+
private readonly path;
|
|
45
|
+
private readonly fs;
|
|
46
|
+
constructor(path: string, fs?: ProjectStoreFileSystem);
|
|
47
|
+
create(project: FramekitProjectDocument): Promise<FramekitProjectDocument>;
|
|
48
|
+
load(): Promise<FramekitProjectDocument>;
|
|
49
|
+
save(project: FramekitProjectDocument, expectedRevision?: ContextRevision): Promise<FramekitProjectDocument>;
|
|
50
|
+
private saveUnlocked;
|
|
51
|
+
private withProjectLock;
|
|
52
|
+
private removeTemporaryFile;
|
|
53
|
+
}
|
|
54
|
+
export declare function encodeFramekitProject(project: FramekitProjectDocument): string;
|
|
55
|
+
export declare function decodeFramekitProject(input: string | unknown): FramekitProjectDocument;
|
|
56
|
+
export declare function validateFramekitProject(project: FramekitProjectDocument): void;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ContextRevision } from "../domain/primitives.js";
|
|
2
|
+
import { type TimelineIrEditOperation } from "../timeline/editing-session.js";
|
|
3
|
+
import { type FramekitProjectDocument, type ProjectStore } from "./project-store.js";
|
|
4
|
+
export declare const PROJECT_EDIT_COMMAND_SCHEMA_VERSION: 1;
|
|
5
|
+
export interface ProjectEditCommand {
|
|
6
|
+
schemaVersion: typeof PROJECT_EDIT_COMMAND_SCHEMA_VERSION;
|
|
7
|
+
target: {
|
|
8
|
+
projectId: string;
|
|
9
|
+
sequenceId: string;
|
|
10
|
+
};
|
|
11
|
+
expectedRevision: ContextRevision;
|
|
12
|
+
operations: TimelineIrEditOperation[];
|
|
13
|
+
}
|
|
14
|
+
export interface ProjectEditDiff {
|
|
15
|
+
beforeDigest: string;
|
|
16
|
+
afterDigest: string;
|
|
17
|
+
operations: TimelineIrEditOperation[];
|
|
18
|
+
changedOccurrenceIds: string[];
|
|
19
|
+
changedMarkerIds: string[];
|
|
20
|
+
changedTitleIds: string[];
|
|
21
|
+
changedTransitionIds: string[];
|
|
22
|
+
}
|
|
23
|
+
export interface ProjectEditPreview {
|
|
24
|
+
command: ProjectEditCommand;
|
|
25
|
+
before: FramekitProjectDocument;
|
|
26
|
+
after: FramekitProjectDocument;
|
|
27
|
+
diff: ProjectEditDiff;
|
|
28
|
+
changedOccurrenceIds: string[];
|
|
29
|
+
changedMarkerIds: string[];
|
|
30
|
+
changedTitleIds: string[];
|
|
31
|
+
changedTransitionIds: string[];
|
|
32
|
+
}
|
|
33
|
+
export interface ProjectEditResult extends ProjectEditPreview {
|
|
34
|
+
committed: true;
|
|
35
|
+
}
|
|
36
|
+
export declare class ProjectTransactionError extends Error {
|
|
37
|
+
readonly code: "PROJECT_EDIT_INVALID" | "PROJECT_EDIT_UNSUPPORTED" | "PROJECT_EDIT_STALE_REVISION" | "PROJECT_EDIT_TARGET_MISMATCH";
|
|
38
|
+
readonly details?: Readonly<Record<string, unknown>>;
|
|
39
|
+
constructor(code: ProjectTransactionError["code"], message: string, details?: Readonly<Record<string, unknown>>, options?: ErrorOptions);
|
|
40
|
+
}
|
|
41
|
+
export declare class ProjectTransactionService {
|
|
42
|
+
private readonly store;
|
|
43
|
+
private readonly clock;
|
|
44
|
+
constructor(store: ProjectStore, options?: {
|
|
45
|
+
clock?: () => string;
|
|
46
|
+
});
|
|
47
|
+
preview(command: ProjectEditCommand): Promise<ProjectEditPreview>;
|
|
48
|
+
execute(command: ProjectEditCommand): Promise<ProjectEditResult>;
|
|
49
|
+
private loadAndGuard;
|
|
50
|
+
private invalid;
|
|
51
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AudioAnalyzer, NoiseAnalyzer, MetadataAnalyzer, SpeechAnalyzer, VisualAnalyzer } from "../domain/media.js";
|
|
2
|
+
import type { VerificationEngine } from "../domain/verification.js";
|
|
3
|
+
import type { SemanticMediaIndexStore } from "./semantic-media-index-store.js";
|
|
4
|
+
export interface RuntimeOptions {
|
|
5
|
+
speechAnalyzer?: SpeechAnalyzer;
|
|
6
|
+
audioAnalyzer?: AudioAnalyzer;
|
|
7
|
+
noiseAnalyzer?: NoiseAnalyzer;
|
|
8
|
+
visualAnalyzer?: VisualAnalyzer;
|
|
9
|
+
metadataAnalyzer?: MetadataAnalyzer;
|
|
10
|
+
semanticMediaIndexStore?: SemanticMediaIndexStore;
|
|
11
|
+
verificationEngine?: VerificationEngine;
|
|
12
|
+
now?: () => number;
|
|
13
|
+
previewTtlMs?: number;
|
|
14
|
+
maxActivePreviews?: number;
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { MediaSourceIdentity, MediaUnderstanding } from "../domain/media.js";
|
|
2
|
+
export declare const SEMANTIC_MEDIA_INDEX_SCHEMA_VERSION: 1;
|
|
3
|
+
export interface SemanticMediaIndexDocument {
|
|
4
|
+
schemaVersion: typeof SEMANTIC_MEDIA_INDEX_SCHEMA_VERSION;
|
|
5
|
+
entries: MediaUnderstanding[];
|
|
6
|
+
}
|
|
7
|
+
/** Persistent, provider-neutral source-media analysis storage. */
|
|
8
|
+
export interface SemanticMediaIndexStore {
|
|
9
|
+
load(source: MediaSourceIdentity): Promise<MediaUnderstanding | undefined>;
|
|
10
|
+
list(): Promise<MediaUnderstanding[]>;
|
|
11
|
+
save(understanding: MediaUnderstanding): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/** Deterministic store for runtime and integration tests. */
|
|
14
|
+
export declare class InMemorySemanticMediaIndexStore implements SemanticMediaIndexStore {
|
|
15
|
+
private readonly entries;
|
|
16
|
+
load(source: MediaSourceIdentity): Promise<MediaUnderstanding | undefined>;
|
|
17
|
+
list(): Promise<MediaUnderstanding[]>;
|
|
18
|
+
save(understanding: MediaUnderstanding): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/** Atomic JSON persistence for a local semantic media index. */
|
|
21
|
+
export declare class JsonSemanticMediaIndexStore implements SemanticMediaIndexStore {
|
|
22
|
+
private readonly path;
|
|
23
|
+
constructor(path: string);
|
|
24
|
+
load(source: MediaSourceIdentity): Promise<MediaUnderstanding | undefined>;
|
|
25
|
+
list(): Promise<MediaUnderstanding[]>;
|
|
26
|
+
save(understanding: MediaUnderstanding): Promise<void>;
|
|
27
|
+
private readDocument;
|
|
28
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EditTransaction } from "../domain/editing.js";
|
|
2
|
+
export interface TransactionStore {
|
|
3
|
+
set(transaction: EditTransaction): void;
|
|
4
|
+
get(transactionId: string): EditTransaction;
|
|
5
|
+
}
|
|
6
|
+
export declare class InMemoryTransactionStore implements TransactionStore {
|
|
7
|
+
private readonly transactions;
|
|
8
|
+
set(transaction: EditTransaction): void;
|
|
9
|
+
get(transactionId: string): EditTransaction;
|
|
10
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { parseRational } from "../timeline/rational-time.js";
|
|
2
|
+
/** Validate the measurement payload before binding provenance or serializing it. */
|
|
3
|
+
export function validateAudioAnalysisPayload(value) {
|
|
4
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5
|
+
throw new Error("ANALYSIS_INVALID: audio analysis must be an object");
|
|
6
|
+
}
|
|
7
|
+
const analysis = value;
|
|
8
|
+
if (analysis.signalScope !== undefined && analysis.signalScope !== "source" && analysis.signalScope !== "occurrence") {
|
|
9
|
+
throw new Error("ANALYSIS_INVALID: unsupported audio signal scope");
|
|
10
|
+
}
|
|
11
|
+
if (analysis.signalScope === "occurrence"
|
|
12
|
+
&& (typeof analysis.occurrenceId !== "string" || !analysis.occurrenceId.trim())) {
|
|
13
|
+
throw new Error("ANALYSIS_INVALID: occurrence audio requires an occurrence identity");
|
|
14
|
+
}
|
|
15
|
+
for (const field of ["integratedLufs", "truePeakDb", "silenceMs"]) {
|
|
16
|
+
const measured = analysis[field];
|
|
17
|
+
if (typeof measured !== "number" || !Number.isFinite(measured)) {
|
|
18
|
+
throw new Error(`ANALYSIS_INVALID: audio ${field} must be finite`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (analysis.silenceMs < 0) {
|
|
22
|
+
throw new Error("ANALYSIS_INVALID: audio silenceMs must be nonnegative");
|
|
23
|
+
}
|
|
24
|
+
if (analysis.analyzedDurationSeconds !== undefined
|
|
25
|
+
&& (typeof analysis.analyzedDurationSeconds !== "number"
|
|
26
|
+
|| !Number.isFinite(analysis.analyzedDurationSeconds) || analysis.analyzedDurationSeconds <= 0)) {
|
|
27
|
+
throw new Error("ANALYSIS_INVALID: audio analyzedDurationSeconds must be finite and positive");
|
|
28
|
+
}
|
|
29
|
+
if (analysis.audibleSamples !== undefined
|
|
30
|
+
&& (typeof analysis.audibleSamples !== "number" || !Number.isSafeInteger(analysis.audibleSamples)
|
|
31
|
+
|| analysis.audibleSamples < 0)) {
|
|
32
|
+
throw new Error("ANALYSIS_INVALID: audio audibleSamples must be a nonnegative safe integer");
|
|
33
|
+
}
|
|
34
|
+
for (const field of ["dialoguePresent", "valid"]) {
|
|
35
|
+
if (analysis[field] !== undefined && typeof analysis[field] !== "boolean") {
|
|
36
|
+
throw new Error(`ANALYSIS_INVALID: audio ${field} must be boolean`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (analysis.invalidReason !== undefined && typeof analysis.invalidReason !== "string") {
|
|
40
|
+
throw new Error("ANALYSIS_INVALID: audio invalidReason must be text");
|
|
41
|
+
}
|
|
42
|
+
if (analysis.sourceTimebase !== undefined)
|
|
43
|
+
rationalSeconds(analysis.sourceTimebase, "sourceTimebase");
|
|
44
|
+
for (const field of ["requestedRange", "measuredRange"]) {
|
|
45
|
+
if (analysis[field] !== undefined)
|
|
46
|
+
validateAudioAnalysisRange(analysis[field], field);
|
|
47
|
+
}
|
|
48
|
+
if (analysis.signalFormat !== undefined) {
|
|
49
|
+
const format = analysis.signalFormat;
|
|
50
|
+
if (!format || typeof format !== "object" || Array.isArray(format)) {
|
|
51
|
+
throw new Error("ANALYSIS_INVALID: audio signalFormat must be an object");
|
|
52
|
+
}
|
|
53
|
+
for (const field of ["sampleRate", "channels"]) {
|
|
54
|
+
const count = format[field];
|
|
55
|
+
if (typeof count !== "number" || !Number.isSafeInteger(count) || count <= 0) {
|
|
56
|
+
throw new Error(`ANALYSIS_INVALID: audio signalFormat ${field} must be a positive safe integer`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const layout = format.channelLayout;
|
|
60
|
+
if (layout !== undefined && (typeof layout !== "string" || !layout.trim())) {
|
|
61
|
+
throw new Error("ANALYSIS_INVALID: audio channelLayout must be nonempty text");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function rationalSeconds(value, label, allowZero = false) {
|
|
66
|
+
if (!value || typeof value !== "object" || Array.isArray(value)
|
|
67
|
+
|| typeof value.value !== "string"
|
|
68
|
+
|| typeof value.timescale !== "string") {
|
|
69
|
+
throw new Error(`ANALYSIS_INVALID: audio ${label} must be a rational time`);
|
|
70
|
+
}
|
|
71
|
+
const parsed = parseRational(value, "ANALYSIS_INVALID");
|
|
72
|
+
const seconds = Number(parsed.value) / Number(parsed.timescale);
|
|
73
|
+
if (!Number.isFinite(seconds) || (allowZero ? seconds < 0 : seconds <= 0)) {
|
|
74
|
+
throw new Error(`ANALYSIS_INVALID: audio ${label} must be ${allowZero ? "nonnegative" : "positive"}`);
|
|
75
|
+
}
|
|
76
|
+
return seconds;
|
|
77
|
+
}
|
|
78
|
+
export function validateAudioAnalysisRange(value, label) {
|
|
79
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
80
|
+
throw new Error(`ANALYSIS_INVALID: audio ${label} must be a range`);
|
|
81
|
+
}
|
|
82
|
+
const range = value;
|
|
83
|
+
if (typeof range.start !== "number" || typeof range.end !== "number"
|
|
84
|
+
|| !Number.isFinite(range.start) || !Number.isFinite(range.end) || range.start < 0 || range.end <= range.start) {
|
|
85
|
+
throw new Error(`ANALYSIS_INVALID: audio ${label} must be finite and positive`);
|
|
86
|
+
}
|
|
87
|
+
if (range.startTime !== undefined
|
|
88
|
+
&& Math.abs(rationalSeconds(range.startTime, label + " start", true) - range.start) > 0.000000001) {
|
|
89
|
+
throw new Error(`ANALYSIS_INVALID: audio ${label} numeric and rational start differ`);
|
|
90
|
+
}
|
|
91
|
+
if (range.durationTime !== undefined
|
|
92
|
+
&& Math.abs(rationalSeconds(range.durationTime, label + " duration") - (range.end - range.start)) > 0.000000001) {
|
|
93
|
+
throw new Error(`ANALYSIS_INVALID: audio ${label} numeric and rational duration differ`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AudioMeasurement } from "../domain/media.js";
|
|
2
|
+
import type { ContextRevision } from "../domain/primitives.js";
|
|
3
|
+
import type { EditOperation } from "../domain/editing.js";
|
|
4
|
+
import type { TimelineDiff } from "../domain/diff.js";
|
|
5
|
+
export type DialogueGainDecision = "APPLY" | "NO_OP" | "SKIP";
|
|
6
|
+
export type DialogueGainReasonCode = "APPLY_GAIN" | "ALREADY_IN_TOLERANCE" | "MEASUREMENT_INVALID" | "NO_DIALOGUE" | "SILENCE" | "DIALOGUE_TOO_SHORT" | "GAIN_OUT_OF_BOUNDS" | "PEAK_RISK";
|
|
7
|
+
export interface DialogueGainPlanningOptions {
|
|
8
|
+
targetLufs: number;
|
|
9
|
+
toleranceDb: number;
|
|
10
|
+
maxTruePeakDb: number;
|
|
11
|
+
minGainDb: number;
|
|
12
|
+
maxGainDb: number;
|
|
13
|
+
minDialogueDurationSeconds: number;
|
|
14
|
+
}
|
|
15
|
+
export interface DialogueGainPlan extends DialogueGainPlanningOptions {
|
|
16
|
+
decision: DialogueGainDecision;
|
|
17
|
+
currentLufs: number;
|
|
18
|
+
desiredGainDb: number;
|
|
19
|
+
clampedGainDb: number;
|
|
20
|
+
estimatedPeakDb: number;
|
|
21
|
+
reasonCodes: DialogueGainReasonCode[];
|
|
22
|
+
}
|
|
23
|
+
export interface DialogueNormalizationRequest extends DialogueGainPlanningOptions {
|
|
24
|
+
mediaId: string;
|
|
25
|
+
occurrenceId: string;
|
|
26
|
+
baseRevision: ContextRevision;
|
|
27
|
+
}
|
|
28
|
+
export interface DialogueNormalizationPreview {
|
|
29
|
+
measurement: AudioMeasurement;
|
|
30
|
+
plan: DialogueGainPlan;
|
|
31
|
+
operations: EditOperation[];
|
|
32
|
+
expectedDiff?: TimelineDiff;
|
|
33
|
+
previewToken?: string;
|
|
34
|
+
warnings: string[];
|
|
35
|
+
expiresAt?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Defaults for the version 1.0.0 dialogue-normalization Skill. */
|
|
38
|
+
export declare const DIALOGUE_NORMALIZATION_DEFAULTS: {
|
|
39
|
+
readonly targetLufs: -16;
|
|
40
|
+
readonly toleranceDb: 0.5;
|
|
41
|
+
readonly maxTruePeakDb: -1;
|
|
42
|
+
readonly minGainDb: -6;
|
|
43
|
+
readonly maxGainDb: 6;
|
|
44
|
+
readonly minDialogueDurationSeconds: 1;
|
|
45
|
+
};
|
|
46
|
+
/** Plan a bounded clip-level gain change without mutating an editor. */
|
|
47
|
+
export declare function planDialogueGain(measurement: AudioMeasurement, options: DialogueGainPlanningOptions): DialogueGainPlan;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ContextRevision } from "../domain/primitives.js";
|
|
2
|
+
import type { EditOperation } from "../domain/editing.js";
|
|
3
|
+
import type { NoiseMeasurement } from "../domain/media.js";
|
|
4
|
+
import type { TimelineDiff } from "../domain/diff.js";
|
|
5
|
+
export type NoiseReductionDecision = "APPLY" | "NO_OP" | "SKIP";
|
|
6
|
+
export type NoiseReductionReasonCode = "APPLY_NOISE_REDUCTION" | "ALREADY_BELOW_THRESHOLD" | "MEASUREMENT_INVALID" | "NO_AFFECTED_RANGE" | "CONFIDENCE_TOO_LOW" | "REDUCTION_INVALID";
|
|
7
|
+
export interface NoiseReductionPlanningOptions {
|
|
8
|
+
noiseThresholdDb: number;
|
|
9
|
+
maxReductionDb: number;
|
|
10
|
+
minConfidence: number;
|
|
11
|
+
}
|
|
12
|
+
export interface NoiseReductionRequest extends NoiseReductionPlanningOptions {
|
|
13
|
+
mediaId: string;
|
|
14
|
+
occurrenceId: string;
|
|
15
|
+
baseRevision: ContextRevision;
|
|
16
|
+
}
|
|
17
|
+
export interface NoiseReductionPlan extends NoiseReductionPlanningOptions {
|
|
18
|
+
decision: NoiseReductionDecision;
|
|
19
|
+
noiseFloorDb: number;
|
|
20
|
+
recommendedReductionDb: number;
|
|
21
|
+
reductionDb: number;
|
|
22
|
+
affectedRanges: NoiseMeasurement["affectedRanges"];
|
|
23
|
+
reasonCodes: NoiseReductionReasonCode[];
|
|
24
|
+
}
|
|
25
|
+
export interface NoiseReductionPreview {
|
|
26
|
+
measurement: NoiseMeasurement;
|
|
27
|
+
plan: NoiseReductionPlan;
|
|
28
|
+
operations: EditOperation[];
|
|
29
|
+
expectedDiff?: TimelineDiff;
|
|
30
|
+
previewToken?: string;
|
|
31
|
+
warnings: string[];
|
|
32
|
+
expiresAt?: string;
|
|
33
|
+
}
|
|
34
|
+
export declare function planNoiseReduction(measurement: NoiseMeasurement, options: NoiseReductionPlanningOptions): NoiseReductionPlan;
|