@kvman/kvvideo 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/api.d.ts +31 -0
- package/dist/api.d.ts.map +1 -1
- 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/launch.d.ts +2 -0
- package/dist/browser/launch.d.ts.map +1 -1
- package/dist/browser/launch.js +7 -1
- package/dist/browser/launch.js.map +1 -1
- package/dist/compose/ass-file.d.ts +5 -0
- package/dist/compose/ass-file.d.ts.map +1 -1
- package/dist/compose/ass-file.js +32 -3
- package/dist/compose/ass-file.js.map +1 -1
- 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 +2 -0
- package/dist/compose/caption-font.d.ts.map +1 -1
- package/dist/compose/caption-font.js +2 -1
- package/dist/compose/caption-font.js.map +1 -1
- 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 +139 -0
- package/dist/compose/compose-input.d.ts.map +1 -1
- package/dist/compose/compose-input.js +48 -9
- package/dist/compose/compose-input.js.map +1 -1
- 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 +49 -0
- package/dist/compose/compose-size.d.ts.map +1 -0
- package/dist/compose/compose-size.js +67 -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 +5 -1
- package/dist/compose/player-copies.d.ts.map +1 -1
- package/dist/compose/player-copies.js +19 -16
- package/dist/compose/player-copies.js.map +1 -1
- package/dist/compose/register-compose.d.ts.map +1 -1
- package/dist/compose/register-compose.js +104 -20
- package/dist/compose/register-compose.js.map +1 -1
- package/dist/compose/render.d.ts +13 -4
- package/dist/compose/render.d.ts.map +1 -1
- package/dist/compose/render.js +48 -22
- package/dist/compose/render.js.map +1 -1
- package/dist/compose/scene-args.d.ts +32 -7
- package/dist/compose/scene-args.d.ts.map +1 -1
- package/dist/compose/scene-args.js +77 -16
- package/dist/compose/scene-args.js.map +1 -1
- 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 +0 -2
- package/dist/compose/scene-plan.d.ts.map +1 -1
- package/dist/compose/scene-plan.js +7 -5
- package/dist/compose/scene-plan.js.map +1 -1
- 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/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 +79 -14
- package/dist/connector.d.ts.map +1 -1
- package/dist/connector.js +33 -8
- package/dist/connector.js.map +1 -1
- 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/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/look/look-at.d.ts +15 -0
- package/dist/look/look-at.d.ts.map +1 -0
- package/dist/look/look-at.js +20 -0
- package/dist/look/look-at.js.map +1 -0
- package/dist/look/look-input.d.ts +22 -0
- package/dist/look/look-input.d.ts.map +1 -0
- package/dist/look/look-input.js +25 -0
- package/dist/look/look-input.js.map +1 -0
- package/dist/look/register-look.d.ts +3 -0
- package/dist/look/register-look.d.ts.map +1 -0
- package/dist/look/register-look.js +52 -0
- package/dist/look/register-look.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 +22 -4
- package/dist/narration/captions.d.ts.map +1 -1
- package/dist/narration/captions.js +44 -16
- package/dist/narration/captions.js.map +1 -1
- 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 +2 -6
- package/dist/narration/piper.d.ts.map +1 -1
- package/dist/narration/piper.js +9 -15
- package/dist/narration/piper.js.map +1 -1
- 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 +8 -0
- package/dist/narration/register-narration.d.ts.map +1 -1
- package/dist/narration/register-narration.js +54 -26
- package/dist/narration/register-narration.js.map +1 -1
- 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 +23 -3
- package/dist/narration/speech-services.d.ts.map +1 -1
- package/dist/narration/speech-services.js +27 -10
- package/dist/narration/speech-services.js.map +1 -1
- 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/programs/media-duration.d.ts +12 -0
- package/dist/programs/media-duration.d.ts.map +1 -1
- package/dist/programs/media-duration.js +13 -0
- package/dist/programs/media-duration.js.map +1 -1
- package/dist/programs/run-program.d.ts +1 -0
- package/dist/programs/run-program.d.ts.map +1 -1
- package/dist/programs/run-program.js +1 -0
- package/dist/programs/run-program.js.map +1 -1
- package/dist/record/address.d.ts +1 -1
- package/dist/record/address.d.ts.map +1 -1
- package/dist/record/address.js +5 -7
- package/dist/record/address.js.map +1 -1
- package/dist/record/cursor-script.d.ts +2 -1
- package/dist/record/cursor-script.d.ts.map +1 -1
- package/dist/record/cursor-script.js +52 -14
- package/dist/record/cursor-script.js.map +1 -1
- package/dist/record/encoder-args.js +1 -1
- 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/page-clock.d.ts +7 -0
- package/dist/record/page-clock.d.ts.map +1 -0
- package/dist/record/page-clock.js +13 -0
- package/dist/record/page-clock.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 +6 -7
- package/dist/record/pointer.d.ts.map +1 -1
- package/dist/record/pointer.js +11 -10
- package/dist/record/pointer.js.map +1 -1
- package/dist/record/record-source.d.ts +16 -0
- package/dist/record/record-source.d.ts.map +1 -0
- package/dist/record/record-source.js +11 -0
- package/dist/record/record-source.js.map +1 -0
- package/dist/record/recorder.d.ts +19 -7
- package/dist/record/recorder.d.ts.map +1 -1
- package/dist/record/recorder.js +52 -18
- package/dist/record/recorder.js.map +1 -1
- package/dist/record/register-record.d.ts.map +1 -1
- package/dist/record/register-record.js +45 -13
- package/dist/record/register-record.js.map +1 -1
- package/dist/record/run-step.d.ts +16 -3
- package/dist/record/run-step.d.ts.map +1 -1
- package/dist/record/run-step.js +43 -23
- package/dist/record/run-step.js.map +1 -1
- package/dist/record/screencast.js +1 -1
- package/dist/record/steps.d.ts +56 -1
- package/dist/record/steps.d.ts.map +1 -1
- package/dist/record/steps.js +36 -18
- package/dist/record/steps.js.map +1 -1
- 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 +4 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +4 -2
- package/dist/settings.js.map +1 -1
- package/dist/setup/ffmpeg-readiness.js +1 -1
- package/dist/setup/ffmpeg-readiness.js.map +1 -1
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +3 -2
- package/dist/ui.js.map +1 -1
- package/dist/web/components/player.css +1 -1
- package/dist/web/components/player.js +33 -21
- package/docs/guide.md +39 -10
- package/locales/ar.json +12 -1
- package/locales/en.json +12 -1
- package/package.json +11 -5
- 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,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,OA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C,CAAC;gBACxG,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAC5B,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,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>;
|
|
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,IAAI,CAAA;CAAE,CAAC;AAyB5F,wBAAsB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAalI"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { mediaDuration } from "../programs/media-duration.js";
|
|
4
|
+
import { kvvideoProblem } from "../problems.js";
|
|
5
|
+
import { cachedSentence, keepSentence, sentenceKey } from "./narration-cache.js";
|
|
6
|
+
import { piperSentence } from "./piper.js";
|
|
7
|
+
import { resolvedChoice, speak, speechRequest } from "./speech-services.js";
|
|
8
|
+
function failed(service, reason) {
|
|
9
|
+
return kvvideoProblem('NARRATION_FAILED', `${service} couldn't narrate: ${reason}`, { service, reason });
|
|
10
|
+
}
|
|
11
|
+
async function measured(voice, file) {
|
|
12
|
+
const duration = await mediaDuration(voice.programs.ffprobe, file, voice.signal);
|
|
13
|
+
if (!duration.ok)
|
|
14
|
+
throw failed(voice.service, `ffprobe couldn't read the narration: ${duration.reason}`);
|
|
15
|
+
return duration.ms;
|
|
16
|
+
}
|
|
17
|
+
async function spokenNow(voice, text, file) {
|
|
18
|
+
if (voice.service === 'piper') {
|
|
19
|
+
if (voice.choice.voice === null || voice.programs.piper === null)
|
|
20
|
+
throw failed('piper', 'no voice');
|
|
21
|
+
await piperSentence(voice.programs.piper, voice.choice.voice, text.spoken, file, voice.speed, voice.signal);
|
|
22
|
+
return { type: 'audio/wav', durationMs: await measured(voice, file), alignment: null };
|
|
23
|
+
}
|
|
24
|
+
const key = voice.key ?? '';
|
|
25
|
+
const request = speechRequest(voice.service, text.spoken, voice.choice, key, { tone: voice.tone, speed: voice.speed, previous: text.previous, next: text.next });
|
|
26
|
+
const speech = await speak(voice.service, request, text.spoken, key, voice.fetch, voice.signal);
|
|
27
|
+
writeFileSync(file, speech.audio);
|
|
28
|
+
return { type: 'audio/mpeg', durationMs: await measured(voice, file), alignment: speech.alignment };
|
|
29
|
+
}
|
|
30
|
+
export async function saySentence(ctx, voice, text, folder, index) {
|
|
31
|
+
const choice = voice.service === 'piper' ? voice.choice : resolvedChoice(voice.service, voice.choice);
|
|
32
|
+
const key = sentenceKey({ service: voice.service, voice: choice.voice, model: choice.model, tone: voice.tone, speed: voice.speed, spoken: text.spoken });
|
|
33
|
+
const cached = await cachedSentence(ctx, key);
|
|
34
|
+
if (cached !== undefined) {
|
|
35
|
+
const file = path.join(folder, `sentence-${String(index)}.${cached.type === 'audio/wav' ? 'wav' : 'mp3'}`);
|
|
36
|
+
writeFileSync(file, cached.audio);
|
|
37
|
+
return { file, durationMs: cached.durationMs, alignment: cached.alignment, reused: true };
|
|
38
|
+
}
|
|
39
|
+
const file = path.join(folder, `sentence-${String(index)}.${voice.service === 'piper' ? 'wav' : 'mp3'}`);
|
|
40
|
+
const said = await spokenNow(voice, text, file);
|
|
41
|
+
await keepSentence(ctx, key, { audio: readFileSync(file), ...said });
|
|
42
|
+
return { file, durationMs: said.durationMs, alignment: said.alignment, reused: false };
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=sentence-speaker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentence-speaker.js","sourceRoot":"","sources":["../../src/narration/sentence-speaker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAuB,MAAM,sBAAsB,CAAC;AACtG,OAAO,EAAE,aAAa,EAAE,MAA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3
4
|
url: string;
|
|
4
5
|
headers: Record<string, string>;
|
|
5
6
|
body: string;
|
|
6
7
|
};
|
|
8
|
+
/** How a sentence is said: the tone (OpenAI only), the speed, and its neighbours (ElevenLabs only). */
|
|
9
|
+
export type Direction = {
|
|
10
|
+
tone: string | null;
|
|
11
|
+
speed: number;
|
|
12
|
+
previous: string | null;
|
|
13
|
+
next: string | null;
|
|
14
|
+
};
|
|
15
|
+
export type Speech = {
|
|
16
|
+
audio: Buffer;
|
|
17
|
+
alignment: Alignment | null;
|
|
18
|
+
};
|
|
7
19
|
export type Fetch = (url: string, init: {
|
|
8
20
|
method: 'POST';
|
|
9
21
|
headers: Record<string, string>;
|
|
10
22
|
body: string;
|
|
11
23
|
signal: AbortSignal;
|
|
12
24
|
}) => Promise<Response>;
|
|
25
|
+
/** The voice and model a service uses: the chosen ones, else its defaults. */
|
|
26
|
+
export declare function resolvedChoice(service: WebService, choice: {
|
|
27
|
+
voice: string | null;
|
|
28
|
+
model: string | null;
|
|
29
|
+
}): {
|
|
30
|
+
voice: string;
|
|
31
|
+
model: string;
|
|
32
|
+
};
|
|
13
33
|
export declare function speechRequest(service: WebService, text: string, choice: {
|
|
14
34
|
voice: string | null;
|
|
15
35
|
model: string | null;
|
|
16
|
-
}, key: string): SpeechRequest;
|
|
17
|
-
/** The
|
|
18
|
-
export declare function speak(service: WebService, request: SpeechRequest, key: string, fetch: Fetch, signal: AbortSignal): Promise<
|
|
36
|
+
}, key: string, direction: Direction): SpeechRequest;
|
|
37
|
+
/** The speech a service answers for `spoken`, or `kvvideo/NARRATION_FAILED`. */
|
|
38
|
+
export declare function speak(service: WebService, request: SpeechRequest, spoken: string, key: string, fetch: Fetch, signal: AbortSignal): Promise<Speech>;
|
|
19
39
|
//# sourceMappingURL=speech-services.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speech-services.d.ts","sourceRoot":"","sources":["../../src/narration/speech-services.ts"],"names":[],"mappings":"
|
|
1
|
+
{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,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,aAAa,CAgBzK;AAoBD,gFAAgF;AAChF,wBAAsB,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAiBxJ"}
|
|
@@ -1,32 +1,49 @@
|
|
|
1
|
-
import { ProblemError } from '@kvman/sdk';
|
|
1
|
+
import { ProblemError, z } from '@kvman/sdk';
|
|
2
2
|
import { kvvideoProblem } from "../problems.js";
|
|
3
|
+
import { alignmentOf, elevenLabsAlignmentSchema } from "./alignment.js";
|
|
3
4
|
const defaults = {
|
|
4
5
|
elevenlabs: { voice: 'JBFqnCBsd6RMkjVDRZzb', model: 'eleven_multilingual_v2' },
|
|
5
6
|
openai: { voice: 'alloy', model: 'gpt-4o-mini-tts' },
|
|
6
7
|
};
|
|
7
8
|
const requestTimeoutMs = 60_000;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/** The voice and model a service uses: the chosen ones, else its defaults. */
|
|
10
|
+
export function resolvedChoice(service, choice) {
|
|
11
|
+
return { voice: choice.voice ?? defaults[service].voice, model: choice.model ?? defaults[service].model };
|
|
12
|
+
}
|
|
13
|
+
export function speechRequest(service, text, choice, key, direction) {
|
|
14
|
+
const { voice, model } = resolvedChoice(service, choice);
|
|
15
|
+
const speed = direction.speed === 1 ? {} : { speed: direction.speed };
|
|
11
16
|
if (service === 'elevenlabs') {
|
|
17
|
+
const neighbours = { ...(direction.previous === null ? {} : { previous_text: direction.previous }), ...(direction.next === null ? {} : { next_text: direction.next }) };
|
|
12
18
|
return {
|
|
13
|
-
url: `https://api.elevenlabs.io/v1/text-to-speech/${encodeURIComponent(voice)}?output_format=mp3_44100_128`,
|
|
19
|
+
url: `https://api.elevenlabs.io/v1/text-to-speech/${encodeURIComponent(voice)}/with-timestamps?output_format=mp3_44100_128`,
|
|
14
20
|
headers: { 'xi-api-key': key, 'Content-Type': 'application/json' },
|
|
15
|
-
body: JSON.stringify({ text, model_id: model }),
|
|
21
|
+
body: JSON.stringify({ text, model_id: model, ...neighbours, ...(direction.speed === 1 ? {} : { voice_settings: speed }) }),
|
|
16
22
|
};
|
|
17
23
|
}
|
|
18
24
|
return {
|
|
19
25
|
url: 'https://api.openai.com/v1/audio/speech',
|
|
20
26
|
headers: { Authorization: `Bearer ${key}`, 'Content-Type': 'application/json' },
|
|
21
|
-
body: JSON.stringify({ model, voice, input: text, response_format: 'mp3' }),
|
|
27
|
+
body: JSON.stringify({ model, voice, input: text, response_format: 'mp3', ...(direction.tone === null ? {} : { instructions: direction.tone }), ...speed }),
|
|
22
28
|
};
|
|
23
29
|
}
|
|
30
|
+
const elevenLabsAnswerSchema = z.object({ audio_base64: z.string(), alignment: elevenLabsAlignmentSchema.nullable() });
|
|
24
31
|
function withoutKey(text, key) {
|
|
25
32
|
return key === '' ? text : text.split(key).join('…');
|
|
26
33
|
}
|
|
27
34
|
const reasonOf = (error) => (error instanceof Error ? error.message : String(error));
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
async function speechOf(service, response, spoken) {
|
|
36
|
+
if (service === 'openai')
|
|
37
|
+
return { audio: Buffer.from(await response.arrayBuffer()), alignment: null };
|
|
38
|
+
const answer = elevenLabsAnswerSchema.safeParse(await response.json());
|
|
39
|
+
if (!answer.success) {
|
|
40
|
+
const reason = "ElevenLabs's answer has no audio and character times";
|
|
41
|
+
throw kvvideoProblem('NARRATION_FAILED', reason, { service, reason });
|
|
42
|
+
}
|
|
43
|
+
return { audio: Buffer.from(answer.data.audio_base64, 'base64'), alignment: answer.data.alignment === null ? null : alignmentOf(answer.data.alignment, spoken) };
|
|
44
|
+
}
|
|
45
|
+
/** The speech a service answers for `spoken`, or `kvvideo/NARRATION_FAILED`. */
|
|
46
|
+
export async function speak(service, request, spoken, key, fetch, signal) {
|
|
30
47
|
const timeout = new AbortController();
|
|
31
48
|
const timer = setTimeout(() => timeout.abort(new Error(`no answer in ${String(requestTimeoutMs / 1000)} s`)), requestTimeoutMs);
|
|
32
49
|
try {
|
|
@@ -35,7 +52,7 @@ export async function speak(service, request, key, fetch, signal) {
|
|
|
35
52
|
const reason = withoutKey((await response.text()).slice(0, 300), key);
|
|
36
53
|
throw kvvideoProblem('NARRATION_FAILED', `${service} answered ${String(response.status)}: ${reason}`, { service, status: response.status, reason });
|
|
37
54
|
}
|
|
38
|
-
return
|
|
55
|
+
return await speechOf(service, response, spoken);
|
|
39
56
|
}
|
|
40
57
|
catch (error) {
|
|
41
58
|
if (signal.aborted || error instanceof ProblemError)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"speech-services.js","sourceRoot":"","sources":["../../src/narration/speech-services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"speech-services.js","sourceRoot":"","sources":["../../src/narration/speech-services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,yBAAyB,EAAkB,MAAM,gBAAgB,CAAC;AAkBxF,MAAM,QAAQ,GAAG;IACf,UAAU,EAAE,EAAE,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,wBAAwB,EAAE;IAC9E,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE;CAC5C,CAAC;AAEX,MAAM,gBAAgB,GAAG,MAAM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BAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAE/E"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// ffmpeg's arguments to clean one take of the person's voice (plan 16 §16.7; ADR 0115, 28 and 50): low rumble removed,
|
|
2
|
+
// steady noise reduced, silence below −45 dB trimmed at both ends down to 150 ms (the end trimmed by reversing the
|
|
3
|
+
// sound, so pauses inside the take stay), and the level evened out at −16 LUFS. With `clean` false, it is only
|
|
4
|
+
// converted. Either way it becomes 44.1 kHz mono WAV, ready to join.
|
|
5
|
+
const trimStart = 'silenceremove=start_periods=1:start_threshold=-45dB:start_silence=0.15';
|
|
6
|
+
export const cleanFilter = ['highpass=f=80', 'afftdn=nr=12:nf=-30', trimStart, 'areverse', trimStart, 'areverse', 'loudnorm=I=-16:TP=-1.5:LRA=11', 'aresample=44100'].join(',');
|
|
7
|
+
export function takeArgs(take, clean, output) {
|
|
8
|
+
return ['-hide_banner', '-loglevel', 'error', '-i', take, '-vn', ...(clean ? ['-af', cleanFilter] : []), '-ac', '1', '-ar', '44100', '-c:a', 'pcm_s16le', '-y', output];
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=voice-args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voice-args.js","sourceRoot":"","sources":["../../src/narration/voice-args.ts"],"names":[],"mappings":"AAAA,uHAAuH;AACvH,mHAAmH;AACnH,+GAA+G;AAC/G,qEAAqE;AAErE,MAAM,SAAS,GAAG,wEAAwE,CAAC;AAE3F,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,eAAe,EAAE,qBAAqB,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,+BAA+B,EAAE,iBAAiB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEhL,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,KAAc,EAAE,MAAc;IACnE,OAAO,CAAC,cAAc,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AAC1K,CAAC"}
|
|
@@ -7,4 +7,16 @@ export type Duration = {
|
|
|
7
7
|
reason: string;
|
|
8
8
|
};
|
|
9
9
|
export declare function mediaDuration(ffprobe: Program, file: string, signal: AbortSignal): Promise<Duration>;
|
|
10
|
+
export type MediaSize = {
|
|
11
|
+
ok: true;
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
} | {
|
|
15
|
+
ok: false;
|
|
16
|
+
reason: string;
|
|
17
|
+
};
|
|
18
|
+
/** A video's or an image's size in pixels, read with ffprobe from its first video stream. */
|
|
19
|
+
export declare function mediaSize(ffprobe: Program, file: string, signal: AbortSignal): Promise<MediaSize>;
|
|
20
|
+
/** Whether a file has a sound stream, read with ffprobe. */
|
|
21
|
+
export declare function hasSound(ffprobe: Program, file: string, signal: AbortSignal): Promise<boolean>;
|
|
10
22
|
//# sourceMappingURL=media-duration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media-duration.d.ts","sourceRoot":"","sources":["../../src/programs/media-duration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAIvE,MAAM,MAAM,QAAQ,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhF,wBAAsB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAM1G"}
|
|
1
|
+
{"version":3,"file":"media-duration.d.ts","sourceRoot":"","sources":["../../src/programs/media-duration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAIvE,MAAM,MAAM,QAAQ,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhF,wBAAsB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAM1G;AAED,MAAM,MAAM,SAAS,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpG,6FAA6F;AAC7F,wBAAsB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAKvG;AAED,4DAA4D;AAC5D,wBAAsB,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAGpG"}
|
|
@@ -7,4 +7,17 @@ export async function mediaDuration(ffprobe, file, signal) {
|
|
|
7
7
|
return { ok: false, reason: lastLines(run.output) || `ffprobe answered ${answer}` };
|
|
8
8
|
return { ok: true, ms: Math.round(seconds * 1000) };
|
|
9
9
|
}
|
|
10
|
+
/** A video's or an image's size in pixels, read with ffprobe from its first video stream. */
|
|
11
|
+
export async function mediaSize(ffprobe, file, signal) {
|
|
12
|
+
const run = await runProgram(ffprobe, ['-v', 'error', '-select_streams', 'v:0', '-show_entries', 'stream=width,height', '-of', 'csv=s=x:p=0', file], { signal });
|
|
13
|
+
const match = /^(\d+)x(\d+)/.exec(run.stdout.trim());
|
|
14
|
+
if (run.exitCode !== 0 || match === null)
|
|
15
|
+
return { ok: false, reason: lastLines(run.output) || `ffprobe answered ${run.stdout.trim()}` };
|
|
16
|
+
return { ok: true, width: Number(match[1]), height: Number(match[2]) };
|
|
17
|
+
}
|
|
18
|
+
/** Whether a file has a sound stream, read with ffprobe. */
|
|
19
|
+
export async function hasSound(ffprobe, file, signal) {
|
|
20
|
+
const run = await runProgram(ffprobe, ['-v', 'error', '-select_streams', 'a', '-show_entries', 'stream=index', '-of', 'csv=p=0', file], { signal });
|
|
21
|
+
return run.exitCode === 0 && run.stdout.trim() !== '';
|
|
22
|
+
}
|
|
10
23
|
//# sourceMappingURL=media-duration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media-duration.js","sourceRoot":"","sources":["../../src/programs/media-duration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAgB,MAAM,kBAAkB,CAAC;AAMvE,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAAgB,EAAE,IAAY,EAAE,MAAmB;IACrF,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/H,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IACjC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,GAAG,CA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AAC"}
|
|
@@ -15,6 +15,7 @@ export type RunOptions = {
|
|
|
15
15
|
signal: AbortSignal;
|
|
16
16
|
cwd?: string;
|
|
17
17
|
timeoutMs?: number;
|
|
18
|
+
onStdout?: (text: string) => void;
|
|
18
19
|
};
|
|
19
20
|
export declare function runProgram(program: Program, args: readonly string[], options: RunOptions): Promise<ProgramRun>;
|
|
20
21
|
/** The last lines of a run's output, for a Problem's reason. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-program.d.ts","sourceRoot":"","sources":["../../src/programs/run-program.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAOlE,sBAAsB;AACtB,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAEjG,uFAAuF;AACvF,MAAM,MAAM,OAAO,GAAG;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7D,MAAM,MAAM,UAAU,GAAG;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"run-program.d.ts","sourceRoot":"","sources":["../../src/programs/run-program.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAOlE,sBAAsB;AACtB,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAEjG,uFAAuF;AACvF,MAAM,MAAM,OAAO,GAAG;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7D,MAAM,MAAM,UAAU,GAAG;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,CAAC;AAQtH,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAgC9G;AAED,gEAAgE;AAChE,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,MAAM,CAE5D"}
|
|
@@ -15,6 +15,7 @@ export function runProgram(program, args, options) {
|
|
|
15
15
|
child.stdout.setEncoding('utf8').on('data', (text) => {
|
|
16
16
|
stdout += text;
|
|
17
17
|
output += text;
|
|
18
|
+
options.onStdout?.(text);
|
|
18
19
|
});
|
|
19
20
|
child.stderr.setEncoding('utf8').on('data', (text) => (output += text));
|
|
20
21
|
const abort = () => killTree(child.pid);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-program.js","sourceRoot":"","sources":["../../src/programs/run-program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAoB,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAc1D,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAE5D,SAAS,OAAO,CAAC,OAAgB;IA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AE,QAAQ,EAAE,CAAC,CAAC;QAC7D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,KAAK,GAAG,EAAE;IAClD,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/D,CAAC"}
|
package/dist/record/address.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Whether a request goes to kvman's port, on any host. */
|
|
2
2
|
export declare function isOwnAddress(url: URL, ownPort: number | null): boolean;
|
|
3
3
|
/** The address, when it is one a recording may open. */
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function recordableAddress(address: string, ownPort: number | null): URL;
|
|
5
5
|
//# sourceMappingURL=address.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/record/address.ts"],"names":[],"mappings":"AAaA,2DAA2D;AAC3D,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAEtE;AAED,wDAAwD;AACxD,wBAAgB,
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/record/address.ts"],"names":[],"mappings":"AAaA,2DAA2D;AAC3D,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAEtE;AAED,wDAAwD;AACxD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,GAAG,CAM9E"}
|
package/dist/record/address.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { invalid } from "../problems.js";
|
|
2
|
-
// The addresses a recording may open (plan 16 §16.5
|
|
3
|
-
//
|
|
4
|
-
// since `0.0.0.0`, `127.0.0.2`, or `[::ffff:127.0.0.1]` reach kvman too.
|
|
2
|
+
// The addresses a recording may open (plan 16 §16.5; ADR 0115, 56): any http or https address without credentials,
|
|
3
|
+
// in a fresh browser, and never kvman's own (ADR 0107, 18). The recorded page's requests to kvman's port are aborted
|
|
4
|
+
// whatever their host, since `0.0.0.0`, `127.0.0.2`, or `[::ffff:127.0.0.1]` reach kvman too.
|
|
5
5
|
const localHosts = new Set(['localhost', '127.0.0.1', '[::1]']);
|
|
6
6
|
function portOf(url) {
|
|
7
7
|
if (url.port !== '')
|
|
@@ -13,15 +13,13 @@ export function isOwnAddress(url, ownPort) {
|
|
|
13
13
|
return ownPort !== null && portOf(url) === ownPort;
|
|
14
14
|
}
|
|
15
15
|
/** The address, when it is one a recording may open. */
|
|
16
|
-
export function
|
|
16
|
+
export function recordableAddress(address, ownPort) {
|
|
17
17
|
const url = URL.canParse(address) ? new URL(address) : undefined;
|
|
18
18
|
if (url === undefined || (url.protocol !== 'http:' && url.protocol !== 'https:'))
|
|
19
19
|
throw invalid(`${address} isn't an http or https address.`, { url: address });
|
|
20
|
-
if (!localHosts.has(url.hostname))
|
|
21
|
-
throw invalid(`${address} isn't on this computer: use localhost, 127.0.0.1, or [::1].`, { url: address });
|
|
22
20
|
if (url.username !== '' || url.password !== '')
|
|
23
21
|
throw invalid(`${address} has a user name or password.`, { url: address });
|
|
24
|
-
if (isOwnAddress(url, ownPort))
|
|
22
|
+
if (localHosts.has(url.hostname) && isOwnAddress(url, ownPort))
|
|
25
23
|
throw invalid(`${address} is kvman's own address, which can't be recorded.`, { url: address });
|
|
26
24
|
return url;
|
|
27
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../src/record/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAEzC,
|
|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AE,CAAC,CAAC;IAC3H,IAAI,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC;QAAE,MAAM,OAAO,CAAC,GAAG,OAAO,mDAAmD,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;IAC/J,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
/** The script a page of the device gets. */
|
|
2
|
+
export declare function cursorScript(device: 'desktop' | 'phone'): string;
|
|
2
3
|
//# sourceMappingURL=cursor-script.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cursor-script.d.ts","sourceRoot":"","sources":["../../src/record/cursor-script.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cursor-script.d.ts","sourceRoot":"","sources":["../../src/record/cursor-script.ts"],"names":[],"mappings":"AAyDA,4CAA4C;AAC5C,wBAAgB,YAAY,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,CAIhE"}
|
|
@@ -1,21 +1,59 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
|
|
1
|
+
// What a recorded page draws (plan 16 §16.5; ADR 0115, 9 and 53): a browser's recording has no pointer, so on a
|
|
2
|
+
// desktop the page draws an arrow that follows the mouse, hidden until the mouse first moves; a press shrinks it for
|
|
3
|
+
// 120 ms and shows a ring. On a phone it draws a round mark at each touch instead. Scroll bars are hidden. The script
|
|
4
|
+
// is added to every page before its own scripts run.
|
|
5
|
+
const arrowPath = 'M3 2 L3 20 L7.6 15.6 L10.6 22.6 L13.8 21.2 L10.9 14.4 L17.2 14.4 Z';
|
|
6
|
+
const shared = `
|
|
7
|
+
const hideScrollBars = () => {
|
|
8
|
+
const style = document.createElement('style');
|
|
9
|
+
style.textContent = 'html { scrollbar-width: none; } ::-webkit-scrollbar { display: none; }';
|
|
10
|
+
document.documentElement.appendChild(style);
|
|
11
|
+
};
|
|
12
|
+
const ring = (x, y, size, color) => {
|
|
13
|
+
const mark = document.createElement('div');
|
|
14
|
+
mark.className = 'kvvideo-ring';
|
|
15
|
+
mark.style.cssText = 'position:fixed;direction:ltr;inset-inline-start:' + (x - size / 2) + 'px;inset-block-start:' + (y - size / 2) + 'px;inline-size:' + size + 'px;block-size:' + size + 'px;border-radius:50%;box-sizing:border-box;border:3px solid ' + color + ';pointer-events:none;z-index:2147483646';
|
|
16
|
+
document.documentElement.appendChild(mark);
|
|
17
|
+
mark.animate([{ opacity: 1, transform: 'scale(.4)' }, { opacity: 0, transform: 'scale(1.3)' }], { duration: 500 }).onfinish = () => mark.remove();
|
|
18
|
+
};`;
|
|
19
|
+
const desktop = `
|
|
4
20
|
const draw = () => {
|
|
5
21
|
if (document.getElementById('kvvideo-cursor')) return;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
document.
|
|
10
|
-
|
|
22
|
+
hideScrollBars();
|
|
23
|
+
const pointer = document.createElement('div');
|
|
24
|
+
pointer.id = 'kvvideo-cursor';
|
|
25
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
26
|
+
for (const [name, value] of [['width', '26'], ['height', '26'], ['viewBox', '0 0 26 26']]) svg.setAttribute(name, value);
|
|
27
|
+
const shape = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
28
|
+
for (const [name, value] of [['d', ${JSON.stringify(arrowPath)}], ['fill', '#fff'], ['stroke', '#111'], ['stroke-width', '1.6'], ['stroke-linejoin', 'round']]) shape.setAttribute(name, value);
|
|
29
|
+
svg.appendChild(shape);
|
|
30
|
+
pointer.appendChild(svg);
|
|
31
|
+
pointer.style.cssText = 'position:fixed;direction:ltr;inset-inline-start:0;inset-block-start:0;inline-size:26px;block-size:26px;margin-block-start:-2px;margin-inline-start:-3px;display:none;transform-origin:3px 2px;pointer-events:none;z-index:2147483647;filter:drop-shadow(0 1px 2px rgba(0,0,0,.4))';
|
|
32
|
+
document.documentElement.appendChild(pointer);
|
|
33
|
+
let x = 0; let y = 0; let scale = 1;
|
|
34
|
+
const place = () => { pointer.style.transform = 'translate(' + x + 'px,' + y + 'px) scale(' + scale + ')'; };
|
|
35
|
+
window.addEventListener('mousemove', (event) => { x = event.clientX; y = event.clientY; pointer.style.display = 'block'; place(); }, true);
|
|
11
36
|
window.addEventListener('mousedown', (event) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
ring
|
|
15
|
-
document.documentElement.appendChild(ring);
|
|
16
|
-
ring.animate([{ opacity: 1, transform: 'scale(.4)' }, { opacity: 0, transform: 'scale(1.3)' }], { duration: 500 }).onfinish = () => ring.remove();
|
|
37
|
+
scale = 0.85; place();
|
|
38
|
+
setTimeout(() => { scale = 1; place(); }, 120);
|
|
39
|
+
ring(event.clientX, event.clientY, 44, 'rgba(255,190,0,.9)');
|
|
17
40
|
}, true);
|
|
18
|
-
}
|
|
41
|
+
};`;
|
|
42
|
+
const phone = `
|
|
43
|
+
const draw = () => {
|
|
44
|
+
if (document.getElementById('kvvideo-touch')) return;
|
|
45
|
+
hideScrollBars();
|
|
46
|
+
const marker = document.createElement('meta');
|
|
47
|
+
marker.id = 'kvvideo-touch';
|
|
48
|
+
document.documentElement.appendChild(marker);
|
|
49
|
+
window.addEventListener('touchstart', (event) => {
|
|
50
|
+
for (const touch of event.changedTouches) ring(touch.clientX, touch.clientY, 40, 'rgba(255,255,255,.9)');
|
|
51
|
+
}, true);
|
|
52
|
+
};`;
|
|
53
|
+
/** The script a page of the device gets. */
|
|
54
|
+
export function cursorScript(device) {
|
|
55
|
+
return `(() => {${shared}${device === 'phone' ? phone : desktop}
|
|
19
56
|
if (document.documentElement) draw(); else document.addEventListener('DOMContentLoaded', draw);
|
|
20
57
|
})();`;
|
|
58
|
+
}
|
|
21
59
|
//# sourceMappingURL=cursor-script.js.map
|