Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions skills/popost/SOURCE-MANIFEST.sha256
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ a74f894b8f8652ed7e24bfbc1cbd9050b231c1d624e76810d3961b0c9e1ba08e references/vid
26cd8f5142b1958dbb02ae28766ce62e13336b1209cc0a58e674c8a0f9eb6514 references/video-step-6-voice.md
8287e464d2cb2baee59eabe14fe7617279d916f25881fc8f03957ac828933bda references/video-step-7-deliver.md
aa60b78da67f9a29492aae836c2e6d336805c212301539e88e651aab5b21b061 references/video-templates.md
7610cae314ee31bcb406a95d0e6d2a3222fb339b65621175f82681e542d220e8 references/video-tools.md
a268291ec22299a2ef43cf752f7f92ce77f8cac364679ef0f46d2243e379feab references/video-tools.md
0eb8c1d8a8e569bc43baaebb34e1bad341a3bce03d8d9d7902b84894353d9268 references/video.md
9ce62b5d799a1e415a153348ae87740665998e9e97c7c34e47ae35adff2d50bc src/args.ts
6722276f8e90bbda70f169453e2671a529f7f57af17e03f9f74324a837ff2041 src/broken-pipe.ts
Expand Down Expand Up @@ -876,7 +876,7 @@ b0afdadb19e13034c97c41d76f4d993bf938b5d64eb50426b711804216b79dfb src/video/gene
05b138218b2a4bfb91b9f03a9fb08c336001d30a25691779999683c8e243019a src/video/generate/clip-sound.ts
a2aaedfd6e2c45fe019e0bb6230be7e72a332bb654ae20cd6e43b31c512d9f4c src/video/generate/cloud-image.ts
dfab9e7ccd06991f0d3bb3d29b72263432720e35543f66377006db90b91e52fc src/video/generate/cloud.ts
ecc26785962bcaba92747968d2d7596c789d56b3951de08ee71613926f81478c src/video/generate/dialogue.ts
eb65582f00c128699a130d4f3405f968715dcd4fa16bd1280443faee6a5eaede src/video/generate/dialogue.ts
50ecd17b36de2f2aeb6ee73635a5edb5a41750b7dbedb2a2ed49a97eb8a02f1f src/video/generate/index.ts
7c6e6ffcfcc6187b4d0fb33889b8d377318a6e5adfbf2cc374e5b9106105bbb1 src/video/generate/provenance.ts
84ad146c516ccb2790649ae8e12bfa632a5b9bb240d0f2282628455050104e87 src/video/generate/speech-lock.ts
Expand Down Expand Up @@ -2156,7 +2156,7 @@ f082f0d7971f6c40301cf0eb008328492e4b4d726e2e9baa37e458d5f38f26de tests/video/ca
ec7c05a77795c1ead0e262752720cb7a095d286faf1e54552db7337c69130bc9 tests/video/cpu-budget.test.ts
ea991534572498196851eae7ee436a02af732c957a41397fac483a4950b0584d tests/video/cue-curve.test.ts
9daa10042c32ccc99d1f0c0ec1e09e0e0cc0b33e1398acdf3d1a64f8ee193f41 tests/video/describe-cards.test.ts
4d66f8d439b19264da1069a25811576bdebc7f5df3ee3b50bafffd474b10f5b1 tests/video/dialogue.test.ts
cc6857575030cf01e9560e1ad14484923dac2c0799ed9cb2696cc8ecd3e28cfa tests/video/dialogue.test.ts
3ec9a8ae65880b184a82e6cf744549661b0d130005ce2603bb7f7beeb489a267 tests/video/draft-export.test.ts
a90338acb41232083376ca04d703dff30e56f6a488d52cd1d9e9ecc041e38d5d tests/video/elements-captions.test.ts
cce755727f12a23f6880283c15b22bf2b64dc6d4f7e66b474e31be67479a5cd4 tests/video/elements-status.test.ts
Expand Down
1 change: 1 addition & 0 deletions skills/popost/references/video-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ the platform's free quotes (the reference pictures of a clip are uploaded for it
{ "speaker": "host", "text": "The exact words of beat 4.", "beat": 4 }] } }
```

- An off-camera participant in the conversation uses `"offscreen": true` on each of their lines. Keep that role out of the visible cast when the role never appears. The model hears the off-camera speaker and only lip-syncs the visible speaker on their own lines.
- `language`: a tag such as `en-US`, `zh-CN`, `ja`; the lines are written in it. `speaker`: a role of the clip's
`cast`; several speakers are several roles. `beat`: the template's beat the line re-makes (TEMPLATE.md marks them
"on camera").
Expand Down
26 changes: 20 additions & 6 deletions skills/popost/src/video/generate/dialogue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { error } from '../project/check-common';
import type { Problem } from '../types';

/** One line of a request: who says what, in which beat of the template (or, without beats, from when to when in the clip). */
export interface SpeechLine { speaker: string; text: string; beat?: number; at?: number; to?: number }
export interface SpeechLine { speaker: string; text: string; beat?: number; at?: number; to?: number; offscreen?: boolean }
/** Native speech with timed lines: the model speaks them, lips and voice made together. */
export interface DialogueSpeech { mode: 'native'; language: string; lines: SpeechLine[]; shot?: number }
/** A line with its slot in the clip, in seconds from the clip's first frame. */
export interface TimedLine { speaker: string; text: string; at: number; to: number; beat?: number }
export interface TimedLine { speaker: string; text: string; at: number; to: number; beat?: number; offscreen?: true }
export interface TimedDialogue { mode: 'native'; language: string; lines: TimedLine[] }

/** What the times are read from: the template's shots and beats on its clock, and how fast its speaker spoke. */
Expand Down Expand Up @@ -100,7 +100,7 @@ export const estimatedLines = (s: DialogueSpeech): TimedLine[] => {
return s.lines.map((l) => {
const text = typeof l.text === 'string' ? l.text : '';
const length = Math.max(ESTIMATE.least, spokenChars(text).length / (wideText(text) ? ORDINARY_PACE.wide : ORDINARY_PACE.latin));
const line = { speaker: l.speaker, text, at: r2(t), to: r2(t + length) };
const line: TimedLine = { speaker: l.speaker, text, at: r2(t), to: r2(t + length), ...(l.offscreen ? { offscreen: true } : {}) };
t += length + ESTIMATE.gap;
return line;
});
Expand All @@ -115,7 +115,7 @@ export const timedLines = (s: DialogueSpeech, times: BeatTimes | undefined): (Ti
const shot = times ? firstShot(s, times) : undefined;
const zero = times && shot !== undefined ? (times.shots[shot] ?? 0) : 0;
return s.lines.map((l): TimedLine | undefined => {
const said = { speaker: l.speaker, text: l.text };
const said = { speaker: l.speaker, text: l.text, ...(l.offscreen ? { offscreen: true as const } : {}) };
if (l.beat !== undefined) {
const b = times && shot !== undefined && Number.isInteger(l.beat) ? times.beats[l.beat] : undefined;
return b && times ? { ...said, at: r2((b.start - zero) / times.fps), to: r2((b.end - zero) / times.fps), beat: l.beat } : undefined;
Expand Down Expand Up @@ -154,15 +154,17 @@ export const dialogueProblems = (s: DialogueSpeech, o: { at: string; cast: reado
out.push(error(where, 'A line says who speaks and the exact words.', 'Write {"speaker": "<a role of this clip\'s cast>", "text": "The exact words", "beat": <the beat it re-makes>}.'));
return;
}
if (!o.cast.includes(l.speaker)) out.push(error(where + '.speaker', 'The speaker ' + quote(l.speaker) + ' is not in this clip\'s "cast" (' + (o.cast.join(', ') || 'empty') + ').', 'Name a role of the cast, or add the role to "cast" (cast.json has the roles).'));
if (l.offscreen !== undefined && typeof l.offscreen !== 'boolean') out.push(error(where + '.offscreen', 'Offscreen is a boolean.', 'Set it to true only for dialogue heard from outside the frame.'));
if (l.offscreen !== true && !o.cast.includes(l.speaker)) out.push(error(where + '.speaker', 'The speaker ' + quote(l.speaker) + ' is not in this clip\'s "cast" (' + (o.cast.join(', ') || 'empty') + ').', 'Name a role of the cast, or add the role to "cast" (cast.json has the roles).'));
if (typeof s.language === 'string' && TAG.test(s.language.trim()) && spokenChars(l.text).length && wideLanguage(s.language) !== wideText(l.text))
out.push(error(where + '.text', 'The line ' + quote(l.text) + ' is not written in the script of its language (' + languageName(s.language) + ').', 'Write the line in ' + languageName(s.language) + ', or correct "language" to the language the line is in.'));
const timed = l.at !== undefined || l.to !== undefined;
if (l.beat !== undefined && timed) out.push(error(where, 'A line names its beat or, without a template\'s beats, its seconds: not both.', 'Remove "at" and "to": the program takes the times from the beat.'));
else if (l.beat !== undefined) {
if (!times) out.push(error(where + '.beat', 'The time of beat ' + JSON.stringify(l.beat) + ' is the template\'s, and no template was given.', 'Run the command with --template <the template directory>.'));
else if (!Number.isInteger(l.beat) || !times.beats[l.beat]) out.push(error(where + '.beat', 'The template has no beat ' + JSON.stringify(l.beat) + ' (its beats are 0 to ' + (times.beats.length - 1) + ').', 'Write the number of the beat this line re-makes, as timeline.md and TEMPLATE.md number them.'));
else if (times.kinds && times.beats[l.beat]?.speech !== 'on-camera') out.push(error(where + '.beat', 'Beat ' + l.beat + ' is not said on camera in the reference: no person of a clip says it.', 'Name only beats TEMPLATE.md marks "on camera"; narration is the voice-over\'s (the fill\'s "voice").'));
else if (l.offscreen === true && times.beats[l.beat]?.speech === 'on-camera') out.push(error(where + '.beat', 'This reference beat has a visible speaker.', 'Use a visible cast role for this beat and move the offscreen line to its own original beat.'));
else if (times.kinds && !l.offscreen && times.beats[l.beat]?.speech !== 'on-camera') out.push(error(where + '.beat', 'Beat ' + l.beat + ' is not said on camera in the reference: no person of a clip says it.', 'Name only beats TEMPLATE.md marks "on camera"; narration is the voice-over\'s (the fill\'s "voice").'));
} else if (hasBeats) out.push(error(where, 'A line of a video made from a template names the beat it re-makes; its time is the program\'s, not written by hand.', 'Write "beat": <the number of its beat> and remove "at" and "to".'));
else if (!free && !(typeof l.at === 'number' && typeof l.to === 'number' && l.at >= 0 && l.to > l.at)) out.push(error(where, 'Without a template\'s beats the lines of a clip either all say when they are spoken ("at" and "to" in seconds, "to" after "at") or none does: the program then gives them slots by an ordinary speaking rate.', 'Write "at": 0.5, "to": 2.8 on every line, or remove "at" and "to" from all of them.'));
});
Expand Down Expand Up @@ -218,6 +220,18 @@ export const noMusic = (): string => pl(NO_MUSIC, ' 本片段没有背景音乐

export const dialoguePrompt = (d: TimedDialogue): string => {
const speakers = [...new Set(d.lines.map((l) => l.speaker))];
if (d.lines.some((line) => line.offscreen)) {
const zh = pl('', 'zh');
const timeline = d.lines.map((line) => {
const role = line.offscreen ? (zh ? '(画外,不出镜)' : ' (off camera, heard only)') : (zh ? '(出镜,对口型)' : ' (visible, lip-synced)');
return stamp(line.at) + '-' + stamp(line.to) + (zh ? ' 秒 ' : ' s ') + line.speaker + role + (zh ? ' 说 ' : ' says ') + JSON.stringify(line.text);
}).join(zh ? ';' : '; ');
return zh
? ' 用' + languageName(d.language) + '按时间原生录制以下对白:' + timeline
+ '。画外说话人的声音来自镜头后方,画面不出现画外说话人。出镜人物只在自己的台词时对口型,听对方时自然反应。没有额外对白、旁白、字幕或屏幕文字。'
: ' Record this native dialogue in ' + languageName(d.language) + ': ' + timeline
+ '. Off-camera speakers are heard from behind the camera and are never shown in those lines. Visible speakers lip-sync only to their own lines and react naturally while listening. No extra dialogue, narrator, captions or on-screen text.';
}
if (pl('', 'zh')) return ' 对白:用' + languageName(d.language) + '原生说出,与画面同时录制并对好口型,' + (speakers.length === 1 ? speakers[0] + '的嘴' : '每个说话人的嘴') + '与' + (speakers.length === 1 ? '台词' : '各自的台词') + '完全同步。台词的时间线,从片段开始算起,单位为秒:'
+ d.lines.map((l) => stamp(l.at) + '-' + stamp(l.to) + ' 秒 ' + l.speaker + ' 说 ' + JSON.stringify(l.text)).join(';')
+ '。这些时间之外没有人说话,两句台词之间嘴保持闭合。没有其他对白,没有旁白,没有字幕或屏幕文字,没有配音,也没有翻译后的语音。生成的语音就是最终音频,之后不会被替换。';
Expand Down
15 changes: 15 additions & 0 deletions skills/popost/tests/video/dialogue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ describe('the times of the lines', () => {
});
});

it('keeps off-camera dialogue in the same native recording without adding a visible role', () => {
const input: DialogueSpeech = {
mode: 'native', language: 'en-US',
lines: [{ speaker: 'interviewer', text: 'Ready?', at: 0, to: 1, offscreen: true },
{ speaker: 'host', text: 'Yes, let us go.', at: 1.2, to: 3 }],
};
expect(dialogueProblems(input, { at: '[0]', cast: ['host'], seconds: 4 })).toEqual([]);
const timed = timedDialogue(input, undefined)!;
expect(timed.lines[0]?.offscreen).toBe(true);
expect(dialoguePrompt(timed)).toContain('interviewer (off camera, heard only) says "Ready?"');
expect(dialoguePrompt(timed)).toContain('host (visible, lip-synced) says "Yes, let us go."');
const onCamera: DialogueSpeech = { ...input, lines: [{ speaker: 'host', text: 'Ready?', offscreen: true, beat: 2 }] };
expect(dialogueProblems(onCamera, { at: '[0]', cast: ['host'], seconds: 4, times })[0]?.message).toContain('visible speaker');
});

describe('the dialogue block of a prompt', () => {
it('names the language in plain words, native lip-synced speech, each line with its time, and what must not be heard', () => {
const one = dialoguePrompt({ mode: 'native', language: 'zh-CN', lines: [{ speaker: 'host', text: '这个小工具改变了我的早晨。', at: 0.5, to: 2.8 }] });
Expand Down
Loading