@bendyline/squisq 1.5.2 → 2.0.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/README.md +63 -10
- package/dist/{Doc-BBVGq1_9.d.ts → Doc-ylqWKDc_.d.ts} +248 -37
- package/dist/{ImageEditDoc-FuyGtt6o.d.ts → ImageEditDoc-D828IXJ1.d.ts} +1 -1
- package/dist/annotationCoercion-Dr_DY9Hx.d.ts +86 -0
- package/dist/{chunk-VWUFZ6ZG.js → chunk-3E5F2XMR.js} +2 -29
- package/dist/chunk-3E5F2XMR.js.map +1 -0
- package/dist/chunk-4X3JQXNM.js +35 -0
- package/dist/chunk-4X3JQXNM.js.map +1 -0
- package/dist/{chunk-P3K7NLHF.js → chunk-5DKBFXPY.js} +31 -121
- package/dist/chunk-5DKBFXPY.js.map +1 -0
- package/dist/{chunk-DLXZMS5K.js → chunk-5J4HKRJF.js} +51 -3
- package/dist/chunk-5J4HKRJF.js.map +1 -0
- package/dist/chunk-5UYI3RJB.js +2503 -0
- package/dist/chunk-5UYI3RJB.js.map +1 -0
- package/dist/{chunk-BEQODJWV.js → chunk-66QO7XFB.js} +11 -291
- package/dist/chunk-66QO7XFB.js.map +1 -0
- package/dist/{chunk-KKNUBQ6Y.js → chunk-6PJRB2CF.js} +156 -91
- package/dist/chunk-6PJRB2CF.js.map +1 -0
- package/dist/{chunk-HWVFJAAH.js → chunk-AMIR72JP.js} +28 -10
- package/dist/chunk-AMIR72JP.js.map +1 -0
- package/dist/chunk-FVJUUTEM.js +74 -0
- package/dist/chunk-FVJUUTEM.js.map +1 -0
- package/dist/{chunk-5TYS5V3G.js → chunk-GF3BVNLU.js} +4127 -3538
- package/dist/chunk-GF3BVNLU.js.map +1 -0
- package/dist/{chunk-Q3ROPT5H.js → chunk-GZY66SDN.js} +1 -1
- package/dist/{chunk-Q3ROPT5H.js.map → chunk-GZY66SDN.js.map} +1 -1
- package/dist/chunk-JOQYPRDZ.js +127 -0
- package/dist/chunk-JOQYPRDZ.js.map +1 -0
- package/dist/{chunk-A4O7GIWE.js → chunk-LYNJEOAC.js} +10 -73
- package/dist/chunk-LYNJEOAC.js.map +1 -0
- package/dist/{chunk-LDQ2HJIX.js → chunk-PXLVXTLW.js} +252 -54
- package/dist/chunk-PXLVXTLW.js.map +1 -0
- package/dist/{chunk-TQWLI6S2.js → chunk-Q7LROV2H.js} +4 -2
- package/dist/{chunk-TQWLI6S2.js.map → chunk-Q7LROV2H.js.map} +1 -1
- package/dist/{chunk-T5UK6YOB.js → chunk-QTSJOY54.js} +60 -17
- package/dist/chunk-QTSJOY54.js.map +1 -0
- package/dist/chunk-QVANWDPH.js +2358 -0
- package/dist/chunk-QVANWDPH.js.map +1 -0
- package/dist/{chunk-GPLTCSXO.js → chunk-R2GC6RLD.js} +7 -7
- package/dist/chunk-R2GC6RLD.js.map +1 -0
- package/dist/chunk-R2YZTCLO.js +292 -0
- package/dist/chunk-R2YZTCLO.js.map +1 -0
- package/dist/chunk-S7A5D7ZJ.js +174 -0
- package/dist/chunk-S7A5D7ZJ.js.map +1 -0
- package/dist/chunk-T3TI7GSZ.js +884 -0
- package/dist/chunk-T3TI7GSZ.js.map +1 -0
- package/dist/{chunk-LTN6I7QW.js → chunk-TUWMK62B.js} +55 -4
- package/dist/chunk-TUWMK62B.js.map +1 -0
- package/dist/{chunk-IMSCRLLV.js → chunk-VR7UPJ7C.js} +35 -25
- package/dist/chunk-VR7UPJ7C.js.map +1 -0
- package/dist/doc/index.d.ts +2334 -5
- package/dist/doc/index.js +127 -33
- package/dist/generate/index.d.ts +7 -2
- package/dist/generate/index.js +1 -1
- package/dist/imageEdit/index.d.ts +9 -6
- package/dist/imageEdit/index.js +3 -3
- package/dist/index.d.ts +12 -10
- package/dist/index.js +246 -80
- package/dist/jsonForm/index.d.ts +7 -3
- package/dist/jsonForm/index.js +9 -4
- package/dist/markdown/index.d.ts +6 -70
- package/dist/markdown/index.js +13 -9
- package/dist/narration/index.d.ts +618 -0
- package/dist/narration/index.js +82 -0
- package/dist/recommend/index.d.ts +15 -1
- package/dist/recommend/index.js +2 -2
- package/dist/schemas/index.d.ts +28 -6
- package/dist/schemas/index.js +15 -13
- package/dist/spatial/index.d.ts +0 -1
- package/dist/spatial/index.js +1 -1
- package/dist/storage/index.js +1 -1
- package/dist/{themeLibrary-CehcJhzz.d.ts → themeLibrary-RjVgLpUi.d.ts} +10 -11
- package/dist/timing/index.js +5 -3
- package/dist/transform/index.d.ts +35 -24
- package/dist/transform/index.js +9 -10
- package/dist/{types-DlAZ7MW4.d.ts → types-BwMPl2CB.d.ts} +1 -1
- package/dist/{types-D98li1gV.d.ts → types-C4kiRn_k.d.ts} +3 -1
- package/dist/versions/index.d.ts +2 -1
- package/dist/versions/index.js +2 -2
- package/package.json +6 -6
- package/src/__tests__/applyNarrationTiming.test.ts +190 -0
- package/src/__tests__/applyRenderStyle.test.ts +3 -3
- package/src/__tests__/asciiDiagramBattle.test.ts +246 -0
- package/src/__tests__/asciiDiagramDetect.test.ts +162 -0
- package/src/__tests__/asciiDiagramMapping.test.ts +38 -0
- package/src/__tests__/asciiDiagramParse.test.ts +233 -0
- package/src/__tests__/asciiDiagramPipeline.test.ts +273 -0
- package/src/__tests__/asciiDiagramRender.test.ts +162 -0
- package/src/__tests__/asciiDiagramRepair.test.ts +84 -0
- package/src/__tests__/asciiTimelineDetect.test.ts +157 -0
- package/src/__tests__/asciiTimelineParse.test.ts +205 -0
- package/src/__tests__/asciiTimelinePipeline.test.ts +349 -0
- package/src/__tests__/asciiTimelineRender.test.ts +376 -0
- package/src/__tests__/attrTokens.test.ts +5 -0
- package/src/__tests__/contentContainer.test.ts +43 -0
- package/src/__tests__/customTemplatesFrontmatter.test.ts +0 -15
- package/src/__tests__/dataTable.test.ts +25 -15
- package/src/__tests__/diagramBlock.test.ts +3 -3
- package/src/__tests__/diagramText.test.ts +26 -0
- package/src/__tests__/docToMarkdownMedia.test.ts +83 -0
- package/src/__tests__/drawingBlock.test.ts +3 -3
- package/src/__tests__/fixtures/asciiDiagramBattle.ts +512 -0
- package/src/__tests__/fixtures/asciiDiagrams.ts +287 -0
- package/src/__tests__/fixtures/asciiTimelines.ts +35 -0
- package/src/__tests__/fixtures/treeviewFixtures.ts +243 -0
- package/src/__tests__/getLayers.test.ts +32 -18
- package/src/__tests__/getLayersFallback.test.ts +8 -8
- package/src/__tests__/imageEditVersions.test.ts +2 -0
- package/src/__tests__/jsonForm.pointer.test.ts +47 -1
- package/src/__tests__/layoutBlock.test.ts +3 -3
- package/src/__tests__/majorApiTypes.test.ts +18 -0
- package/src/__tests__/markdown.test.ts +41 -0
- package/src/__tests__/matchFontFamily.test.ts +114 -0
- package/src/__tests__/materializeBlockLayers.test.ts +135 -0
- package/src/__tests__/materializeTestUtils.ts +17 -0
- package/src/__tests__/narrationAlign.test.ts +150 -0
- package/src/__tests__/narrationFeatures.test.ts +71 -0
- package/src/__tests__/narrationNuclei.test.ts +45 -0
- package/src/__tests__/narrationPacing.test.ts +189 -0
- package/src/__tests__/narrationScript.test.ts +149 -0
- package/src/__tests__/narrationSessionRepro.test.ts +62 -0
- package/src/__tests__/narrationSidecar.test.ts +88 -0
- package/src/__tests__/narrationSyllables.test.ts +65 -0
- package/src/__tests__/narrationTestSignals.ts +167 -0
- package/src/__tests__/narrationVad.test.ts +66 -0
- package/src/__tests__/resolveDocTheme.test.ts +16 -2
- package/src/__tests__/rootExports.test.ts +18 -0
- package/src/__tests__/scopedContentContainer.test.ts +20 -0
- package/src/__tests__/shapeGeometry.test.ts +12 -0
- package/src/__tests__/templateAnnotationParse.test.ts +10 -0
- package/src/__tests__/templateInputs.test.ts +69 -0
- package/src/__tests__/templateMetadata.test.ts +2 -1
- package/src/__tests__/templates.test.ts +143 -17
- package/src/__tests__/themeCompile.test.ts +49 -22
- package/src/__tests__/transformProvenance.test.ts +160 -0
- package/src/__tests__/transformV2.test.ts +40 -14
- package/src/__tests__/treeviewBattle.test.ts +76 -0
- package/src/__tests__/treeviewDetect.test.ts +168 -0
- package/src/__tests__/treeviewParse.test.ts +118 -0
- package/src/__tests__/treeviewPipeline.test.ts +183 -0
- package/src/__tests__/treeviewRender.test.ts +91 -0
- package/src/__tests__/versions.test.ts +44 -0
- package/src/doc/applyNarrationTiming.ts +244 -0
- package/src/doc/asciiDiagram/chars.ts +210 -0
- package/src/doc/asciiDiagram/detect.ts +175 -0
- package/src/doc/asciiDiagram/index.ts +38 -0
- package/src/doc/asciiDiagram/mapping.ts +225 -0
- package/src/doc/asciiDiagram/parse.ts +1095 -0
- package/src/doc/asciiDiagram/render.ts +963 -0
- package/src/doc/asciiDiagram/repair.ts +400 -0
- package/src/doc/asciiDiagram/types.ts +65 -0
- package/src/doc/asciiTimeline/detect.ts +138 -0
- package/src/doc/asciiTimeline/index.ts +26 -0
- package/src/doc/asciiTimeline/mapping.ts +43 -0
- package/src/doc/asciiTimeline/parse.ts +870 -0
- package/src/doc/asciiTimeline/render.ts +427 -0
- package/src/doc/asciiTimeline/types.ts +73 -0
- package/src/doc/asciiTimeline/wrappedFlow.ts +427 -0
- package/src/doc/audioMapping.ts +60 -46
- package/src/doc/customTemplatesFrontmatter.ts +0 -41
- package/src/doc/docToMarkdown.ts +70 -2
- package/src/doc/index.ts +76 -4
- package/src/doc/markdownToDoc.ts +135 -1
- package/src/doc/materializeBlockLayers.ts +304 -0
- package/src/doc/mediaAnnotations.ts +20 -0
- package/src/doc/resolveDocTheme.ts +8 -7
- package/src/doc/templateInputs.ts +185 -2
- package/src/doc/templates/__tests__/customTemplateRegistry.test.ts +22 -8
- package/src/doc/templates/diagramBlock.ts +237 -38
- package/src/doc/templates/fallbackBlock.ts +1 -1
- package/src/doc/templates/index.ts +134 -279
- package/src/doc/templates/inputDescriptors.ts +20 -1
- package/src/doc/templates/metadata.ts +10 -0
- package/src/doc/templates/persistentLayers.ts +12 -126
- package/src/doc/templates/registry.ts +88 -0
- package/src/doc/templates/templateNames.ts +22 -0
- package/src/doc/templates/timelineBlock.ts +613 -0
- package/src/doc/templates/treeBlock.ts +131 -0
- package/src/doc/treeview/chars.ts +72 -0
- package/src/doc/treeview/detect.ts +145 -0
- package/src/doc/treeview/index.ts +30 -0
- package/src/doc/treeview/mapping.ts +95 -0
- package/src/doc/treeview/parse.ts +201 -0
- package/src/doc/treeview/render.ts +41 -0
- package/src/doc/treeview/types.ts +43 -0
- package/src/doc/utils/applyRenderStyle.ts +2 -9
- package/src/doc/utils/diagramText.ts +78 -0
- package/src/doc/utils/shapeGeometry.ts +67 -5
- package/src/doc/validate.ts +1 -1
- package/src/generate/templateMapper.ts +7 -0
- package/src/imageEdit/export.ts +6 -5
- package/src/imageEdit/versionPaths.ts +13 -26
- package/src/imageEdit/versions.ts +21 -100
- package/src/index.ts +1 -0
- package/src/internal/immutable.ts +58 -0
- package/src/jsonForm/index.ts +9 -1
- package/src/jsonForm/pointer.ts +68 -23
- package/src/markdown/attrTokens.ts +7 -5
- package/src/markdown/index.ts +1 -0
- package/src/markdown/stringify.ts +4 -9
- package/src/markdown/utils.ts +36 -14
- package/src/narration/align.ts +514 -0
- package/src/narration/features.ts +231 -0
- package/src/narration/index.ts +86 -0
- package/src/narration/nuclei.ts +118 -0
- package/src/narration/pacing.ts +211 -0
- package/src/narration/script.ts +239 -0
- package/src/narration/session.ts +100 -0
- package/src/narration/sidecar.ts +187 -0
- package/src/narration/syllables.ts +85 -0
- package/src/narration/trace.ts +50 -0
- package/src/narration/types.ts +299 -0
- package/src/narration/vad.ts +131 -0
- package/src/recommend/numberHighlight.ts +25 -0
- package/src/recommend/templates.ts +108 -12
- package/src/schemas/BlockTemplates.ts +156 -7
- package/src/schemas/Doc.ts +72 -9
- package/src/schemas/Media.ts +12 -2
- package/src/schemas/Theme.ts +45 -25
- package/src/schemas/Viewport.ts +2 -2
- package/src/schemas/fontStacks.ts +79 -0
- package/src/schemas/themeCompile.ts +15 -0
- package/src/schemas/themeConstants.ts +2 -0
- package/src/schemas/themeLibrary.ts +25 -19
- package/src/schemas/themeValidator.ts +1 -1
- package/src/spatial/Geohash.ts +0 -3
- package/src/storage/ContentContainer.ts +17 -9
- package/src/storage/ScopedContentContainer.ts +45 -15
- package/src/transform/applyTransform.ts +5 -5
- package/src/transform/index.ts +3 -1
- package/src/transform/registry.ts +169 -49
- package/src/transform/templateSelector.ts +21 -2
- package/src/transform/timingAllocator.ts +152 -21
- package/src/transform/types.ts +14 -1
- package/src/versions/gitignore.ts +34 -0
- package/src/versions/index.ts +2 -0
- package/src/versions/operations.ts +18 -104
- package/src/versions/paths.ts +13 -28
- package/src/versions/snapshotStore.ts +202 -0
- package/src/versions/types.ts +3 -1
- package/dist/chunk-5TYS5V3G.js.map +0 -1
- package/dist/chunk-A4O7GIWE.js.map +0 -1
- package/dist/chunk-BEQODJWV.js.map +0 -1
- package/dist/chunk-DLXZMS5K.js.map +0 -1
- package/dist/chunk-GPLTCSXO.js.map +0 -1
- package/dist/chunk-HWVFJAAH.js.map +0 -1
- package/dist/chunk-IMSCRLLV.js.map +0 -1
- package/dist/chunk-JELIRVDP.js +0 -24
- package/dist/chunk-JELIRVDP.js.map +0 -1
- package/dist/chunk-KKNUBQ6Y.js.map +0 -1
- package/dist/chunk-LDQ2HJIX.js.map +0 -1
- package/dist/chunk-LTN6I7QW.js.map +0 -1
- package/dist/chunk-P3K7NLHF.js.map +0 -1
- package/dist/chunk-T5UK6YOB.js.map +0 -1
- package/dist/chunk-UY7KGQ5R.js +0 -192
- package/dist/chunk-UY7KGQ5R.js.map +0 -1
- package/dist/chunk-VLJJHDAC.js +0 -218
- package/dist/chunk-VLJJHDAC.js.map +0 -1
- package/dist/chunk-VWUFZ6ZG.js.map +0 -1
- package/dist/story/index.d.ts +0 -1801
- package/dist/story/index.js +0 -279
- package/src/doc/getLayers.ts +0 -195
- /package/dist/{story → narration}/index.js.map +0 -0
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
import { F as Doc, e as AudioBookmark } from '../Doc-ylqWKDc_.js';
|
|
2
|
+
import '../types-BwMPl2CB.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Shared types + tuning configs for the narration engine.
|
|
6
|
+
*
|
|
7
|
+
* The engine is pure TypeScript with zero dependencies and no DOM/Node
|
|
8
|
+
* APIs: audio arrives as mono `Float32Array` PCM (the editor decodes
|
|
9
|
+
* WebM/MP4 on its side), and every stage is a deterministic step
|
|
10
|
+
* function `(state, input, config) → state` so the whole pipeline is
|
|
11
|
+
* unit-testable in Node with synthetic signals. No `Date.now`, no
|
|
12
|
+
* `Math.random`, no timers anywhere in this module.
|
|
13
|
+
*/
|
|
14
|
+
/** One word of the teleprompter script, positioned inside {@link NarrationScript.sourceText}. */
|
|
15
|
+
interface ScriptToken {
|
|
16
|
+
/** The word as displayed (no surrounding whitespace). */
|
|
17
|
+
text: string;
|
|
18
|
+
/** Start offset into {@link NarrationScript.sourceText}. */
|
|
19
|
+
charOffset: number;
|
|
20
|
+
/** Exclusive end offset into {@link NarrationScript.sourceText}. */
|
|
21
|
+
charEnd: number;
|
|
22
|
+
/** Id of the doc block this word belongs to. */
|
|
23
|
+
blockId: string;
|
|
24
|
+
/** Index into {@link NarrationScript.blocks}. */
|
|
25
|
+
blockIndex: number;
|
|
26
|
+
/** Estimated syllable count (≥ 1 for spoken tokens; 0 when `spoken` is false). */
|
|
27
|
+
syllables: number;
|
|
28
|
+
/** Spoken-word equivalents (numbers count as several words; 0 when not spoken). */
|
|
29
|
+
spokenWordEquiv: number;
|
|
30
|
+
/**
|
|
31
|
+
* Pause class after this token:
|
|
32
|
+
* 0 none · 1 clause/sentence punctuation · 2 paragraph break · 3 block boundary.
|
|
33
|
+
*/
|
|
34
|
+
pauseAfter: 0 | 1 | 2 | 3;
|
|
35
|
+
/**
|
|
36
|
+
* Whether this token is actually spoken. Standalone punctuation runs —
|
|
37
|
+
* an em-dash, a lone bullet, `···` — tokenize on whitespace like words
|
|
38
|
+
* but carry no letters or digits: they DISPLAY in the prompter yet must
|
|
39
|
+
* never be the highlighted active word, are never paused on, and add no
|
|
40
|
+
* syllables to the pacing/alignment model.
|
|
41
|
+
*/
|
|
42
|
+
spoken: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** The token/char span of one doc block inside the script. */
|
|
45
|
+
interface ScriptBlockRange {
|
|
46
|
+
blockId: string;
|
|
47
|
+
/** The block's heading text, when present. */
|
|
48
|
+
heading?: string;
|
|
49
|
+
/** Inclusive index into {@link NarrationScript.tokens}. */
|
|
50
|
+
tokenStart: number;
|
|
51
|
+
/** Exclusive index into {@link NarrationScript.tokens}. */
|
|
52
|
+
tokenEnd: number;
|
|
53
|
+
/** Start offset into {@link NarrationScript.sourceText} (includes the spoken title). */
|
|
54
|
+
charStart: number;
|
|
55
|
+
/** Exclusive end offset into {@link NarrationScript.sourceText}. */
|
|
56
|
+
charEnd: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The teleprompter script derived from a Doc. `sourceText` is canonical:
|
|
60
|
+
* it is stored verbatim in the timing sidecar, and every `charOffset`
|
|
61
|
+
* indexes into it. Building is deterministic — the same Doc always
|
|
62
|
+
* yields a byte-identical script.
|
|
63
|
+
*/
|
|
64
|
+
interface NarrationScript {
|
|
65
|
+
sourceText: string;
|
|
66
|
+
tokens: ScriptToken[];
|
|
67
|
+
blocks: ScriptBlockRange[];
|
|
68
|
+
totalSyllables: number;
|
|
69
|
+
/**
|
|
70
|
+
* Prefix sums: `cumulativeSyllables[i]` = syllables of `tokens[0..i-1]`.
|
|
71
|
+
* Length is `tokens.length + 1`.
|
|
72
|
+
*/
|
|
73
|
+
cumulativeSyllables: number[];
|
|
74
|
+
}
|
|
75
|
+
/** Per-frame acoustic features extracted from PCM. */
|
|
76
|
+
interface FrameFeatures {
|
|
77
|
+
/** Frame CENTER time in seconds from the start of the signal. */
|
|
78
|
+
tSec: number;
|
|
79
|
+
/** Full-band root-mean-square of the frame. */
|
|
80
|
+
rms: number;
|
|
81
|
+
/** Mean square of the 250–3000 Hz bandpassed frame (speech band energy). */
|
|
82
|
+
bandEnergy: number;
|
|
83
|
+
/** Zero crossings / (frameLength − 1), in [0, 1]. */
|
|
84
|
+
zcr: number;
|
|
85
|
+
}
|
|
86
|
+
interface FeatureConfig {
|
|
87
|
+
/** Analysis frame length in samples (~21 ms @ 48 kHz). */
|
|
88
|
+
frameSize: number;
|
|
89
|
+
/** Hop between frame starts in seconds (live 0.02; the aligner uses 0.01). */
|
|
90
|
+
hopSec: number;
|
|
91
|
+
/** Bandpass high-pass corner (Hz). */
|
|
92
|
+
bandLowHz: number;
|
|
93
|
+
/** Bandpass low-pass corner (Hz). */
|
|
94
|
+
bandHighHz: number;
|
|
95
|
+
}
|
|
96
|
+
declare const DEFAULT_FEATURE_CONFIG: FeatureConfig;
|
|
97
|
+
interface VadConfig {
|
|
98
|
+
/** Floor-seeding period before any speech decision (ms). */
|
|
99
|
+
warmupMs: number;
|
|
100
|
+
/** Floor attack toward minima (per-frame EMA alpha when energy < floor). */
|
|
101
|
+
alphaDown: number;
|
|
102
|
+
/** Floor release (per-frame EMA alpha when energy ≥ floor; frozen while speaking). */
|
|
103
|
+
alphaUp: number;
|
|
104
|
+
/** Enter speech when energy > floor × enterRatio for enterFrames frames. */
|
|
105
|
+
enterRatio: number;
|
|
106
|
+
/**
|
|
107
|
+
* Exit hysteresis: sub-exit frames only count once energy < floor ×
|
|
108
|
+
* exitRatio. The floor is a LOW-percentile tracker, so steady room
|
|
109
|
+
* noise runs ~1.8–2.3× above it — exitRatio must sit above that band
|
|
110
|
+
* (and below enterRatio) or silence never registers.
|
|
111
|
+
*/
|
|
112
|
+
exitRatio: number;
|
|
113
|
+
/** Consecutive supra-enter frames required to enter speech. */
|
|
114
|
+
enterFrames: number;
|
|
115
|
+
/** Sub-exit dwell required to leave speech (ms). */
|
|
116
|
+
hangoverMs: number;
|
|
117
|
+
/**
|
|
118
|
+
* Dip-starved rebaseline: real speech dips below enterRatio × floor
|
|
119
|
+
* between syllables; a "speech" that stays strongly above the floor
|
|
120
|
+
* for this long with zero dips is a shifted noise floor — adopt it
|
|
121
|
+
* and exit. Guards against a step change in room noise wedging the
|
|
122
|
+
* VAD open forever (the floor is otherwise frozen while speaking).
|
|
123
|
+
*/
|
|
124
|
+
noiseRebaselineSec: number;
|
|
125
|
+
/** Absolute floor clamp guarding digital silence. */
|
|
126
|
+
floorMin: number;
|
|
127
|
+
}
|
|
128
|
+
declare const DEFAULT_VAD_CONFIG: VadConfig;
|
|
129
|
+
interface NucleiConfig {
|
|
130
|
+
/** One-pole low-pass cutoff for the amplitude envelope (Hz). */
|
|
131
|
+
envelopeHz: number;
|
|
132
|
+
/** Minimum spacing between accepted syllable onsets (ms) — caps ~8.3 syl/s. */
|
|
133
|
+
minInterOnsetMs: number;
|
|
134
|
+
/** Peak must exceed valley-since-last-peak × this ratio. */
|
|
135
|
+
prominenceRatio: number;
|
|
136
|
+
/** Peak must exceed the decaying loudness reference × this fraction. */
|
|
137
|
+
minRelPeak: number;
|
|
138
|
+
/** Decay time constant of the loudness reference (s). */
|
|
139
|
+
peakRefTauSec: number;
|
|
140
|
+
}
|
|
141
|
+
declare const DEFAULT_NUCLEI_CONFIG: NucleiConfig;
|
|
142
|
+
interface PacingConfig {
|
|
143
|
+
/** The user's base speaking rate (words per minute). */
|
|
144
|
+
baseWpm: number;
|
|
145
|
+
/**
|
|
146
|
+
* How strongly the detected voice rate steers the cruise velocity vs.
|
|
147
|
+
* the user's set pace, in [0, 1]. The speaking-cruise velocity is
|
|
148
|
+
* `voiceBlend·voiceRate + (1 − voiceBlend)·baseRate`, so the WPM slider
|
|
149
|
+
* is ALWAYS felt (it never fully cancels) and an under-counting detector
|
|
150
|
+
* can't drag the prompter to a crawl. 1 = pure voice-follow (the old
|
|
151
|
+
* behavior, where WPM only mattered at the clamps); 0 = ignore the voice.
|
|
152
|
+
*/
|
|
153
|
+
voiceBlend: number;
|
|
154
|
+
/** Clamp on the cruise velocity as a fraction of the set pace. */
|
|
155
|
+
minRateMult: number;
|
|
156
|
+
maxRateMult: number;
|
|
157
|
+
/** EMA time constant for the detected syllable rate (s). */
|
|
158
|
+
rateEmaTauSec: number;
|
|
159
|
+
/** Velocity slew time constant while speaking (s). */
|
|
160
|
+
velSlewTauSec: number;
|
|
161
|
+
/** Velocity decay time constant in silence (s) — halted within ~250 ms. */
|
|
162
|
+
haltTauSec: number;
|
|
163
|
+
/** Proportional gain of the forward-only catch-up boost (per syllable behind). */
|
|
164
|
+
kP: number;
|
|
165
|
+
/** Integral gain of the forward-only boost (per syllable·second behind). */
|
|
166
|
+
kI: number;
|
|
167
|
+
/** Anti-windup clamp on the (≤ 0) behind-error integral (syllable·seconds). */
|
|
168
|
+
intClamp: number;
|
|
169
|
+
/** Max fraction the catch-up boost may ADD to the cruise velocity. */
|
|
170
|
+
maxCorrection: number;
|
|
171
|
+
/** Window (words ahead) used for the local expected syllables-per-word. */
|
|
172
|
+
sylWindowWords: number;
|
|
173
|
+
/** Reader-ahead error beyond this hard-resyncs the prompter FORWARD. */
|
|
174
|
+
resyncSyllables: number;
|
|
175
|
+
}
|
|
176
|
+
declare const DEFAULT_PACING_CONFIG: PacingConfig;
|
|
177
|
+
interface AlignConfig {
|
|
178
|
+
/** Fine analysis hop for the offline pass (s). */
|
|
179
|
+
hopSec: number;
|
|
180
|
+
/** Non-speech runs at least this long become GAP events (s). */
|
|
181
|
+
gapMinSec: number;
|
|
182
|
+
/** Sakoe-Chiba band half-width around the live-trace prior (s). */
|
|
183
|
+
bandRadiusSec: number;
|
|
184
|
+
/** Band half-width when no trace exists (s); also floored at 10% of take length. */
|
|
185
|
+
bandRadiusNoTraceSec: number;
|
|
186
|
+
/** Cost weight for |Δt| on syllable↔syllable matches (normalized by band radius). */
|
|
187
|
+
matchTimeWeight: number;
|
|
188
|
+
/** Cost of matching an expected pause slot to a detected syllable (reader didn't pause). */
|
|
189
|
+
pauseToSylCost: number;
|
|
190
|
+
/** Cost of matching an expected syllable slot to a detected gap (mid-sentence hesitation). */
|
|
191
|
+
sylToGapCost: number;
|
|
192
|
+
/** Cost of skipping an expected slot (merged/unspoken syllable). */
|
|
193
|
+
deleteCost: number;
|
|
194
|
+
/** Cost of skipping a detected event (filler word, breath, click). */
|
|
195
|
+
insertCost: number;
|
|
196
|
+
/** Snap a block start to a silence-gap end within this window before it (s). */
|
|
197
|
+
blockSnapWindowSec: number;
|
|
198
|
+
/** Padding after the last speech for the final block's end (s). */
|
|
199
|
+
tailPadSec: number;
|
|
200
|
+
}
|
|
201
|
+
declare const DEFAULT_ALIGN_CONFIG: AlignConfig;
|
|
202
|
+
/** Refined timestamp of one script token. */
|
|
203
|
+
interface WordTiming {
|
|
204
|
+
tokenIndex: number;
|
|
205
|
+
/** Seconds into the take when the word begins. Monotonically non-decreasing. */
|
|
206
|
+
tSec: number;
|
|
207
|
+
/** True when this word had no matched syllable and was interpolated. */
|
|
208
|
+
interpolated: boolean;
|
|
209
|
+
}
|
|
210
|
+
/** Narration time range of one doc block. Ranges are CONTIGUOUS: endSec === next.startSec. */
|
|
211
|
+
interface NarrationBlockRange {
|
|
212
|
+
blockId: string;
|
|
213
|
+
heading?: string;
|
|
214
|
+
blockIndex: number;
|
|
215
|
+
charStart: number;
|
|
216
|
+
charEnd: number;
|
|
217
|
+
startSec: number;
|
|
218
|
+
endSec: number;
|
|
219
|
+
}
|
|
220
|
+
interface NarrationAlignment {
|
|
221
|
+
/** One entry per script token, monotonic in time. */
|
|
222
|
+
words: WordTiming[];
|
|
223
|
+
blocks: NarrationBlockRange[];
|
|
224
|
+
/** Total syllable onsets detected in the take (diagnostics). */
|
|
225
|
+
detectedSyllables: number;
|
|
226
|
+
/** Total DTW path cost (diagnostics/QA). */
|
|
227
|
+
cost: number;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Deterministic English-oriented syllable estimation.
|
|
232
|
+
*
|
|
233
|
+
* Approximation limits (accepted by design): ±1 on roughly 15% of
|
|
234
|
+
* English words; systematically wrong on loanwords ("cafe", "naive"),
|
|
235
|
+
* some vowel-hiatus words ("create", "quiet"), and non-English text.
|
|
236
|
+
* Every consumer tolerates per-word error — the pacing controller
|
|
237
|
+
* smooths rates and anchors on cumulative sums, and the aligner pays
|
|
238
|
+
* symmetric insert/delete costs — so the estimator only needs to be
|
|
239
|
+
* unbiased on average. Exact outputs are part of the deterministic
|
|
240
|
+
* contract (tests pin a corpus table).
|
|
241
|
+
*/
|
|
242
|
+
/**
|
|
243
|
+
* Estimate the syllable count of a single whitespace-delimited token.
|
|
244
|
+
* Always ≥ 1 for non-empty tokens.
|
|
245
|
+
*/
|
|
246
|
+
declare function estimateSyllables(token: string): number;
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Teleprompter script model: a Doc flattened into an ordered word-token
|
|
250
|
+
* stream with per-block ranges.
|
|
251
|
+
*
|
|
252
|
+
* `sourceText` is the canonical narration text — it is stored verbatim
|
|
253
|
+
* in the timing sidecar, and every token/block `charOffset` indexes into
|
|
254
|
+
* it. Determinism matters: the same Doc always builds a byte-identical
|
|
255
|
+
* script, because sidecar↔doc matching later compares slices of this
|
|
256
|
+
* exact string.
|
|
257
|
+
*/
|
|
258
|
+
|
|
259
|
+
interface BuildScriptOptions {
|
|
260
|
+
/** Include block headings as spoken text (readers usually speak them). Default true. */
|
|
261
|
+
includeTitles?: boolean;
|
|
262
|
+
/** Separator joining block texts inside `sourceText`. Default '\n\n'. */
|
|
263
|
+
blockSeparator?: string;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Build the narration script for a doc. Blocks with no spoken text
|
|
267
|
+
* (pure-media sections, container-template children) contribute no
|
|
268
|
+
* tokens and no block range.
|
|
269
|
+
*/
|
|
270
|
+
declare function buildNarrationScript(doc: Doc, options?: BuildScriptOptions): NarrationScript;
|
|
271
|
+
/**
|
|
272
|
+
* Expected cumulative syllables at a (fractional) word position —
|
|
273
|
+
* linear interpolation over the prefix sums.
|
|
274
|
+
*/
|
|
275
|
+
declare function expectedSyllablesAt(script: NarrationScript, wordPos: number): number;
|
|
276
|
+
/**
|
|
277
|
+
* Inverse of {@link expectedSyllablesAt}: the fractional word position at
|
|
278
|
+
* which the script reaches `syllables` cumulative syllables. Used by the
|
|
279
|
+
* pacing controller's hard resync.
|
|
280
|
+
*/
|
|
281
|
+
declare function wordPosAtExpectedSyllables(script: NarrationScript, syllables: number): number;
|
|
282
|
+
/** Index of the token containing (or following) a char offset into sourceText. */
|
|
283
|
+
declare function wordIndexAtChar(script: NarrationScript, charOffset: number): number;
|
|
284
|
+
/**
|
|
285
|
+
* Index of the active word at a playback time, given aligned word
|
|
286
|
+
* timings — the last word whose `tSec` ≤ `tSec` (or 0 before the first).
|
|
287
|
+
*/
|
|
288
|
+
declare function wordIndexAtTime(words: WordTiming[], tSec: number): number;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Frame feature extraction: full-band RMS, speech-band energy, and
|
|
292
|
+
* zero-crossing rate over hopped (possibly overlapping) frames.
|
|
293
|
+
*
|
|
294
|
+
* Band energy uses two cascaded RBJ biquads — a high-pass at
|
|
295
|
+
* `bandLowHz` and a low-pass at `bandHighHz` (both Q = 1/√2,
|
|
296
|
+
* Audio-EQ-Cookbook closed forms) — rather than an FFT or Goertzel
|
|
297
|
+
* bins: a Butterworth-ish cascade gives a true maximally-flat band in
|
|
298
|
+
* one O(N) pass, and the filter state persists across hops, which is
|
|
299
|
+
* exactly right for streaming (no window-boundary energy jitter).
|
|
300
|
+
* Goertzel measures single frequencies (DTMF-style) — wrong tool for
|
|
301
|
+
* broadband speech energy.
|
|
302
|
+
*/
|
|
303
|
+
|
|
304
|
+
interface BiquadCoeffs {
|
|
305
|
+
b0: number;
|
|
306
|
+
b1: number;
|
|
307
|
+
b2: number;
|
|
308
|
+
a1: number;
|
|
309
|
+
a2: number;
|
|
310
|
+
}
|
|
311
|
+
interface BiquadState {
|
|
312
|
+
x1: number;
|
|
313
|
+
x2: number;
|
|
314
|
+
y1: number;
|
|
315
|
+
y2: number;
|
|
316
|
+
}
|
|
317
|
+
interface BandpassState {
|
|
318
|
+
coeffs: {
|
|
319
|
+
hp: BiquadCoeffs;
|
|
320
|
+
lp: BiquadCoeffs;
|
|
321
|
+
};
|
|
322
|
+
hp: BiquadState;
|
|
323
|
+
lp: BiquadState;
|
|
324
|
+
}
|
|
325
|
+
/** Create bandpass state for a sample rate (corners derived at init). */
|
|
326
|
+
declare function createBandpass(sampleRate: number, lowHz?: number, highHz?: number): BandpassState;
|
|
327
|
+
/**
|
|
328
|
+
* Run the bandpass over a chunk. Pure in the state: returns a NEW state,
|
|
329
|
+
* writes filtered samples into `output` (may alias `input`).
|
|
330
|
+
*/
|
|
331
|
+
declare function bandpassRun(state: BandpassState, input: Float32Array, output: Float32Array): BandpassState;
|
|
332
|
+
interface FeatureState {
|
|
333
|
+
sampleRate: number;
|
|
334
|
+
config: FeatureConfig;
|
|
335
|
+
/** Hop between frame starts, in samples. */
|
|
336
|
+
hopSamples: number;
|
|
337
|
+
bandpass: BandpassState;
|
|
338
|
+
/** Unconsumed raw samples (the next frame's prefix). */
|
|
339
|
+
rawCarry: Float32Array;
|
|
340
|
+
/** Bandpassed twin of `rawCarry`. */
|
|
341
|
+
bandCarry: Float32Array;
|
|
342
|
+
/** Absolute sample index of `rawCarry[0]` from the start of the signal. */
|
|
343
|
+
carryStartSample: number;
|
|
344
|
+
}
|
|
345
|
+
declare function createFeatureState(sampleRate: number, config?: Partial<FeatureConfig>): FeatureState;
|
|
346
|
+
/**
|
|
347
|
+
* Feed a hop of PCM. Returns a new state plus every complete frame the
|
|
348
|
+
* buffered signal now covers (usually 0–1 for worklet-sized hops, more
|
|
349
|
+
* for large chunks).
|
|
350
|
+
*/
|
|
351
|
+
declare function featureStep(state: FeatureState, hop: Float32Array): {
|
|
352
|
+
state: FeatureState;
|
|
353
|
+
frames: FrameFeatures[];
|
|
354
|
+
};
|
|
355
|
+
/** Batch feature extraction over a whole take (the aligner's entry point). */
|
|
356
|
+
declare function extractFrameFeatures(pcm: Float32Array, sampleRate: number, config?: Partial<FeatureConfig>): FrameFeatures[];
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Adaptive voice-activity detection over frame features.
|
|
360
|
+
*
|
|
361
|
+
* The noise floor is an asymmetric EMA of band energy that hugs minima
|
|
362
|
+
* (≈ a 5th-percentile tracker): fast attack toward quieter frames, slow
|
|
363
|
+
* release upward, and FROZEN upward while speaking so long speech can't
|
|
364
|
+
* inflate it. Speech enters via a ratio threshold with a
|
|
365
|
+
* consecutive-frame debounce and exits after a continuous sub-exit
|
|
366
|
+
* dwell (hangover) — the hangover also bridges trailing fricatives and
|
|
367
|
+
* inter-word dips. A dip-starved rebaseline escape keeps a step change
|
|
368
|
+
* in room noise from wedging the detector open: real speech dips below
|
|
369
|
+
* the enter threshold between syllables, steady noise never does.
|
|
370
|
+
*/
|
|
371
|
+
|
|
372
|
+
interface VadState {
|
|
373
|
+
/** Adaptive noise-floor estimate (band-energy units). */
|
|
374
|
+
noiseFloor: number;
|
|
375
|
+
/** The VAD decision — the stage's output. */
|
|
376
|
+
speaking: boolean;
|
|
377
|
+
/** Consecutive supra-enter frames observed while silent. */
|
|
378
|
+
enterStreak: number;
|
|
379
|
+
/** tSec when the current sub-exit dwell began (while speaking), else null. */
|
|
380
|
+
subExitSince: number | null;
|
|
381
|
+
/** tSec when the current zero-dip run began (while speaking), else null. */
|
|
382
|
+
noDipSince: number | null;
|
|
383
|
+
/** No speech decisions before this time (floor seeding). */
|
|
384
|
+
warmupUntilSec: number;
|
|
385
|
+
/** False until the first frame seeds the floor. */
|
|
386
|
+
seeded: boolean;
|
|
387
|
+
lastTSec: number;
|
|
388
|
+
}
|
|
389
|
+
declare function createVadState(config?: Partial<VadConfig>): VadState;
|
|
390
|
+
/** Pure per-frame step. `state.speaking` on the returned state is the decision for this frame. */
|
|
391
|
+
declare function vadStep(state: VadState, frame: FrameFeatures, config?: Partial<VadConfig>): VadState;
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Syllable-nuclei detection: vowel nuclei show up as peaks in a
|
|
395
|
+
* low-passed amplitude envelope of the speech-band signal.
|
|
396
|
+
*
|
|
397
|
+
* Envelope = one-pole low-pass (≈10 Hz) over √bandEnergy (amplitude
|
|
398
|
+
* domain, so peaks are nuclei rather than energy spikes). A peak is
|
|
399
|
+
* emitted one frame late (local-max needs one frame of lookahead —
|
|
400
|
+
* ~20 ms live latency) and accepted only when: VAD says speaking, it
|
|
401
|
+
* clears the minimum inter-onset spacing, it is prominent relative to
|
|
402
|
+
* the valley since the last accepted peak, and it clears a decaying
|
|
403
|
+
* loudness reference (guards against ripples inside quiet speech).
|
|
404
|
+
*/
|
|
405
|
+
|
|
406
|
+
interface NucleiState {
|
|
407
|
+
/** One-pole envelope of √bandEnergy. */
|
|
408
|
+
env: number;
|
|
409
|
+
prevEnv: number;
|
|
410
|
+
prevPrevEnv: number;
|
|
411
|
+
/** tSec of the previous frame (the peak-candidate time). */
|
|
412
|
+
prevTSec: number;
|
|
413
|
+
/** Envelope minimum since the last accepted peak. */
|
|
414
|
+
valley: number;
|
|
415
|
+
lastOnsetTSec: number;
|
|
416
|
+
/** Decaying loudness reference. */
|
|
417
|
+
peakRef: number;
|
|
418
|
+
lastTSec: number;
|
|
419
|
+
framesSeen: number;
|
|
420
|
+
}
|
|
421
|
+
declare function createNucleiState(_config?: Partial<NucleiConfig>): NucleiState;
|
|
422
|
+
/**
|
|
423
|
+
* Pure per-frame step. `onset` is the tSec of a newly accepted syllable
|
|
424
|
+
* nucleus (emitted once, at its peak frame), or null.
|
|
425
|
+
*/
|
|
426
|
+
declare function nucleiStep(state: NucleiState, frame: FrameFeatures, speaking: boolean, config?: Partial<NucleiConfig>): {
|
|
427
|
+
state: NucleiState;
|
|
428
|
+
onset: number | null;
|
|
429
|
+
};
|
|
430
|
+
/** Batch wrapper for the offline aligner. `vadFlags[i]` pairs with `frames[i]`. */
|
|
431
|
+
declare function detectSyllableOnsets(frames: FrameFeatures[], vadFlags: boolean[], config?: Partial<NucleiConfig>): number[];
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* The teleprompter pacing controller.
|
|
435
|
+
*
|
|
436
|
+
* A pure, deterministic step function: given the current state, one
|
|
437
|
+
* analysis tick (VAD flag + syllable onsets), and the script, produce
|
|
438
|
+
* the next state. The prompter position (`wordPos`) advances at a
|
|
439
|
+
* velocity that (a) halts within ~250 ms of silence, (b) tracks the
|
|
440
|
+
* reader's detected syllable rate while speaking, and (c) is corrected
|
|
441
|
+
* by a PI loop on cumulative detected-vs-expected syllables so the
|
|
442
|
+
* highlight can't drift arbitrarily far from the voice. Silence near an
|
|
443
|
+
* expected paragraph/block break is legitimate and accrues no error.
|
|
444
|
+
*/
|
|
445
|
+
|
|
446
|
+
interface PacingTick {
|
|
447
|
+
tSec: number;
|
|
448
|
+
speaking: boolean;
|
|
449
|
+
/** Syllable onsets detected in this tick (0 or 1 for frame-sized ticks). */
|
|
450
|
+
onsets: number;
|
|
451
|
+
}
|
|
452
|
+
interface PacingState {
|
|
453
|
+
/** Fractional word position — the active token is `floor(wordPos)`. */
|
|
454
|
+
wordPos: number;
|
|
455
|
+
/** Current scroll velocity in words per second. */
|
|
456
|
+
velocityWps: number;
|
|
457
|
+
/** EMA of the detected syllable rate (syl/s); 0 until two onsets arrive. */
|
|
458
|
+
emaSylPerSec: number;
|
|
459
|
+
lastOnsetTSec: number | null;
|
|
460
|
+
/** Syllables detected since the last anchor. */
|
|
461
|
+
cumDetectedSyl: number;
|
|
462
|
+
/** Expected cumulative syllables at the last anchor position. */
|
|
463
|
+
anchorExpectedSyl: number;
|
|
464
|
+
/** PI integral of the cumulative-syllable error (syl·s). */
|
|
465
|
+
errIntegral: number;
|
|
466
|
+
/** Continuous silence observed so far (s). */
|
|
467
|
+
silenceSec: number;
|
|
468
|
+
lastTSec: number | null;
|
|
469
|
+
/** True when silent and fully stopped. */
|
|
470
|
+
halted: boolean;
|
|
471
|
+
}
|
|
472
|
+
declare function createPacingState(startWordPos?: number): PacingState;
|
|
473
|
+
/** Pure controller step — same inputs always yield the same output state. */
|
|
474
|
+
declare function pacingStep(state: PacingState, tick: PacingTick, script: NarrationScript, config?: Partial<PacingConfig>): PacingState;
|
|
475
|
+
/**
|
|
476
|
+
* Re-anchor after a manual nudge/scroll: the new position becomes the
|
|
477
|
+
* zero-error reference. The learned rate EMA survives.
|
|
478
|
+
*/
|
|
479
|
+
declare function reanchorPacing(state: PacingState, wordPos: number, script: NarrationScript): PacingState;
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Live-session composition: one pure call per PCM hop runs feature
|
|
483
|
+
* extraction → VAD → nuclei → pacing. This is the only surface the
|
|
484
|
+
* editor's mic loop needs — feed it worklet batches, read
|
|
485
|
+
* `state.pacing.wordPos` / `state.vad.speaking` / `state.lastFrame`.
|
|
486
|
+
*/
|
|
487
|
+
|
|
488
|
+
interface NarrationSessionConfig {
|
|
489
|
+
feature?: Partial<FeatureConfig>;
|
|
490
|
+
vad?: Partial<VadConfig>;
|
|
491
|
+
nuclei?: Partial<NucleiConfig>;
|
|
492
|
+
pacing?: Partial<PacingConfig>;
|
|
493
|
+
}
|
|
494
|
+
interface NarrationSessionState {
|
|
495
|
+
script: NarrationScript;
|
|
496
|
+
config: NarrationSessionConfig;
|
|
497
|
+
features: FeatureState;
|
|
498
|
+
vad: VadState;
|
|
499
|
+
nuclei: NucleiState;
|
|
500
|
+
pacing: PacingState;
|
|
501
|
+
/** Most recent analysis frame — drives the UI level meter. */
|
|
502
|
+
lastFrame: FrameFeatures | null;
|
|
503
|
+
/** Seconds of PCM consumed so far. */
|
|
504
|
+
tSec: number;
|
|
505
|
+
}
|
|
506
|
+
declare function createNarrationSession(sampleRate: number, script: NarrationScript, config?: NarrationSessionConfig): NarrationSessionState;
|
|
507
|
+
/** Feed one hop of mono PCM; every completed frame advances VAD/nuclei/pacing. */
|
|
508
|
+
declare function narrationSessionStep(state: NarrationSessionState, hop: Float32Array): NarrationSessionState;
|
|
509
|
+
/** Manual nudge/scroll: re-anchor the pacing controller at a word position. */
|
|
510
|
+
declare function reanchorSession(state: NarrationSessionState, wordPos: number): NarrationSessionState;
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Live prompter trace: sparse `{ tMs, wordPos }` samples the UI records
|
|
514
|
+
* while the reader records a take (~4 Hz plus one on every re-anchor).
|
|
515
|
+
* The offline aligner uses it as a prior — a Sakoe-Chiba band around
|
|
516
|
+
* the trace keeps the DTW honest and cheap.
|
|
517
|
+
*/
|
|
518
|
+
interface TraceSample {
|
|
519
|
+
tMs: number;
|
|
520
|
+
wordPos: number;
|
|
521
|
+
}
|
|
522
|
+
interface NarrationTrace {
|
|
523
|
+
samples: TraceSample[];
|
|
524
|
+
}
|
|
525
|
+
/** Clamped linear interpolation of the trace at a time. */
|
|
526
|
+
declare function traceWordPosAt(trace: NarrationTrace, tSec: number): number;
|
|
527
|
+
/** Downsample to at most `maxSamples`, always keeping both endpoints. */
|
|
528
|
+
declare function downsampleTrace(trace: NarrationTrace, maxSamples: number): NarrationTrace;
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Offline narration alignment: refine word/block timestamps from a
|
|
532
|
+
* recorded take.
|
|
533
|
+
*
|
|
534
|
+
* Pipeline: fine-hop features → VAD flags → syllable onsets + silence
|
|
535
|
+
* gaps (the DETECTED event sequence) vs. the script's expected
|
|
536
|
+
* syllable/pause slots (the EXPECTED sequence), aligned with a banded
|
|
537
|
+
* DTW. The band (Sakoe-Chiba style) follows the live prompter trace
|
|
538
|
+
* when one exists — the trace is what the reader actually saw — and a
|
|
539
|
+
* proportional prior otherwise. Matched slots yield word timestamps;
|
|
540
|
+
* block starts snap to the end of the breath gap readers take before a
|
|
541
|
+
* heading; block ranges are made CONTIGUOUS because downstream preview
|
|
542
|
+
* building re-derives start times from durations.
|
|
543
|
+
*/
|
|
544
|
+
|
|
545
|
+
interface AlignInput {
|
|
546
|
+
/** Mono PCM of the whole take. */
|
|
547
|
+
pcm: Float32Array;
|
|
548
|
+
sampleRate: number;
|
|
549
|
+
script: NarrationScript;
|
|
550
|
+
/** Live prompter trace recorded during the take, if any. */
|
|
551
|
+
trace?: NarrationTrace;
|
|
552
|
+
}
|
|
553
|
+
declare function alignNarration(input: AlignInput, config?: Partial<AlignConfig>): NarrationAlignment;
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Narration timing sidecar v3 — the extended `<audio>.timing.json`.
|
|
557
|
+
*
|
|
558
|
+
* v1 (the recorder's original shape) is `{ sourceText, duration,
|
|
559
|
+
* bookmarks }` with bookmarks always empty. v3 fills the bookmarks with
|
|
560
|
+
* real per-word timings from the aligner and adds contiguous per-block
|
|
561
|
+
* ranges. `version: 2` is already taken by the consolidated root
|
|
562
|
+
* `timing.json` (`{ version: 2, sections }`), hence v3.
|
|
563
|
+
*
|
|
564
|
+
* Compatibility contract (tested in both directions): v3 is a strict
|
|
565
|
+
* superset of v1, so the legacy `parseTimingJson` gate (requires
|
|
566
|
+
* `sourceText` + `duration`, ignores unknown keys) keeps accepting v3
|
|
567
|
+
* files; {@link parseNarrationTimingJson} accepts v1 files and returns
|
|
568
|
+
* them with empty `blocks`.
|
|
569
|
+
*/
|
|
570
|
+
|
|
571
|
+
/** Narration time range of one doc block at record time. */
|
|
572
|
+
interface NarrationTimingBlock {
|
|
573
|
+
/** Doc block id at record time (primary match key; ids can drift on heading edits). */
|
|
574
|
+
blockId?: string;
|
|
575
|
+
/** Block heading at record time (human-readable + fuzzy match key). */
|
|
576
|
+
heading?: string;
|
|
577
|
+
/** Index in renderable-block order at record time. */
|
|
578
|
+
blockIndex: number;
|
|
579
|
+
/** Char range into `sourceText` — the durable content key. */
|
|
580
|
+
charStart: number;
|
|
581
|
+
charEnd: number;
|
|
582
|
+
startSec: number;
|
|
583
|
+
/** Contiguous with the next block's startSec (aligner invariant). */
|
|
584
|
+
endSec: number;
|
|
585
|
+
}
|
|
586
|
+
interface NarrationTimingJsonV3 {
|
|
587
|
+
version: 3;
|
|
588
|
+
/** EXACTLY the NarrationScript.sourceText of the take. */
|
|
589
|
+
sourceText: string;
|
|
590
|
+
/** Take length in seconds (decoded-PCM length, not the recorder clock). */
|
|
591
|
+
duration: number;
|
|
592
|
+
/** Per-word timings: { id: `word-${i}`, time, charOffset, textFragment }. */
|
|
593
|
+
bookmarks: AudioBookmark[];
|
|
594
|
+
blocks: NarrationTimingBlock[];
|
|
595
|
+
/** Start skew of the companion camera recording, when one exists. */
|
|
596
|
+
cameraOffsetSec?: number;
|
|
597
|
+
/** Provenance of the timing data. */
|
|
598
|
+
generator?: {
|
|
599
|
+
name: string;
|
|
600
|
+
method: 'dsp-align';
|
|
601
|
+
baseWpm?: number;
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
interface BuildNarrationTimingOptions {
|
|
605
|
+
cameraOffsetSec?: number;
|
|
606
|
+
baseWpm?: number;
|
|
607
|
+
}
|
|
608
|
+
/** Build the v3 sidecar payload from a script + its alignment. Pure. */
|
|
609
|
+
declare function buildNarrationTimingJson(script: NarrationScript, alignment: NarrationAlignment, durationSec: number, options?: BuildNarrationTimingOptions): NarrationTimingJsonV3;
|
|
610
|
+
/**
|
|
611
|
+
* Tolerant parse: accepts v3, and v1 (`{ sourceText, duration,
|
|
612
|
+
* bookmarks? }`) which comes back with empty `blocks`. Returns null for
|
|
613
|
+
* malformed payloads. Blocks are sorted and clamped monotonic
|
|
614
|
+
* defensively (hand-edited sidecars).
|
|
615
|
+
*/
|
|
616
|
+
declare function parseNarrationTimingJson(data: ArrayBuffer | Uint8Array | string): NarrationTimingJsonV3 | null;
|
|
617
|
+
|
|
618
|
+
export { type AlignConfig, type AlignInput, type BandpassState, type BuildNarrationTimingOptions, type BuildScriptOptions, DEFAULT_ALIGN_CONFIG, DEFAULT_FEATURE_CONFIG, DEFAULT_NUCLEI_CONFIG, DEFAULT_PACING_CONFIG, DEFAULT_VAD_CONFIG, type FeatureConfig, type FeatureState, type FrameFeatures, type NarrationAlignment, type NarrationBlockRange, type NarrationScript, type NarrationSessionConfig, type NarrationSessionState, type NarrationTimingBlock, type NarrationTimingJsonV3, type NarrationTrace, type NucleiConfig, type NucleiState, type PacingConfig, type PacingState, type PacingTick, type ScriptBlockRange, type ScriptToken, type TraceSample, type VadConfig, type VadState, type WordTiming, alignNarration, bandpassRun, buildNarrationScript, buildNarrationTimingJson, createBandpass, createFeatureState, createNarrationSession, createNucleiState, createPacingState, createVadState, detectSyllableOnsets, downsampleTrace, estimateSyllables, expectedSyllablesAt, extractFrameFeatures, featureStep, narrationSessionStep, nucleiStep, pacingStep, parseNarrationTimingJson, reanchorPacing, reanchorSession, traceWordPosAt, vadStep, wordIndexAtChar, wordIndexAtTime, wordPosAtExpectedSyllables };
|