@kvman/kvvideo 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +10 -2
- package/dist/api.d.ts +105 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +2 -0
- package/dist/api.js.map +1 -0
- package/dist/brand/brand.d.ts +17 -0
- package/dist/brand/brand.d.ts.map +1 -0
- package/dist/brand/brand.js +44 -0
- package/dist/brand/brand.js.map +1 -0
- package/dist/browser/channels.d.ts +6 -0
- package/dist/browser/channels.d.ts.map +1 -0
- package/dist/browser/channels.js +5 -0
- package/dist/browser/channels.js.map +1 -0
- package/dist/browser/launch.d.ts +6 -0
- package/dist/browser/launch.d.ts.map +1 -0
- package/dist/browser/launch.js +14 -0
- package/dist/browser/launch.js.map +1 -0
- package/dist/browser/start-browser.d.ts +5 -0
- package/dist/browser/start-browser.d.ts.map +1 -0
- package/dist/browser/start-browser.js +17 -0
- package/dist/browser/start-browser.js.map +1 -0
- package/dist/compose/ass-file.d.ts +17 -0
- package/dist/compose/ass-file.d.ts.map +1 -0
- package/dist/compose/ass-file.js +65 -0
- package/dist/compose/ass-file.js.map +1 -0
- package/dist/compose/background.d.ts +23 -0
- package/dist/compose/background.d.ts.map +1 -0
- package/dist/compose/background.js +31 -0
- package/dist/compose/background.js.map +1 -0
- package/dist/compose/camera.d.ts +32 -0
- package/dist/compose/camera.d.ts.map +1 -0
- package/dist/compose/camera.js +98 -0
- package/dist/compose/camera.js.map +1 -0
- package/dist/compose/caption-font.d.ts +8 -0
- package/dist/compose/caption-font.d.ts.map +1 -0
- package/dist/compose/caption-font.js +24 -0
- package/dist/compose/caption-font.js.map +1 -0
- package/dist/compose/compose-drawing.d.ts +19 -0
- package/dist/compose/compose-drawing.d.ts.map +1 -0
- package/dist/compose/compose-drawing.js +38 -0
- package/dist/compose/compose-drawing.js.map +1 -0
- package/dist/compose/compose-input.d.ts +187 -0
- package/dist/compose/compose-input.d.ts.map +1 -0
- package/dist/compose/compose-input.js +76 -0
- package/dist/compose/compose-input.js.map +1 -0
- package/dist/compose/compose-plan.d.ts +36 -0
- package/dist/compose/compose-plan.d.ts.map +1 -0
- package/dist/compose/compose-plan.js +55 -0
- package/dist/compose/compose-plan.js.map +1 -0
- package/dist/compose/compose-size.d.ts +50 -0
- package/dist/compose/compose-size.d.ts.map +1 -0
- package/dist/compose/compose-size.js +72 -0
- package/dist/compose/compose-size.js.map +1 -0
- package/dist/compose/drawn-images.d.ts +19 -0
- package/dist/compose/drawn-images.d.ts.map +1 -0
- package/dist/compose/drawn-images.js +75 -0
- package/dist/compose/drawn-images.js.map +1 -0
- package/dist/compose/final-pass.d.ts +34 -0
- package/dist/compose/final-pass.d.ts.map +1 -0
- package/dist/compose/final-pass.js +106 -0
- package/dist/compose/final-pass.js.map +1 -0
- package/dist/compose/frame-layout.d.ts +30 -0
- package/dist/compose/frame-layout.d.ts.map +1 -0
- package/dist/compose/frame-layout.js +33 -0
- package/dist/compose/frame-layout.js.map +1 -0
- package/dist/compose/overlays.d.ts +20 -0
- package/dist/compose/overlays.d.ts.map +1 -0
- package/dist/compose/overlays.js +30 -0
- package/dist/compose/overlays.js.map +1 -0
- package/dist/compose/page-again.d.ts +26 -0
- package/dist/compose/page-again.d.ts.map +1 -0
- package/dist/compose/page-again.js +50 -0
- package/dist/compose/page-again.js.map +1 -0
- package/dist/compose/player-copies.d.ts +10 -0
- package/dist/compose/player-copies.d.ts.map +1 -0
- package/dist/compose/player-copies.js +34 -0
- package/dist/compose/player-copies.js.map +1 -0
- package/dist/compose/register-compose.d.ts +3 -0
- package/dist/compose/register-compose.d.ts.map +1 -0
- package/dist/compose/register-compose.js +151 -0
- package/dist/compose/register-compose.js.map +1 -0
- package/dist/compose/render.d.ts +25 -0
- package/dist/compose/render.d.ts.map +1 -0
- package/dist/compose/render.js +61 -0
- package/dist/compose/render.js.map +1 -0
- package/dist/compose/scene-args.d.ts +37 -0
- package/dist/compose/scene-args.d.ts.map +1 -0
- package/dist/compose/scene-args.js +103 -0
- package/dist/compose/scene-args.js.map +1 -0
- package/dist/compose/scene-look.d.ts +31 -0
- package/dist/compose/scene-look.d.ts.map +1 -0
- package/dist/compose/scene-look.js +46 -0
- package/dist/compose/scene-look.js.map +1 -0
- package/dist/compose/scene-plan.d.ts +26 -0
- package/dist/compose/scene-plan.d.ts.map +1 -0
- package/dist/compose/scene-plan.js +34 -0
- package/dist/compose/scene-plan.js.map +1 -0
- package/dist/compose/sound-effects.d.ts +23 -0
- package/dist/compose/sound-effects.d.ts.map +1 -0
- package/dist/compose/sound-effects.js +40 -0
- package/dist/compose/sound-effects.js.map +1 -0
- package/dist/compose/srt.d.ts +3 -0
- package/dist/compose/srt.d.ts.map +1 -0
- package/dist/compose/srt.js +10 -0
- package/dist/compose/srt.js.map +1 -0
- package/dist/compose/transitions.d.ts +16 -0
- package/dist/compose/transitions.d.ts.map +1 -0
- package/dist/compose/transitions.js +38 -0
- package/dist/compose/transitions.js.map +1 -0
- package/dist/connector.d.ts +132 -0
- package/dist/connector.d.ts.map +1 -0
- package/dist/connector.js +63 -0
- package/dist/connector.js.map +1 -0
- package/dist/files/answer-path.d.ts +3 -0
- package/dist/files/answer-path.d.ts.map +1 -0
- package/dist/files/answer-path.js +6 -0
- package/dist/files/answer-path.js.map +1 -0
- package/dist/files/place-output.d.ts +8 -0
- package/dist/files/place-output.d.ts.map +1 -0
- package/dist/files/place-output.js +24 -0
- package/dist/files/place-output.js.map +1 -0
- package/dist/files/sidecar.d.ts +209 -0
- package/dist/files/sidecar.d.ts.map +1 -0
- package/dist/files/sidecar.js +66 -0
- package/dist/files/sidecar.js.map +1 -0
- package/dist/files/workspace-paths.d.ts +7 -0
- package/dist/files/workspace-paths.d.ts.map +1 -0
- package/dist/files/workspace-paths.js +48 -0
- package/dist/files/workspace-paths.js.map +1 -0
- package/dist/fonts/bundled-fonts.d.ts +10 -0
- package/dist/fonts/bundled-fonts.d.ts.map +1 -0
- package/dist/fonts/bundled-fonts.js +10 -0
- package/dist/fonts/bundled-fonts.js.map +1 -0
- package/dist/fonts/font-family.d.ts +2 -0
- package/dist/fonts/font-family.d.ts.map +1 -0
- package/dist/fonts/font-family.js +43 -0
- package/dist/fonts/font-family.js.map +1 -0
- package/dist/fonts/register-fonts.d.ts +3 -0
- package/dist/fonts/register-fonts.d.ts.map +1 -0
- package/dist/fonts/register-fonts.js +12 -0
- package/dist/fonts/register-fonts.js.map +1 -0
- package/dist/guide.d.ts +3 -0
- package/dist/guide.d.ts.map +1 -0
- package/dist/guide.js +6 -0
- package/dist/guide.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/narration/alignment.d.ts +15 -0
- package/dist/narration/alignment.d.ts.map +1 -0
- package/dist/narration/alignment.js +21 -0
- package/dist/narration/alignment.js.map +1 -0
- package/dist/narration/captions.d.ts +28 -0
- package/dist/narration/captions.d.ts.map +1 -0
- package/dist/narration/captions.js +70 -0
- package/dist/narration/captions.js.map +1 -0
- package/dist/narration/join-args.d.ts +3 -0
- package/dist/narration/join-args.d.ts.map +1 -0
- package/dist/narration/join-args.js +19 -0
- package/dist/narration/join-args.js.map +1 -0
- package/dist/narration/narration-cache.d.ts +25 -0
- package/dist/narration/narration-cache.d.ts.map +1 -0
- package/dist/narration/narration-cache.js +36 -0
- package/dist/narration/narration-cache.js.map +1 -0
- package/dist/narration/piper.d.ts +4 -0
- package/dist/narration/piper.d.ts.map +1 -0
- package/dist/narration/piper.js +13 -0
- package/dist/narration/piper.js.map +1 -0
- package/dist/narration/pronunciations.d.ts +11 -0
- package/dist/narration/pronunciations.d.ts.map +1 -0
- package/dist/narration/pronunciations.js +40 -0
- package/dist/narration/pronunciations.js.map +1 -0
- package/dist/narration/register-narration.d.ts +25 -0
- package/dist/narration/register-narration.d.ts.map +1 -0
- package/dist/narration/register-narration.js +103 -0
- package/dist/narration/register-narration.js.map +1 -0
- package/dist/narration/register-voice.d.ts +27 -0
- package/dist/narration/register-voice.d.ts.map +1 -0
- package/dist/narration/register-voice.js +82 -0
- package/dist/narration/register-voice.js.map +1 -0
- package/dist/narration/sentence-speaker.d.ts +35 -0
- package/dist/narration/sentence-speaker.d.ts.map +1 -0
- package/dist/narration/sentence-speaker.js +44 -0
- package/dist/narration/sentence-speaker.js.map +1 -0
- package/dist/narration/speech-services.d.ts +39 -0
- package/dist/narration/speech-services.d.ts.map +1 -0
- package/dist/narration/speech-services.js +67 -0
- package/dist/narration/speech-services.js.map +1 -0
- package/dist/narration/voice-args.d.ts +3 -0
- package/dist/narration/voice-args.d.ts.map +1 -0
- package/dist/narration/voice-args.js +10 -0
- package/dist/narration/voice-args.js.map +1 -0
- package/dist/problems.d.ts +12 -0
- package/dist/problems.d.ts.map +1 -0
- package/dist/problems.js +19 -0
- package/dist/problems.js.map +1 -0
- package/dist/programs/kill-tree.d.ts +16 -0
- package/dist/programs/kill-tree.d.ts.map +1 -0
- package/dist/programs/kill-tree.js +28 -0
- package/dist/programs/kill-tree.js.map +1 -0
- package/dist/programs/media-duration.d.ts +22 -0
- package/dist/programs/media-duration.d.ts.map +1 -0
- package/dist/programs/media-duration.js +23 -0
- package/dist/programs/media-duration.js.map +1 -0
- package/dist/programs/piped-program.d.ts +7 -0
- package/dist/programs/piped-program.d.ts.map +1 -0
- package/dist/programs/piped-program.js +45 -0
- package/dist/programs/piped-program.js.map +1 -0
- package/dist/programs/programs.d.ts +6 -0
- package/dist/programs/programs.d.ts.map +1 -0
- package/dist/programs/programs.js +6 -0
- package/dist/programs/programs.js.map +1 -0
- package/dist/programs/run-program.d.ts +23 -0
- package/dist/programs/run-program.d.ts.map +1 -0
- package/dist/programs/run-program.js +47 -0
- package/dist/programs/run-program.js.map +1 -0
- package/dist/record/address.d.ts +5 -0
- package/dist/record/address.d.ts.map +1 -0
- package/dist/record/address.js +26 -0
- package/dist/record/address.js.map +1 -0
- package/dist/record/cursor-script.d.ts +3 -0
- package/dist/record/cursor-script.d.ts.map +1 -0
- package/dist/record/cursor-script.js +59 -0
- package/dist/record/cursor-script.js.map +1 -0
- package/dist/record/encoder-args.d.ts +3 -0
- package/dist/record/encoder-args.d.ts.map +1 -0
- package/dist/record/encoder-args.js +13 -0
- package/dist/record/encoder-args.js.map +1 -0
- package/dist/record/frame-writer.d.ts +8 -0
- package/dist/record/frame-writer.d.ts.map +1 -0
- package/dist/record/frame-writer.js +30 -0
- package/dist/record/frame-writer.js.map +1 -0
- package/dist/record/motion.d.ts +19 -0
- package/dist/record/motion.d.ts.map +1 -0
- package/dist/record/motion.js +59 -0
- package/dist/record/motion.js.map +1 -0
- package/dist/record/narration-cues.d.ts +14 -0
- package/dist/record/narration-cues.d.ts.map +1 -0
- package/dist/record/narration-cues.js +12 -0
- package/dist/record/narration-cues.js.map +1 -0
- package/dist/record/own-port.d.ts +2 -0
- package/dist/record/own-port.d.ts.map +1 -0
- package/dist/record/own-port.js +23 -0
- package/dist/record/own-port.js.map +1 -0
- package/dist/record/page-ready.d.ts +4 -0
- package/dist/record/page-ready.d.ts.map +1 -0
- package/dist/record/page-ready.js +15 -0
- package/dist/record/page-ready.js.map +1 -0
- package/dist/record/page-route.d.ts +13 -0
- package/dist/record/page-route.d.ts.map +1 -0
- package/dist/record/page-route.js +64 -0
- package/dist/record/page-route.js.map +1 -0
- package/dist/record/pointer.d.ts +8 -0
- package/dist/record/pointer.d.ts.map +1 -0
- package/dist/record/pointer.js +24 -0
- package/dist/record/pointer.js.map +1 -0
- package/dist/record/recorder.d.ts +34 -0
- package/dist/record/recorder.d.ts.map +1 -0
- package/dist/record/recorder.js +99 -0
- package/dist/record/recorder.js.map +1 -0
- package/dist/record/register-record.d.ts +3 -0
- package/dist/record/register-record.d.ts.map +1 -0
- package/dist/record/register-record.js +83 -0
- package/dist/record/register-record.js.map +1 -0
- package/dist/record/run-step.d.ts +20 -0
- package/dist/record/run-step.d.ts.map +1 -0
- package/dist/record/run-step.js +69 -0
- package/dist/record/run-step.js.map +1 -0
- package/dist/record/screencast.d.ts +9 -0
- package/dist/record/screencast.d.ts.map +1 -0
- package/dist/record/screencast.js +38 -0
- package/dist/record/screencast.js.map +1 -0
- package/dist/record/steps.d.ts +124 -0
- package/dist/record/steps.d.ts.map +1 -0
- package/dist/record/steps.js +47 -0
- package/dist/record/steps.js.map +1 -0
- package/dist/register-with-kvcoder.d.ts +3 -0
- package/dist/register-with-kvcoder.d.ts.map +1 -0
- package/dist/register-with-kvcoder.js +15 -0
- package/dist/register-with-kvcoder.js.map +1 -0
- package/dist/review/analysis.d.ts +19 -0
- package/dist/review/analysis.d.ts.map +1 -0
- package/dist/review/analysis.js +36 -0
- package/dist/review/analysis.js.map +1 -0
- package/dist/review/frames.d.ts +9 -0
- package/dist/review/frames.d.ts.map +1 -0
- package/dist/review/frames.js +28 -0
- package/dist/review/frames.js.map +1 -0
- package/dist/review/register-review.d.ts +24 -0
- package/dist/review/register-review.d.ts.map +1 -0
- package/dist/review/register-review.js +81 -0
- package/dist/review/register-review.js.map +1 -0
- package/dist/review/sheet-args.d.ts +11 -0
- package/dist/review/sheet-args.d.ts.map +1 -0
- package/dist/review/sheet-args.js +24 -0
- package/dist/review/sheet-args.js.map +1 -0
- package/dist/settings.d.ts +33 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +29 -0
- package/dist/settings.js.map +1 -0
- package/dist/setup/browser-readiness.d.ts +14 -0
- package/dist/setup/browser-readiness.d.ts.map +1 -0
- package/dist/setup/browser-readiness.js +16 -0
- package/dist/setup/browser-readiness.js.map +1 -0
- package/dist/setup/ffmpeg-readiness.d.ts +19 -0
- package/dist/setup/ffmpeg-readiness.d.ts.map +1 -0
- package/dist/setup/ffmpeg-readiness.js +33 -0
- package/dist/setup/ffmpeg-readiness.js.map +1 -0
- package/dist/setup/narration-readiness.d.ts +21 -0
- package/dist/setup/narration-readiness.d.ts.map +1 -0
- package/dist/setup/narration-readiness.js +18 -0
- package/dist/setup/narration-readiness.js.map +1 -0
- package/dist/setup/register-setup.d.ts +3 -0
- package/dist/setup/register-setup.d.ts.map +1 -0
- package/dist/setup/register-setup.js +51 -0
- package/dist/setup/register-setup.js.map +1 -0
- package/dist/ui.d.ts +3 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +26 -0
- package/dist/ui.js.map +1 -0
- package/dist/video-start.d.ts +3 -0
- package/dist/video-start.d.ts.map +1 -0
- package/dist/video-start.js +28 -0
- package/dist/video-start.js.map +1 -0
- package/dist/web/components/player.css +2 -0
- package/dist/web/components/player.js +55 -0
- package/docs/guide.md +28 -0
- package/fonts/Amiri-Bold.ttf +0 -0
- package/fonts/IBMPlexSansArabic-Bold.ttf +0 -0
- package/fonts/Lato-Bold.ttf +0 -0
- package/fonts/OFL-Amiri.txt +94 -0
- package/fonts/OFL-IBMPlexSansArabic.txt +93 -0
- package/fonts/OFL-Lato.txt +93 -0
- package/fonts/OFL-Poppins.txt +93 -0
- package/fonts/Poppins-Bold.ttf +0 -0
- package/locales/ar.json +48 -0
- package/locales/en.json +48 -0
- package/package.json +73 -3
- package/sounds/SOURCES.md +13 -0
- package/sounds/click.wav +0 -0
- package/sounds/keys.wav +0 -0
- package/sounds/pop.wav +0 -0
- package/sounds/whoosh.wav +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const maximumLine = 42;
|
|
2
|
+
const length = (text) => [...text].length;
|
|
3
|
+
/** The text's sentences, in order: cut at line breaks and after `.`, `!`, `?`, `؟`, and `…` followed by a space. */
|
|
4
|
+
export function sentencesOf(text) {
|
|
5
|
+
return text
|
|
6
|
+
.split(/\r?\n/u)
|
|
7
|
+
.map((line) => line.replace(/\s+/gu, ' ').trim())
|
|
8
|
+
.flatMap((line) => line.split(/(?<=[.!?؟…])\s+/u))
|
|
9
|
+
.filter((sentence) => sentence !== '');
|
|
10
|
+
}
|
|
11
|
+
/** A sentence's caption lines: whole words, each line as long as it can be up to 42 characters. */
|
|
12
|
+
export function linesOf(sentence) {
|
|
13
|
+
const lines = [];
|
|
14
|
+
let current = '';
|
|
15
|
+
for (const word of sentence.split(' ')) {
|
|
16
|
+
const joined = current === '' ? word : `${current} ${word}`;
|
|
17
|
+
if (current !== '' && length(joined) > maximumLine) {
|
|
18
|
+
lines.push(current);
|
|
19
|
+
current = word;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
current = joined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (current !== '')
|
|
26
|
+
lines.push(current);
|
|
27
|
+
return lines;
|
|
28
|
+
}
|
|
29
|
+
// Each line's start, in characters of the sentence, and its words with their starts and ends.
|
|
30
|
+
function lineSpans(sentence) {
|
|
31
|
+
const characters = [...sentence];
|
|
32
|
+
let at = 0;
|
|
33
|
+
return linesOf(sentence).map((line) => {
|
|
34
|
+
while (characters[at] === ' ')
|
|
35
|
+
at += 1;
|
|
36
|
+
const from = at;
|
|
37
|
+
const words = [];
|
|
38
|
+
for (const word of line.split(' ')) {
|
|
39
|
+
words.push({ text: word, from: at, to: at + length(word) - 1 });
|
|
40
|
+
at += length(word) + 1;
|
|
41
|
+
}
|
|
42
|
+
at -= 1;
|
|
43
|
+
return { text: line, from, words };
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function proportional(sentence) {
|
|
47
|
+
const lines = linesOf(sentence.text);
|
|
48
|
+
const total = lines.reduce((sum, line) => sum + length(line), 0);
|
|
49
|
+
let before = 0;
|
|
50
|
+
return lines.map((line) => {
|
|
51
|
+
const startMs = sentence.startMs + Math.floor((sentence.durationMs * before) / total);
|
|
52
|
+
before += length(line);
|
|
53
|
+
return { text: line, startMs, endMs: 0 };
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function aligned(sentence, alignment) {
|
|
57
|
+
const at = (index, edge) => sentence.startMs + Math.floor(alignment[edge][sentence.spoken.spokenIndex(index, edge === 'startsMs' ? 'first' : 'last')] ?? 0);
|
|
58
|
+
return lineSpans(sentence.text).map((line) => ({
|
|
59
|
+
text: line.text,
|
|
60
|
+
startMs: at(line.from, 'startsMs'),
|
|
61
|
+
endMs: 0,
|
|
62
|
+
words: line.words.map((word) => ({ text: word.text, startMs: at(word.from, 'startsMs'), endMs: at(word.to, 'endsMs') })),
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
/** The captions of placed sentences over a narration of `durationMs`: each line ends where the next starts. */
|
|
66
|
+
export function captionsOf(sentences, durationMs) {
|
|
67
|
+
const lines = sentences.flatMap((sentence) => (sentence.alignment === null ? proportional(sentence) : aligned(sentence, sentence.alignment)));
|
|
68
|
+
return lines.map((line, index) => ({ ...line, endMs: index === lines.length - 1 ? durationMs : (lines[index + 1]?.startMs ?? durationMs) }));
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=captions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captions.js","sourceRoot":"","sources":["../../src/narration/captions.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC;AAE1D,oHAAoH;AACpH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,IAAI;SACR,KAAK,CAAC,QAAQ,CAAC;SACf,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;SAChD,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;SACjD,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,KAAK,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,OAAO,CAAC,QAAgB;IACtC,MAAM,KAAK,GAAa,EAAE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,MAAM,aAAa,MAAM,CAAC;AAEjC,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAcrF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// ffmpeg's arguments to join a narration's sentences (plan 16 §16.6 and §16.7; ADR 0115, 41): each brought to the
|
|
2
|
+
// same sound, 250 ms of silence after every one but the last, joined in order and encoded as MP3 at 192 kb/s.
|
|
3
|
+
export const sentenceGapMs = 250;
|
|
4
|
+
export function joinNarrationArgs(inputs, output) {
|
|
5
|
+
const shaped = inputs.map((_, index) => {
|
|
6
|
+
const pad = index === inputs.length - 1 ? '' : `,apad=pad_dur=${String(sentenceGapMs / 1000)}`;
|
|
7
|
+
return `[${String(index)}:a]aformat=sample_rates=44100:channel_layouts=mono${pad}[s${String(index)}]`;
|
|
8
|
+
});
|
|
9
|
+
const joined = `${inputs.map((_, index) => `[s${String(index)}]`).join('')}concat=n=${String(inputs.length)}:v=0:a=1[out]`;
|
|
10
|
+
return [
|
|
11
|
+
'-hide_banner', '-loglevel', 'error',
|
|
12
|
+
...inputs.flatMap((input) => ['-i', input]),
|
|
13
|
+
'-filter_complex', [...shaped, joined].join(';'),
|
|
14
|
+
'-map', '[out]',
|
|
15
|
+
'-codec:a', 'libmp3lame', '-b:a', '192k',
|
|
16
|
+
'-y', output,
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=join-args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"join-args.js","sourceRoot":"","sources":["../../src/narration/join-args.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAClH,8GAA8G;AAE9G,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AAEjC,MAAM,UAAU,iBAAiB,CAAC,MAAyB,EAAE,MAAc;IACzE,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;QACrC,MAAM,GAAG,GAAG,KAAK,KAAK,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,MAAM,CAAC,aAAa,GAAG,IAAI,CAAC,EAAE,CAAC;QAC/F,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,qDAAqD,GAAG,KAAK,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;IACxG,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,YAAY,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC;IAC3H,OAAO;QACL,cAAc,EAAE,WAAW,EAAE,OAAO;QACpC,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC3C,iBAAiB,EAAE,CAAC,GAAG,MAAM,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QAChD,MAAM,EAAE,OAAO;QACf,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM;QACxC,IAAI,EAAE,MAAM;KACb,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Collection, type Ctx, type Files, type JsonObject } from '@kvman/sdk';
|
|
2
|
+
import { type Alignment } from './alignment.ts';
|
|
3
|
+
/** What makes two sentences sound the same. */
|
|
4
|
+
export type SentenceKey = {
|
|
5
|
+
service: string;
|
|
6
|
+
voice: string | null;
|
|
7
|
+
model: string | null;
|
|
8
|
+
tone: string | null;
|
|
9
|
+
speed: number;
|
|
10
|
+
spoken: string;
|
|
11
|
+
};
|
|
12
|
+
export type CachedSentence = {
|
|
13
|
+
audio: Buffer;
|
|
14
|
+
type: string;
|
|
15
|
+
durationMs: number;
|
|
16
|
+
alignment: Alignment | null;
|
|
17
|
+
};
|
|
18
|
+
export declare function sentenceKey(key: SentenceKey): string;
|
|
19
|
+
export declare function cachedSentence(ctx: Ctx, key: string): Promise<CachedSentence | undefined>;
|
|
20
|
+
export declare function keepSentence(ctx: Ctx, key: string, sentence: CachedSentence): Promise<void>;
|
|
21
|
+
/** Deletes the oldest rows past `limit`, with their files. */
|
|
22
|
+
export declare function trimOldest<Row extends JsonObject & {
|
|
23
|
+
fileId: string;
|
|
24
|
+
}>(collection: Pick<Collection<Row>, 'count' | 'find' | 'delete'>, files: Pick<Files, 'unlink'>, limit: number): Promise<void>;
|
|
25
|
+
//# sourceMappingURL=narration-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"narration-cache.d.ts","sourceRoot":"","sources":["../../src/narration/narration-cache.ts"],"names":[],"mappings":"AACA,OAAO,EAAK,KAAK,UAAU,EAAE,KAAK,GAAG,EAAE,KAAK,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AACvF,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAUjE,+CAA+C;AAC/C,MAAM,MAAM,WAAW,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9I,MAAM,MAAM,cAAc,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAAA;CAAE,CAAC;AAE9G,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,CAEpD;AAID,wBAAsB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAI/F;AAED,wBAAsB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAMjG;AAED,8DAA8D;AAC9D,wBAAsB,UAAU,CAAC,GAAG,SAAS,UAAU,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOxM"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { z } from '@kvman/sdk';
|
|
3
|
+
import { alignmentSchema } from "./alignment.js";
|
|
4
|
+
// The narration cache (plan 16 §16.6; ADR 0115, 40): each spoken sentence's audio, kept in the kernel's files with a
|
|
5
|
+
// row in the workspace collection `narrations`, so an unchanged sentence is never paid for twice. Past 2000 rows the
|
|
6
|
+
// oldest go with their files; the collection's ids rise with time, so the oldest come first.
|
|
7
|
+
const kept = 2000;
|
|
8
|
+
const rowSchema = z.object({ key: z.string(), fileId: z.string(), type: z.string(), durationMs: z.number().int().nonnegative(), alignment: alignmentSchema.nullable(), createdAt: z.string() });
|
|
9
|
+
export function sentenceKey(key) {
|
|
10
|
+
return createHash('sha256').update(JSON.stringify([key.service, key.voice, key.model, key.tone, key.speed, key.spoken])).digest('hex');
|
|
11
|
+
}
|
|
12
|
+
const rows = (ctx) => ctx.store.collection('narrations', rowSchema);
|
|
13
|
+
export async function cachedSentence(ctx, key) {
|
|
14
|
+
const [row] = await rows(ctx).find({ key }, { limit: 1 });
|
|
15
|
+
if (row === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
return { audio: await ctx.files.read(row.fileId), type: row.type, durationMs: row.durationMs, alignment: row.alignment };
|
|
18
|
+
}
|
|
19
|
+
export async function keepSentence(ctx, key, sentence) {
|
|
20
|
+
const extension = sentence.type === 'audio/wav' ? 'wav' : 'mp3';
|
|
21
|
+
const file = await ctx.files.write(`narration-${key.slice(0, 16)}.${extension}`, sentence.audio, sentence.type);
|
|
22
|
+
const collection = rows(ctx);
|
|
23
|
+
await collection.insert({ key, fileId: file.id, type: sentence.type, durationMs: sentence.durationMs, alignment: sentence.alignment, createdAt: new Date().toISOString() });
|
|
24
|
+
await trimOldest(collection, ctx.files, kept);
|
|
25
|
+
}
|
|
26
|
+
/** Deletes the oldest rows past `limit`, with their files. */
|
|
27
|
+
export async function trimOldest(collection, files, limit) {
|
|
28
|
+
const extra = (await collection.count({})) - limit;
|
|
29
|
+
if (extra <= 0)
|
|
30
|
+
return;
|
|
31
|
+
for (const old of await collection.find({}, { limit: extra, order: 'asc' })) {
|
|
32
|
+
await files.unlink(old.fileId);
|
|
33
|
+
await collection.delete(old.id);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=narration-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"narration-cache.js","sourceRoot":"","sources":["../../src/narration/narration-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAA0D,MAAM,YAAY,CAAC;AACvF,OAAO,EAAE,eAAe,EAAkB,MAAM,gBAAgB,CAAC;AAEjE,qHAAqH;AACrH,qHAAqH;AACrH,6FAA6F;AAE7F,MAAM,IAAI,GAAG,IAAI,CAAC;AAElB,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC,E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GAAG,CAAC,MAAM,CAAC,CAAC;QAC/B,MAAM,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Program } from '../programs/run-program.ts';
|
|
2
|
+
/** Speaks `sentence` with the voice into the WAV file `wav`. */
|
|
3
|
+
export declare function piperSentence(piper: Program, voice: string, sentence: string, wav: string, speed: number, signal: AbortSignal): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=piper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"piper.d.ts","sourceRoot":"","sources":["../../src/narration/piper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAMjF,gEAAgE;AAChE,wBAAsB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAMnJ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { lastLines, runProgram } from "../programs/run-program.js";
|
|
2
|
+
import { kvvideoProblem } from "../problems.js";
|
|
3
|
+
// Piper on this computer (plan 16 §16.6; ADR 0107, 22): it speaks one sentence into a WAV, slower or faster by its
|
|
4
|
+
// length scale, the inverse of the speed.
|
|
5
|
+
/** Speaks `sentence` with the voice into the WAV file `wav`. */
|
|
6
|
+
export async function piperSentence(piper, voice, sentence, wav, speed, signal) {
|
|
7
|
+
const spoken = await runProgram(piper, ['-m', voice, '-f', wav, '--length-scale', String(Math.round((1 / speed) * 1000) / 1000), '--', sentence], { signal });
|
|
8
|
+
if (spoken.exitCode !== 0) {
|
|
9
|
+
const reason = lastLines(spoken.output);
|
|
10
|
+
throw kvvideoProblem('NARRATION_FAILED', `piper couldn't narrate: ${reason}`, { service: 'piper', reason });
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=piper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"piper.js","sourceRoot":"","sources":["../../src/narration/piper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAgB,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,mHAAmH;AACnH,0CAA0C;AAE1C,gEAAgE;AAChE,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,KAAc,EAAE,KAAa,EAAE,QAAgB,EAAE,GAAW,EAAE,KAAa,EAAE,MAAmB;IAClI,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9J,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACxC,MAAM,cAAc,CAAC,kBAAkB,EAAE,2BAA2B,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IAC9G,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Pronunciation = {
|
|
2
|
+
word: string;
|
|
3
|
+
say: string;
|
|
4
|
+
};
|
|
5
|
+
/** A sentence as spoken, and where each of its characters (by code point) is in it. */
|
|
6
|
+
export type Spoken = {
|
|
7
|
+
text: string;
|
|
8
|
+
spokenIndex(index: number, edge: 'first' | 'last'): number;
|
|
9
|
+
};
|
|
10
|
+
export declare function spokenOf(sentence: string, pronunciations: readonly Pronunciation[]): Spoken;
|
|
11
|
+
//# sourceMappingURL=pronunciations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pronunciations.d.ts","sourceRoot":"","sources":["../../src/narration/pronunciations.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1D,uFAAuF;AACvF,MAAM,MAAM,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAUlG,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,aAAa,EAAE,GAAG,MAAM,CA2B3F"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// The pronunciation list (plan 16 §16.2; ADR 0115, 15): each word is replaced by what the voice should say, as a whole
|
|
2
|
+
// word, ignoring case. The captions keep the text as written, so each character of the sentence keeps where it is in
|
|
3
|
+
// what is spoken: a replaced word's characters span the whole replacement.
|
|
4
|
+
const escaped = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
5
|
+
function matcher(pronunciations) {
|
|
6
|
+
if (pronunciations.length === 0)
|
|
7
|
+
return undefined;
|
|
8
|
+
const words = [...pronunciations].map((entry) => entry.word).sort((a, b) => b.length - a.length);
|
|
9
|
+
return new RegExp(`(?<![\\p{L}\\p{N}_])(?:${words.map(escaped).join('|')})(?![\\p{L}\\p{N}_])`, 'giu');
|
|
10
|
+
}
|
|
11
|
+
export function spokenOf(sentence, pronunciations) {
|
|
12
|
+
const says = new Map(pronunciations.map((entry) => [entry.word.toLowerCase(), entry.say]));
|
|
13
|
+
const spans = [];
|
|
14
|
+
let spoken = '';
|
|
15
|
+
let spokenLength = 0;
|
|
16
|
+
let from = 0;
|
|
17
|
+
const keep = (text) => {
|
|
18
|
+
for (const character of text) {
|
|
19
|
+
spans.push([spokenLength, spokenLength]);
|
|
20
|
+
spoken += character;
|
|
21
|
+
spokenLength += 1;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const pattern = matcher(pronunciations);
|
|
25
|
+
const matches = pattern === undefined ? [] : [...sentence.matchAll(pattern)];
|
|
26
|
+
for (const match of matches) {
|
|
27
|
+
keep(sentence.slice(from, match.index));
|
|
28
|
+
const say = says.get(match[0].toLowerCase()) ?? match[0];
|
|
29
|
+
const sayLength = [...say].length;
|
|
30
|
+
const replaced = [...match[0]].length;
|
|
31
|
+
for (let index = 0; index < replaced; index += 1)
|
|
32
|
+
spans.push([spokenLength, spokenLength + sayLength - 1]);
|
|
33
|
+
spoken += say;
|
|
34
|
+
spokenLength += sayLength;
|
|
35
|
+
from = match.index + match[0].length;
|
|
36
|
+
}
|
|
37
|
+
keep(sentence.slice(from));
|
|
38
|
+
return { text: spoken, spokenIndex: (index, edge) => spans[index]?.[edge === 'first' ? 0 : 1] ?? 0 };
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=pronunciations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pronunciations.js","sourceRoot":"","sources":["../../src/narration/pronunciations.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,qHAAqH;AACrH,2EAA2E;AAO3E,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AAEtF,SAAS,OAAO,CAAC,cAAwC;IACvD,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAClD,MAAM,KAAK,GAAG,CAAC,GAAG,cAAc,CAAC,CAAC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actOptional<z.ZodNumber>;
|
|
7
|
+
replace: z.ZodExactOptional<z.ZodBoolean>;
|
|
8
|
+
}, z.core.$strict>;
|
|
9
|
+
export declare const narrateOutputSchema: z.ZodObject<{
|
|
10
|
+
file: z.ZodString;
|
|
11
|
+
durationMs: z.ZodNumber;
|
|
12
|
+
captions: z.ZodArray<z.ZodObject<{
|
|
13
|
+
text: z.ZodString;
|
|
14
|
+
startMs: z.ZodNumber;
|
|
15
|
+
endMs: z.ZodNumber;
|
|
16
|
+
words: z.ZodExactOptional<z.ZodArray<z.ZodObject<{
|
|
17
|
+
text: z.ZodString;
|
|
18
|
+
startMs: z.ZodNumber;
|
|
19
|
+
endMs: z.ZodNumber;
|
|
20
|
+
}, z.core.$strip>>>;
|
|
21
|
+
}, z.core.$strip>>;
|
|
22
|
+
reused: z.ZodNumber;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
export declare function registerNarration(ctx: Ctx): void;
|
|
25
|
+
//# sourceMappingURL=register-narration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-narration.d.ts","sourceRoot":"","sources":["../../src/narration/register-narration.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAoBzC,eAAO,MAAM,kBAAkB;;;;;;kBAM7B,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;iBAA8J,CAAC;AAuB/L,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAgDhD"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { z } from '@kvman/sdk';
|
|
3
|
+
import { answerPath } from "../files/answer-path.js";
|
|
4
|
+
import { placeOutput, workFolder } from "../files/place-output.js";
|
|
5
|
+
import { sidecarCaptionSchema, sidecarOutputPath, writeSidecar } from "../files/sidecar.js";
|
|
6
|
+
import { outputPath } from "../files/workspace-paths.js";
|
|
7
|
+
import { mediaDuration } from "../programs/media-duration.js";
|
|
8
|
+
import { programOf } from "../programs/programs.js";
|
|
9
|
+
import { lastLines, runProgram } from "../programs/run-program.js";
|
|
10
|
+
import { invalid, kvvideoProblem } from "../problems.js";
|
|
11
|
+
import { keySecrets } from "../setup/narration-readiness.js";
|
|
12
|
+
import { captionsOf, sentencesOf } from "./captions.js";
|
|
13
|
+
import { joinNarrationArgs, sentenceGapMs } from "./join-args.js";
|
|
14
|
+
import { spokenOf } from "./pronunciations.js";
|
|
15
|
+
import { saySentence } from "./sentence-speaker.js";
|
|
16
|
+
// `video narrate` (plan 16 §16.6; ADR 0115, 15, 17, 39 to 41): the text is said sentence by sentence, each from the
|
|
17
|
+
// cache or the chosen service, then joined with 250 ms between them into an MP3 in the workspace, with its captions
|
|
18
|
+
// in a sidecar beside it. Everything that can fail before a service is paid for is checked first.
|
|
19
|
+
export const narrateInputSchema = z.strictObject({
|
|
20
|
+
text: z.string().min(1).max(4000).describe('What the narrator says: one scene, a few sentences.'),
|
|
21
|
+
file: z.string().min(1).max(1000).describe('The .mp3 file to write, in the workspace.'),
|
|
22
|
+
tone: z.string().min(1).max(300).describe('How it is said, as "warm and upbeat"; OpenAI only.').exactOptional(),
|
|
23
|
+
speed: z.number().min(0.7).max(1.2).describe('How fast it is said: 0.7 to 1.2, 1 by default.').exactOptional(),
|
|
24
|
+
replace: z.boolean().describe('Write over an existing file.').exactOptional(),
|
|
25
|
+
});
|
|
26
|
+
export const narrateOutputSchema = z.object({ file: z.string(), durationMs: z.number().int().nonnegative(), captions: z.array(sidecarCaptionSchema), reused: z.number().int().nonnegative() });
|
|
27
|
+
async function chosenService(ctx) {
|
|
28
|
+
const service = await ctx.settings.get('kvvideo.narration.service');
|
|
29
|
+
if (service === null)
|
|
30
|
+
throw kvvideoProblem('NARRATION_NOT_SET', 'No narration service is chosen; set kvvideo.narration.service.', { setting: 'kvvideo.narration.service' });
|
|
31
|
+
return service;
|
|
32
|
+
}
|
|
33
|
+
async function voiceOf(ctx, input) {
|
|
34
|
+
const service = await chosenService(ctx);
|
|
35
|
+
const choice = { voice: await ctx.settings.get('kvvideo.narration.voice'), model: await ctx.settings.get('kvvideo.narration.model') };
|
|
36
|
+
const shared = { service, choice, tone: input.tone ?? null, speed: input.speed ?? 1, fetch, signal: ctx.job.signal };
|
|
37
|
+
const ffprobe = await programOf(ctx, 'ffprobe');
|
|
38
|
+
if (service === 'piper') {
|
|
39
|
+
if (choice.voice === null)
|
|
40
|
+
throw kvvideoProblem('NARRATION_NOT_SET', "Piper has no voice; set kvvideo.narration.voice to a voice's .onnx file.", { setting: 'kvvideo.narration.voice' });
|
|
41
|
+
return { ...shared, key: null, programs: { ffprobe, piper: await programOf(ctx, 'piper') } };
|
|
42
|
+
}
|
|
43
|
+
const secret = keySecrets[service];
|
|
44
|
+
const key = await ctx.secrets.get(secret);
|
|
45
|
+
if (key === undefined)
|
|
46
|
+
throw kvvideoProblem('NARRATION_KEY_MISSING', `The ${service} key is missing; add the secret ${secret} on kvvideo's extension page.`, { service, secret });
|
|
47
|
+
return { ...shared, key, programs: { ffprobe, piper: null } };
|
|
48
|
+
}
|
|
49
|
+
export function registerNarration(ctx) {
|
|
50
|
+
ctx.registerCommand('kvvideo.narration.make', {
|
|
51
|
+
description: 'Narrates text sentence by sentence with the chosen text-to-speech service into an MP3 file in the workspace, with its length and captions.',
|
|
52
|
+
input: narrateInputSchema,
|
|
53
|
+
output: narrateOutputSchema,
|
|
54
|
+
public: true,
|
|
55
|
+
retries: 0,
|
|
56
|
+
timeoutMs: 300_000,
|
|
57
|
+
handle: async (input) => {
|
|
58
|
+
const root = ctx.job.workspace.path;
|
|
59
|
+
const replace = input.replace === true;
|
|
60
|
+
const output = outputPath(root, input.file, '.mp3', replace);
|
|
61
|
+
const sidecar = sidecarOutputPath(output, replace, input.file);
|
|
62
|
+
const voice = await voiceOf(ctx, input);
|
|
63
|
+
const ffmpeg = await programOf(ctx, 'ffmpeg');
|
|
64
|
+
const pronunciations = await ctx.settings.get('kvvideo.narration.pronunciations');
|
|
65
|
+
const sentences = sentencesOf(input.text).map((text) => ({ text, spoken: spokenOf(text, pronunciations) }));
|
|
66
|
+
if (sentences.length === 0)
|
|
67
|
+
throw invalid('The text has nothing to say.', { text: input.text });
|
|
68
|
+
const work = workFolder();
|
|
69
|
+
try {
|
|
70
|
+
const placed = [];
|
|
71
|
+
const files = [];
|
|
72
|
+
let startMs = 0;
|
|
73
|
+
let reused = 0;
|
|
74
|
+
for (const [index, sentence] of sentences.entries()) {
|
|
75
|
+
ctx.job.progress({ key: 'kvvideo.progress.sentence', params: { n: index + 1, of: sentences.length } });
|
|
76
|
+
const text = { spoken: sentence.spoken.text, previous: sentences[index - 1]?.spoken.text ?? null, next: sentences[index + 1]?.spoken.text ?? null };
|
|
77
|
+
const said = await saySentence(ctx, voice, text, work.folder, index + 1);
|
|
78
|
+
if (said.reused)
|
|
79
|
+
reused += 1;
|
|
80
|
+
files.push(said.file);
|
|
81
|
+
placed.push({ text: sentence.text, spoken: sentence.spoken, startMs, durationMs: said.durationMs, alignment: said.alignment });
|
|
82
|
+
startMs += said.durationMs + sentenceGapMs;
|
|
83
|
+
}
|
|
84
|
+
const made = path.join(work.folder, 'narration.mp3');
|
|
85
|
+
const joined = await runProgram(ffmpeg, joinNarrationArgs(files, made), { signal: ctx.job.signal });
|
|
86
|
+
if (joined.exitCode !== 0)
|
|
87
|
+
throw kvvideoProblem('NARRATION_FAILED', `ffmpeg couldn't join the narration: ${lastLines(joined.output)}`, { service: voice.service, reason: lastLines(joined.output) });
|
|
88
|
+
const duration = await mediaDuration(voice.programs.ffprobe, made, ctx.job.signal);
|
|
89
|
+
if (!duration.ok)
|
|
90
|
+
throw kvvideoProblem('NARRATION_FAILED', `ffprobe couldn't read the narration: ${duration.reason}`, { service: voice.service, reason: duration.reason });
|
|
91
|
+
const captions = captionsOf(placed, duration.ms);
|
|
92
|
+
const madeSidecar = writeSidecar(work.folder, { kind: 'narration', durationMs: duration.ms, captions });
|
|
93
|
+
placeOutput(made, output);
|
|
94
|
+
placeOutput(madeSidecar, sidecar);
|
|
95
|
+
return { file: answerPath(root, output), durationMs: duration.ms, captions, reused };
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
work.remove();
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=register-narration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-narration.js","sourceRoot":"","sources":["../../src/narration/register-narration.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAY,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAuB,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAc,MAAM,uBAAuB,CAAC;AAEhE,oHAAoH;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M,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;gBACjD,MAAM,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;gBACxG,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;gBAC1B,WAAW,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;gBAClC,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;YACvF,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z, type Ctx } from '@kvman/sdk';
|
|
2
|
+
export declare const takeExtensions: string[];
|
|
3
|
+
export declare const voiceInputSchema: z.ZodObject<{
|
|
4
|
+
lines: z.ZodArray<z.ZodObject<{
|
|
5
|
+
take: z.ZodString;
|
|
6
|
+
text: z.ZodString;
|
|
7
|
+
}, z.core.$strict>>;
|
|
8
|
+
file: z.ZodString;
|
|
9
|
+
clean: z.ZodExactOptional<z.ZodBoolean>;
|
|
10
|
+
replace: z.ZodExactOptional<z.ZodBoolean>;
|
|
11
|
+
}, z.core.$strict>;
|
|
12
|
+
export declare const voiceOutputSchema: z.ZodObject<{
|
|
13
|
+
file: z.ZodString;
|
|
14
|
+
durationMs: z.ZodNumber;
|
|
15
|
+
captions: z.ZodArray<z.ZodObject<{
|
|
16
|
+
text: z.ZodString;
|
|
17
|
+
startMs: z.ZodNumber;
|
|
18
|
+
endMs: z.ZodNumber;
|
|
19
|
+
words: z.ZodExactOptional<z.ZodArray<z.ZodObject<{
|
|
20
|
+
text: z.ZodString;
|
|
21
|
+
startMs: z.ZodNumber;
|
|
22
|
+
endMs: z.ZodNumber;
|
|
23
|
+
}, z.core.$strip>>>;
|
|
24
|
+
}, z.core.$strip>>;
|
|
25
|
+
}, z.core.$strip>;
|
|
26
|
+
export declare function registerVoice(ctx: Ctx): void;
|
|
27
|
+
//# sourceMappingURL=register-voice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-voice.d.ts","sourceRoot":"","sources":["../../src/narration/register-voice.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAkBzC,eAAO,MAAM,cAAc,UAAoD,CAAC;AAEhF,eAAO,MAAM,gBAAgB;;;;;;;;kBAK3B,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;iBAAsH,CAAC;AAMrJ,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CA+C5C"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { z } from '@kvman/sdk';
|
|
3
|
+
import { answerPath } from "../files/answer-path.js";
|
|
4
|
+
import { placeOutput, workFolder } from "../files/place-output.js";
|
|
5
|
+
import { sidecarCaptionSchema, sidecarOutputPath, writeSidecar } from "../files/sidecar.js";
|
|
6
|
+
import { inputPath, outputPath } from "../files/workspace-paths.js";
|
|
7
|
+
import { mediaDuration } from "../programs/media-duration.js";
|
|
8
|
+
import { programOf } from "../programs/programs.js";
|
|
9
|
+
import { lastLines, runProgram } from "../programs/run-program.js";
|
|
10
|
+
import { kvvideoProblem } from "../problems.js";
|
|
11
|
+
import { captionsOf, sentencesOf } from "./captions.js";
|
|
12
|
+
import { joinNarrationArgs, sentenceGapMs } from "./join-args.js";
|
|
13
|
+
import { spokenOf } from "./pronunciations.js";
|
|
14
|
+
import { takeArgs } from "./voice-args.js";
|
|
15
|
+
// `video voice` (plan 16 §16.7; ADR 0115, 28 and 50): the person's takes of a scene, as `ask record` wrote them, each
|
|
16
|
+
// cleaned (or only converted), joined as `narrate` joins sentences into an MP3 of the workspace, with each take's
|
|
17
|
+
// captions lasting its own length; a sidecar beside it. The takes are never changed.
|
|
18
|
+
export const takeExtensions = ['.webm', '.ogg', '.m4a', '.mp4', '.mp3', '.wav'];
|
|
19
|
+
export const voiceInputSchema = z.strictObject({
|
|
20
|
+
lines: z.array(z.strictObject({ take: z.string().min(1).max(1000).describe('A take of the person, as ask record wrote it.'), text: z.string().min(1).max(500).describe('What is said in the take.') })).min(1).max(20),
|
|
21
|
+
file: z.string().min(1).max(1000).describe('The .mp3 file to write, in the workspace.'),
|
|
22
|
+
clean: z.boolean().describe('false only converts the takes; true (the default) removes noise, trims silence, and evens the level.').exactOptional(),
|
|
23
|
+
replace: z.boolean().describe('Write over an existing file.').exactOptional(),
|
|
24
|
+
});
|
|
25
|
+
export const voiceOutputSchema = z.object({ file: z.string(), durationMs: z.number().int().nonnegative(), captions: z.array(sidecarCaptionSchema) });
|
|
26
|
+
function failed(take, reason) {
|
|
27
|
+
return kvvideoProblem('RENDER_FAILED', `ffmpeg couldn't make ${take === null ? 'the joined voice' : `take ${String(take)}`}: ${reason}`, { take, reason });
|
|
28
|
+
}
|
|
29
|
+
export function registerVoice(ctx) {
|
|
30
|
+
ctx.registerCommand('kvvideo.voice.make', {
|
|
31
|
+
description: "Makes a narration from the person's own takes: each cleaned, joined into an MP3 file in the workspace, with its length and captions.",
|
|
32
|
+
input: voiceInputSchema,
|
|
33
|
+
output: voiceOutputSchema,
|
|
34
|
+
public: true,
|
|
35
|
+
retries: 0,
|
|
36
|
+
timeoutMs: 300_000,
|
|
37
|
+
handle: async (input) => {
|
|
38
|
+
const root = ctx.job.workspace.path;
|
|
39
|
+
const replace = input.replace === true;
|
|
40
|
+
const takes = input.lines.map((line) => inputPath(root, line.take, takeExtensions));
|
|
41
|
+
const output = outputPath(root, input.file, '.mp3', replace);
|
|
42
|
+
const sidecar = sidecarOutputPath(output, replace, input.file);
|
|
43
|
+
const [ffmpeg, ffprobe] = [await programOf(ctx, 'ffmpeg'), await programOf(ctx, 'ffprobe')];
|
|
44
|
+
const work = workFolder();
|
|
45
|
+
try {
|
|
46
|
+
const cleaned = [];
|
|
47
|
+
const placed = [];
|
|
48
|
+
let startMs = 0;
|
|
49
|
+
for (const [index, take] of takes.entries()) {
|
|
50
|
+
ctx.job.progress({ key: 'kvvideo.progress.take', params: { n: index + 1, of: takes.length } });
|
|
51
|
+
const made = path.join(work.folder, `take-${String(index + 1)}.wav`);
|
|
52
|
+
const run = await runProgram(ffmpeg, takeArgs(take, input.clean !== false, made), { signal: ctx.job.signal });
|
|
53
|
+
if (run.exitCode !== 0)
|
|
54
|
+
throw failed(index + 1, lastLines(run.output));
|
|
55
|
+
const length = await mediaDuration(ffprobe, made, ctx.job.signal);
|
|
56
|
+
if (!length.ok)
|
|
57
|
+
throw failed(index + 1, length.reason);
|
|
58
|
+
const text = sentencesOf(input.lines[index]?.text ?? '').join(' ');
|
|
59
|
+
placed.push({ text, spoken: spokenOf(text, []), startMs, durationMs: length.ms, alignment: null });
|
|
60
|
+
cleaned.push(made);
|
|
61
|
+
startMs += length.ms + sentenceGapMs;
|
|
62
|
+
}
|
|
63
|
+
const joined = path.join(work.folder, 'voice.mp3');
|
|
64
|
+
const run = await runProgram(ffmpeg, joinNarrationArgs(cleaned, joined), { signal: ctx.job.signal });
|
|
65
|
+
if (run.exitCode !== 0)
|
|
66
|
+
throw failed(null, lastLines(run.output));
|
|
67
|
+
const duration = await mediaDuration(ffprobe, joined, ctx.job.signal);
|
|
68
|
+
if (!duration.ok)
|
|
69
|
+
throw failed(null, duration.reason);
|
|
70
|
+
const captions = captionsOf(placed, duration.ms);
|
|
71
|
+
const madeSidecar = writeSidecar(work.folder, { kind: 'narration', durationMs: duration.ms, captions });
|
|
72
|
+
placeOutput(joined, output);
|
|
73
|
+
placeOutput(madeSidecar, sidecar);
|
|
74
|
+
return { file: answerPath(root, output), durationMs: duration.ms, captions };
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
work.remove();
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=register-voice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-voice.js","sourceRoot":"","sources":["../../src/narration/register-voice.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAY,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAuB,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,sHAAsH;AACtH,kHAAkH;AAClH,qFAAqF;AAErF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAEhF,MAAM,CA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,EAAE,CAAC;YAC/E,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Ctx } from '@kvman/sdk';
|
|
2
|
+
import type { Program } from '../programs/run-program.ts';
|
|
3
|
+
import type { NarrationService } from '../settings.ts';
|
|
4
|
+
import type { Alignment } from './alignment.ts';
|
|
5
|
+
import { type Fetch } from './speech-services.ts';
|
|
6
|
+
export type Voice = {
|
|
7
|
+
service: NarrationService;
|
|
8
|
+
choice: {
|
|
9
|
+
voice: string | null;
|
|
10
|
+
model: string | null;
|
|
11
|
+
};
|
|
12
|
+
key: string | null;
|
|
13
|
+
tone: string | null;
|
|
14
|
+
speed: number;
|
|
15
|
+
programs: {
|
|
16
|
+
ffprobe: Program;
|
|
17
|
+
piper: Program | null;
|
|
18
|
+
};
|
|
19
|
+
fetch: Fetch;
|
|
20
|
+
signal: AbortSignal;
|
|
21
|
+
};
|
|
22
|
+
export type SaidSentence = {
|
|
23
|
+
file: string;
|
|
24
|
+
durationMs: number;
|
|
25
|
+
alignment: Alignment | null;
|
|
26
|
+
reused: boolean;
|
|
27
|
+
};
|
|
28
|
+
/** The sentence's spoken text and its neighbours, as sent. */
|
|
29
|
+
export type SentenceText = {
|
|
30
|
+
spoken: string;
|
|
31
|
+
previous: string | null;
|
|
32
|
+
next: string | null;
|
|
33
|
+
};
|
|
34
|
+
export declare function saySentence(ctx: Ctx, voice: Voice, text: SentenceText, folder: string, index: number): Promise<SaidSentence>;
|
|
35
|
+
//# sourceMappingURL=sentence-speaker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentence-speaker.d.ts","sourceRoot":"","sources":["../../src/narration/sentence-speaker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,KA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