// 时间轴:由旁白逐句时长自动推算每一幕、每一句的起止时间 import scriptJson from './script.json' import voiceJson from './voice.json' export type LineKind = 'n' | 'q' export interface RawLine { id: string; k: string; t: string } export interface RawScene { id: string; no: string; title: string; en: string; para?: string; lines: RawLine[] } export interface Line { id: string; k: LineKind; t: string; start: number; dur: number; end: number; scene: string } export interface Scene { id: string; no: string; title: string; en: string; para?: string start: number; end: number; dur: number; intro: number; lines: Line[] } const voice = voiceJson as Record const raw = scriptJson as RawScene[] const INTRO: Record = { prologue: 1.6, depth: 1.4, recite: 1.6, epilogue: 1.2 } const TAIL: Record = { epilogue: 7.5, shot5: 1.6 } const EXTRA: Record = { p1: 0.5, p3: 0.4, p4: 0.3, p5: 0.7, p6: 0.3, p8: 1.6, p9: 0.8, a3: 0.3, a5: 0.3, a8: 0.3, a9: 1.0, b2: 0.3, b4: 0.3, b8: 0.3, b10: 0.6, b11: 0.3, b12: 1.2, b14: 0.4, b16: 1.0, c2: 0.4, c3: 0.3, c4: 0.9, c5: 0.8, c7: 0.4, c8: 0.7, c9: 0.4, c11: 0.5, c13: 0.5, c15: 0.4, c17: 0.4, c18: 0.6, c19: 0.8, c21: 0.3, c22: 1.6, d2: 0.3, d4: 0.3, d7: 0.8, e1: 0.4, e2: 0.4, e3: 0.4, e4: 0.6, e5: 0.8, e6: 1.4, e7: 2.0, e8: 1.2, f1: 0.5, f5: 0.6, f6: 0.5, f7: 1.4, g1: 0.5, g6: 0.8, g7: 0.3, g11: 1.0, h2: 1.4, h3: 0.4, h4: 0.6, } function build() { const scenes: Scene[] = [] let t = 0 for (const s of raw) { const intro = INTRO[s.id] ?? 3.6 const start = t let cur = start + intro const lines: Line[] = [] for (const l of s.lines) { const dur = voice[l.id] ?? 2 lines.push({ id: l.id, k: l.k as LineKind, t: l.t, start: cur, dur, end: cur + dur, scene: s.id }) cur += dur + (l.k === 'q' ? 0.7 : 0.32) + (EXTRA[l.id] ?? 0) } const end = cur + (TAIL[s.id] ?? 0.9) scenes.push({ id: s.id, no: s.no, title: s.title, en: s.en, para: s.para, start, end, dur: end - start, intro, lines }) t = end } return { scenes, duration: t } } export const TL = build() export const DURATION = TL.duration export const ALL_LINES: Line[] = TL.scenes.flatMap((s) => s.lines) export const LINE: Record = Object.fromEntries(ALL_LINES.map((l) => [l.id, l])) export const SCENE: Record = Object.fromEntries(TL.scenes.map((s) => [s.id, s])) export const FULL_TEXT = raw.filter((s) => s.para).map((s) => s.para as string) export function sceneIndexAt(t: number) { const sc = TL.scenes for (let i = sc.length - 1; i >= 0; i--) if (t >= sc[i].start) return i return 0 } export function lineAt(t: number): Line | null { for (const l of ALL_LINES) if (t >= l.start && t < l.end + 0.25) return l return null } export const SHOT_NAMES = ['航拍', '跟拍', '延时', '特写', '空镜']