rvlib-shipkit 2.20.0 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/package.json +1 -1
- package/src/asks/asks-queue.ts +8 -7
- package/src/assets/kits/identity-kit.ts +158 -2
- package/src/checks/SK004-gitignore-policy.check.ts +6 -3
- package/src/cli/cmd_Bump.ts +3 -3
- package/src/cli/cmd_GlobalProcesses.ts +2 -107
- package/src/cli/cmd_Home.ts +1 -1
- package/src/cli/cmd_Overview.ts +2 -1
- package/src/cli/cmd_Rec.ts +349 -0
- package/src/cli/cmd_Releases.ts +42 -3
- package/src/cli/cmd_Review.ts +22 -13
- package/src/cli/cmd_Secret.ts +10 -3
- package/src/cli/cmd_Sign.ts +24 -0
- package/src/cli/cmd_Social.ts +57 -8
- package/src/cli/cmd_Sound.ts +17 -4
- package/src/cli/cmd_Trailer.ts +67 -1
- package/src/cli/family-pages.ts +1 -0
- package/src/cli/registry.ts +6 -1
- package/src/collections/collection-types.ts +1 -1
- package/src/collections/review.ts +23 -4
- package/src/core/agent-spawn.ts +4 -17
- package/src/core/code-lines.ts +49 -0
- package/src/core/discover-checks.ts +27 -3
- package/src/core/hard-reset.ts +34 -0
- package/src/core/layout.ts +6 -0
- package/src/core/raw-access.ts +3 -13
- package/src/core/throwaway-worktree.ts +72 -0
- package/src/home/app-sign.ts +98 -0
- package/src/home/gui-app/ShipkitGui.swift +35 -0
- package/src/home/gui-app.ts +31 -11
- package/src/home/home-routes.ts +6 -0
- package/src/home/pm-switch.ts +112 -0
- package/src/home/serve-web.ts +1 -1
- package/src/identities/identities.ts +17 -6
- package/src/media-kinds.ts +5 -3
- package/src/media-store/forget.ts +54 -0
- package/src/media-store/put.ts +4 -3
- package/src/media-store/space.ts +63 -24
- package/src/messages/brief.ts +3 -3
- package/src/messages/score.ts +2 -0
- package/src/recordings/delete.ts +19 -0
- package/src/recordings/edit.ts +231 -0
- package/src/recordings/load.ts +37 -0
- package/src/recordings/marks-draw.ts +111 -0
- package/src/recordings/marks-png.ts +25 -0
- package/src/recordings/marks.ts +138 -0
- package/src/recordings/media-kind.ts +67 -0
- package/src/recordings/model.ts +170 -0
- package/src/recordings/open.ts +33 -0
- package/src/recordings/place.ts +89 -0
- package/src/recordings/presets.ts +99 -0
- package/src/recordings/recorder-app/Capture.swift +510 -0
- package/src/recordings/recorder-app/Clip.swift +107 -0
- package/src/recordings/recorder-app/Editor.swift +39 -0
- package/src/recordings/recorder-app/Tray.swift +298 -0
- package/src/recordings/recorder-app/main.swift +859 -0
- package/src/recordings/recorder-app.ts +46 -0
- package/src/recordings/recorder.shipkit.ts +11 -0
- package/src/recordings/routes.ts +140 -0
- package/src/recordings/run-recorder.ts +40 -0
- package/src/recordings/share.ts +107 -0
- package/src/recordings/take.ts +146 -0
- package/src/recordings/view.ts +40 -0
- package/src/release/gate-checkout.ts +74 -0
- package/src/release/release-scope.ts +35 -26
- package/src/release/run-bump.ts +79 -37
- package/src/release/run-release.ts +67 -53
- package/src/releases/add.ts +38 -5
- package/src/releases/before.ts +31 -0
- package/src/releases/from-card.ts +105 -20
- package/src/releases/model.ts +100 -18
- package/src/releases/pictures.ts +29 -8
- package/src/repo-config.ts +7 -3
- package/src/review/http.ts +1 -1
- package/src/review/model.ts +12 -2
- package/src/review/stage-card.ts +1 -1
- package/src/review/store.ts +12 -2
- package/src/review/trailer-desk.ts +20 -0
- package/src/review/trailer-model.ts +67 -0
- package/src/review/trailer-routes.ts +98 -1
- package/src/review/trailer-voices.ts +144 -0
- package/src/review/watchers.ts +58 -1
- package/src/secrets/manager.ts +18 -1
- package/src/serve/hub-app/benign-errors.ts +22 -0
- package/src/serve/hub-app/hash-route.ts +27 -15
- package/src/serve/hub-app/home-st.ts +23 -5
- package/src/serve/hub-app/home.html +1 -0
- package/src/serve/hub-app/hub-app.tsx +8 -1
- package/src/serve/hub-app/icons.tsx +2 -0
- package/src/serve/hub-app/palette-st.ts +1 -0
- package/src/serve/hub-app/project-list.css +7 -2
- package/src/serve/hub-app/project-list.tsx +10 -0
- package/src/serve/hub-app/projects-svc.ts +17 -7
- package/src/serve/hub-app/recordings-st.ts +641 -0
- package/src/serve/hub-app/recordings-view.tsx +504 -0
- package/src/serve/hub-app/recordings.css +82 -0
- package/src/serve/hub-app/releases/releases-page.tsx +121 -28
- package/src/serve/hub-app/releases/releases-st.ts +46 -4
- package/src/serve/hub-app/releases.css +30 -3
- package/src/serve/hub-app/repo-sections.ts +1 -1
- package/src/serve/hub-app/repo-st.ts +16 -11
- package/src/serve/hub-app/review/clip-st.ts +3 -1
- package/src/serve/hub-app/review/kit.tsx +3 -3
- package/src/serve/hub-app/review/trailer-page.tsx +32 -6
- package/src/serve/hub-app/review/trailer-st.ts +184 -8
- package/src/serve/hub-app/review/trailer-timeline.tsx +39 -4
- package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
- package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
- package/src/serve/hub-app/review.css +90 -0
- package/src/serve/hub-app/social/comms-page.tsx +10 -5
- package/src/serve/hub-app/social/next-release.tsx +118 -0
- package/src/serve/hub-app/social/post-card.tsx +31 -3
- package/src/serve/hub-app/social/social-model.ts +6 -0
- package/src/serve/hub-app/social/social-st.ts +50 -1
- package/src/serve/hub-app/social.css +12 -0
- package/src/serve/hub-app/tree-build.ts +2 -0
- package/src/serve/project-gutter-route.ts +8 -0
- package/src/serve/project-gutter.ts +4 -2
- package/src/shipkit.ts +2 -2
- package/src/shot/box.ts +49 -22
- package/src/shot/browser-slot.ts +13 -3
- package/src/shot/client.ts +1 -1
- package/src/shot/film-box.ts +193 -117
- package/src/shot/shooter.ts +20 -8
- package/src/smoke/run-smoke.ts +8 -6
- package/src/social/compose.ts +14 -0
- package/src/social/desk-index.ts +49 -8
- package/src/social/discord-layout.ts +6 -2
- package/src/social/drafts.ts +1 -1
- package/src/social/kinds.ts +3 -2
- package/src/social/load.ts +42 -9
- package/src/social/publish/index.ts +27 -10
- package/src/social/publish/secret.ts +12 -4
- package/src/social/release-card.ts +69 -0
- package/src/social/release-stage.ts +173 -30
- package/src/social/routes.ts +7 -1
- package/src/social/stage.ts +45 -22
- package/src/trailer/bed.ts +111 -0
- package/src/trailer/build.ts +81 -38
- package/src/trailer/ffmpeg.ts +14 -0
- package/src/trailer/grammar.ts +32 -4
- package/src/trailer/graph.ts +12 -1
- package/src/trailer/look.ts +7 -0
- package/src/trailer/shot-plan.ts +75 -0
- package/src/trailer/shot-state.ts +191 -0
- package/src/trailer/sound/audio.ts +28 -0
- package/src/trailer/sound/brand.ts +53 -3
- package/src/trailer/sound/gen.ts +61 -2
- package/src/trailer/sound/index.ts +25 -11
- package/src/trailer/sound/presets.ts +86 -5
- package/src/trailer/sound/run.ts +1 -1
- package/src/trailer/sound/takes.ts +94 -0
- package/src/trailer/titles.ts +36 -0
- package/src/trailer/url.ts +1 -1
- package/src/veille/chrome.ts +6 -3
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// each shot's state in plain words (wiki tools/trailer/index.md, Shot states): what the lanes plan for it (the cut's
|
|
2
|
+
// plan, written by `sk trailer plan`), what its take was when a build or a check last read it, and the owner's answer on
|
|
3
|
+
// the card that shows its new take. Pure: `sk trailer check` and the hub's trailer page say the same words from it. A
|
|
4
|
+
// take of an older world stays ready: a moved repo is a detail, never a reason a shot is not final
|
|
5
|
+
export const PLAN_MARKS = ['queued', 'filming', 'waiting', 'ready'] as const
|
|
6
|
+
export type PlanMark = (typeof PLAN_MARKS)[number]
|
|
7
|
+
|
|
8
|
+
/** what a lane wrote about one shot */
|
|
9
|
+
export interface PlanEntry {
|
|
10
|
+
mark: PlanMark
|
|
11
|
+
/** the lane's name */
|
|
12
|
+
by: string
|
|
13
|
+
/** why, in plain words: "old studio UI", "new dress" */
|
|
14
|
+
why?: string
|
|
15
|
+
/** waiting: the review card that shows the new take */
|
|
16
|
+
card?: string
|
|
17
|
+
/** when it was written, ISO */
|
|
18
|
+
at: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** a cut's plan: one entry a shot that a lane spoke for; a shot with none is ready once filmed */
|
|
22
|
+
export interface CutPlan {
|
|
23
|
+
shots: Record<string, PlanEntry>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** how a shot is filmed: its own take, a file read in place, drawn (a card), or a grid or split of other takes */
|
|
27
|
+
export type FactKind = 'take' | 'file' | 'drawn' | 'grid'
|
|
28
|
+
|
|
29
|
+
/** one shot's take as a build or a check last read it */
|
|
30
|
+
export interface TakeFact {
|
|
31
|
+
kind: FactKind
|
|
32
|
+
filmed: boolean
|
|
33
|
+
/** a take: when it was filmed, ISO */
|
|
34
|
+
filmedAt?: string
|
|
35
|
+
/** a take of an older world: the parts of the repo that moved since (empty when its stamp kept none) */
|
|
36
|
+
moved?: string[]
|
|
37
|
+
/** a grid or split: its cells, and how many are filmed */
|
|
38
|
+
cells?: { of: number; filmed: number }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** a cut's takes as last read: `at` the read, ISO */
|
|
42
|
+
export interface TakeFacts {
|
|
43
|
+
at: string
|
|
44
|
+
shots: Record<string, TakeFact>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type ShotState = 'ready' | 'queued' | 'filming' | 'waiting' | 'unfilmed'
|
|
48
|
+
|
|
49
|
+
/** the owner's answer on a card, as the store folds it: null while he has not answered */
|
|
50
|
+
export interface CardAnswer {
|
|
51
|
+
status: string
|
|
52
|
+
approved: boolean
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** one shot's state as the page and the check say it */
|
|
56
|
+
export interface ShotStatus {
|
|
57
|
+
state: ShotState
|
|
58
|
+
/** the state in plain words: "ready", "queued", "filming now", "new take waiting for your answer", "not filmed" */
|
|
59
|
+
word: string
|
|
60
|
+
by?: string
|
|
61
|
+
why?: string
|
|
62
|
+
card?: string
|
|
63
|
+
/** dim details: when it was filmed, an older world, the plan's age */
|
|
64
|
+
detail: string[]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const STATE_WORD: Record<ShotState, string> = {
|
|
68
|
+
ready: 'ready',
|
|
69
|
+
queued: 'queued',
|
|
70
|
+
filming: 'filming now',
|
|
71
|
+
waiting: 'new take waiting for your answer',
|
|
72
|
+
unfilmed: 'not filmed',
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** the order a list of states reads in: what needs someone first */
|
|
76
|
+
export const STATE_ORDER: readonly ShotState[] = ['unfilmed', 'waiting', 'filming', 'queued', 'ready']
|
|
77
|
+
|
|
78
|
+
const ago = (iso: string, now: number): string => {
|
|
79
|
+
const m = Math.max(0, Math.round((now - Date.parse(iso)) / 60_000))
|
|
80
|
+
return m < 60 ? `${m} min ago` : m < 48 * 60 ? `${Math.round(m / 60)} h ago` : `${Math.round(m / 1440)} days ago`
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** the dim words of a take: when it was filmed and on which world, how a shot is made otherwise */
|
|
84
|
+
export function factDetail(f: TakeFact | undefined, now = Date.now()): string[] {
|
|
85
|
+
if (!f) return []
|
|
86
|
+
if (f.kind === 'file') return ['a file']
|
|
87
|
+
if (f.kind === 'drawn') return ['drawn']
|
|
88
|
+
if (f.kind === 'grid') return f.cells ? [`a grid of ${f.cells.of}, ${f.cells.filmed} filmed`] : []
|
|
89
|
+
if (!f.filmed) return []
|
|
90
|
+
const when = f.filmedAt ? ` ${ago(f.filmedAt, now)}` : ''
|
|
91
|
+
if (f.moved === undefined) return [`filmed${when}`]
|
|
92
|
+
return [`filmed${when} on an older world${f.moved.length > 0 ? `: ${f.moved.slice(0, 4).join(', ')}${f.moved.length > 4 ? ` and ${f.moved.length - 4} more` : ''} moved` : ''}`]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** one shot's state: the plan first, then the card's answer, then the take. Not filmed wins over ready; a plan that
|
|
96
|
+
* still says queued or filming after a newer take is said in the details */
|
|
97
|
+
export function shotStatus(entry: PlanEntry | undefined, fact: TakeFact | undefined, card: CardAnswer | null = null, now = Date.now()): ShotStatus {
|
|
98
|
+
const detail = factDetail(fact, now)
|
|
99
|
+
const unfilmed = fact !== undefined && !fact.filmed
|
|
100
|
+
const lane = entry ? { by: entry.by, ...(entry.why ? { why: entry.why } : {}) } : {}
|
|
101
|
+
const of = (state: ShotState, more: Partial<ShotStatus> = {}): ShotStatus => ({ state, word: STATE_WORD[state], ...lane, ...more, detail: [...(more.detail ?? []), ...detail] })
|
|
102
|
+
if (!entry) return of(unfilmed ? 'unfilmed' : 'ready')
|
|
103
|
+
const marked = `marked ${ago(entry.at, now)}`
|
|
104
|
+
if (entry.mark === 'waiting' && entry.card) {
|
|
105
|
+
if (card === null) return of('waiting', { card: entry.card, detail: [marked] })
|
|
106
|
+
// the answer settles it: a yes takes the take in, anything else sends the shot back to its lane
|
|
107
|
+
if (card.approved) return of(unfilmed ? 'unfilmed' : 'ready', { card: entry.card, detail: [`taken on card ${entry.card}`] })
|
|
108
|
+
return of('queued', { card: entry.card, why: `your answer on card ${entry.card}: ${card.status}${entry.why ? `; ${entry.why}` : ''}`, detail: [marked] })
|
|
109
|
+
}
|
|
110
|
+
if (entry.mark === 'ready') return of(unfilmed ? 'unfilmed' : 'ready', { detail: [`checked and kept, ${marked}`] })
|
|
111
|
+
const after = fact?.filmedAt !== undefined && Date.parse(fact.filmedAt) > Date.parse(entry.at) ? ['a take was filmed after it was marked'] : []
|
|
112
|
+
return of(entry.mark === 'waiting' ? 'queued' : entry.mark, { detail: [marked, ...after] })
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** the cut at a glance */
|
|
116
|
+
export interface Summary {
|
|
117
|
+
total: number
|
|
118
|
+
counts: Record<ShotState, number>
|
|
119
|
+
/** the cards waiting for the owner's answer, each with its shots, in the cut's order */
|
|
120
|
+
cards: { card: string; shots: string[] }[]
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function summaryOf(shots: readonly { name: string; status: ShotStatus }[]): Summary {
|
|
124
|
+
const counts: Record<ShotState, number> = { ready: 0, queued: 0, filming: 0, waiting: 0, unfilmed: 0 }
|
|
125
|
+
const cards = new Map<string, string[]>()
|
|
126
|
+
for (const { name, status } of shots) {
|
|
127
|
+
counts[status.state]++
|
|
128
|
+
if (status.state === 'waiting' && status.card) cards.set(status.card, [...(cards.get(status.card) ?? []), name])
|
|
129
|
+
}
|
|
130
|
+
return { total: shots.length, counts, cards: [...cards].map(([card, s]) => ({ card, shots: s })) }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** the summary as one line: "17 of 29 shots ready · 12 queued · 0 filming · cards waiting: none" */
|
|
134
|
+
export function summaryText(s: Summary): string {
|
|
135
|
+
const c = s.counts
|
|
136
|
+
return [
|
|
137
|
+
`${c.ready} of ${s.total} shots ready`,
|
|
138
|
+
`${c.queued} queued`,
|
|
139
|
+
`${c.filming} filming`,
|
|
140
|
+
...(c.unfilmed > 0 ? [`${c.unfilmed} not filmed`] : []),
|
|
141
|
+
`cards waiting: ${s.cards.length === 0 ? 'none' : s.cards.map((x) => `${x.card} (${x.shots.join(', ')})`).join(', ')}`,
|
|
142
|
+
].join(' · ')
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** a cut's shots as the hub's trailer page shows them: each shot's state by its name, the summary, the cut whose plan
|
|
146
|
+
* it reads (a kept version reads its cut's), when its takes were last read (null: never, so no take is known) */
|
|
147
|
+
export interface CutStates {
|
|
148
|
+
states: Record<string, ShotStatus>
|
|
149
|
+
summary: Summary
|
|
150
|
+
plan: string
|
|
151
|
+
read: string | null
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function cutStates(names: readonly string[], plan: CutPlan, planCut: string, facts: TakeFacts | null, answer: (card: string) => CardAnswer | null, now = Date.now()): CutStates {
|
|
155
|
+
const shots = names.map((name) => {
|
|
156
|
+
const e = plan.shots[name]
|
|
157
|
+
return { name, status: shotStatus(e, facts?.shots[name], e?.card ? answer(e.card) : null, now) }
|
|
158
|
+
})
|
|
159
|
+
return { states: Object.fromEntries(shots.map((s) => [s.name, s.status])), summary: summaryOf(shots), plan: planCut, read: facts?.at ?? null }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** a state as the check prints it: the word, the lane and why, the card */
|
|
163
|
+
export function statusText(s: ShotStatus): string {
|
|
164
|
+
const word = s.state === 'ready' ? 'ready' : s.word.toUpperCase()
|
|
165
|
+
const lane = s.by ? ` by ${s.by}${s.why ? `: ${s.why}` : ''}` : s.why ? `: ${s.why}` : ''
|
|
166
|
+
const card = s.state === 'waiting' && s.card ? ` on card ${s.card}` : ''
|
|
167
|
+
return `${word}${card}${s.state === 'ready' ? '' : lane}`
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** a kept version's plan is its cut's: `v3-voice-v22` reads v3-voice's, `v7` main's */
|
|
171
|
+
export const planCutOf = (cut: string, version: boolean): string => (version ? (/^v\d+$/.test(cut) ? 'main' : cut.replace(/-v\d+$/, '')) : cut)
|
|
172
|
+
|
|
173
|
+
/** a plan read from its file's text: an entry with no known mark or lane is dropped, never trusted */
|
|
174
|
+
export function parsePlan(text: string): CutPlan {
|
|
175
|
+
const raw = JSON.parse(text) as { shots?: Record<string, Partial<PlanEntry>> }
|
|
176
|
+
const shots: Record<string, PlanEntry> = {}
|
|
177
|
+
for (const [name, e] of Object.entries(raw.shots ?? {}))
|
|
178
|
+
if (e && PLAN_MARKS.includes(e.mark as PlanMark) && typeof e.by === 'string' && typeof e.at === 'string')
|
|
179
|
+
shots[name] = { mark: e.mark as PlanMark, by: e.by, at: e.at, ...(typeof e.why === 'string' && e.why ? { why: e.why } : {}), ...(typeof e.card === 'string' && e.card ? { card: e.card } : {}) }
|
|
180
|
+
return { shots }
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** the plan with these shots marked (or their entries dropped, `mark` null) */
|
|
184
|
+
export function markShots(plan: CutPlan, shots: readonly string[], mark: Omit<PlanEntry, 'at'> | null, at: string): CutPlan {
|
|
185
|
+
const next = { ...plan.shots }
|
|
186
|
+
for (const s of shots) {
|
|
187
|
+
if (mark === null) delete next[s]
|
|
188
|
+
else next[s] = { ...mark, at }
|
|
189
|
+
}
|
|
190
|
+
return { shots: next }
|
|
191
|
+
}
|
|
@@ -106,6 +106,34 @@ export async function writeTrimmed(src: string, out: string, t: Trim): Promise<v
|
|
|
106
106
|
/** the true peak no made sound passes */
|
|
107
107
|
const CEILING_DBTP = -1.5
|
|
108
108
|
|
|
109
|
+
/** a voice recorded on a microphone written at its loudness: the trimmed take raised toward `lufs`, its body evened by
|
|
110
|
+
* a gentle compressor (a generated voice comes compressed already), its peaks held by a true peak limiter at 4x the
|
|
111
|
+
* rate, measured and made again until it lands within 0.3 LU (four passes at most). A raw take is peaky: plain gain
|
|
112
|
+
* under the ceiling stopped it 5 to 8 LU short of a made line, so it sat under the music */
|
|
113
|
+
export async function finishVoice(src: string, out: string, t: Trim, lufs: number): Promise<void> {
|
|
114
|
+
const trimmed = `${out}.trim.wav`
|
|
115
|
+
try {
|
|
116
|
+
await writeTrimmed(src, trimmed, t)
|
|
117
|
+
const m0 = await loudness(trimmed)
|
|
118
|
+
if (m0.lufs <= -70) return void (await ffmpeg(['-y', '-v', 'error', '-i', trimmed, '-c:a', 'pcm_s16le', out]))
|
|
119
|
+
const limit = (10 ** ((CEILING_DBTP - 0.5) / 20)).toFixed(4)
|
|
120
|
+
// above the compressor's knee a dB of gain moves the loudness by less: each pass steps by what the last dB moved
|
|
121
|
+
let gain = lufs - m0.lufs
|
|
122
|
+
let last: { gain: number; lufs: number } | null = null
|
|
123
|
+
for (let pass = 0; pass < 6; pass++) {
|
|
124
|
+
const af = [`volume=${gain.toFixed(2)}dB`, 'acompressor=threshold=0.1:ratio=3:attack=5:release=80:knee=3', `aresample=${SOUND_RATE * 4}`, `alimiter=limit=${limit}:attack=1:release=50:level=disabled`, `aresample=${SOUND_RATE}`].join(',')
|
|
125
|
+
await ffmpeg(['-y', '-v', 'error', '-i', trimmed, '-af', af, '-c:a', 'pcm_s16le', out])
|
|
126
|
+
const m = await loudness(out)
|
|
127
|
+
if (Math.abs(m.lufs - lufs) <= 0.3) break
|
|
128
|
+
const slope = last && Math.abs(gain - last.gain) > 0.01 ? Math.max(0.15, Math.min(1, (m.lufs - last.lufs) / (gain - last.gain))) : 1
|
|
129
|
+
last = { gain, lufs: m.lufs }
|
|
130
|
+
gain += Math.max(-12, Math.min(12, (lufs - m.lufs) / slope))
|
|
131
|
+
}
|
|
132
|
+
} finally {
|
|
133
|
+
rmSync(trimmed, { force: true })
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
109
137
|
/** the trimmed sound written at its level: `lufs` its integrated loudness (a sound too short to measure, under 0.4 s,
|
|
110
138
|
* set by its peak at -3 dBFS), `peak` its sample peak; never past -1.5 dBTP. A measured static gain, so a short line
|
|
111
139
|
* lands where a long one does */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// the voices a brand declares for its trailers (`.shipkit/identity/brand.ts`, its `trailer.voice` and
|
|
2
|
-
// `trailer.voices`): an ElevenLabs voice, a clip comfy-ts clones,
|
|
2
|
+
// `trailer.voices`): an ElevenLabs voice, a clip comfy-ts clones, a voice comfy-ts designs from words, or the owner's
|
|
3
|
+
// own takes. Pure
|
|
3
4
|
export type TrailerVoice =
|
|
4
5
|
/** ElevenLabs, paid: a voice id of the account or its library */
|
|
5
6
|
| { eleven: string; model?: string; stability?: number; similarity?: number; speed?: number; language?: string }
|
|
@@ -7,6 +8,23 @@ export type TrailerVoice =
|
|
|
7
8
|
| { clone: string; transcript?: string; engine?: string; language?: string }
|
|
8
9
|
/** comfy-ts designs the voice once from its description (the reference reads `line`), then clones it, free */
|
|
9
10
|
| { design: string; line?: string; seed?: number; engine?: string; language?: string }
|
|
11
|
+
/** the owner reads it himself (`record` is his name, as the hub says it): each line plays his take of its words,
|
|
12
|
+
* recorded on the hub's trailer page (takes.ts); until he records one, the `standin` voice reads it (default the
|
|
13
|
+
* brand's voice). `takes: false` plays the standin on every line, his takes kept for when it is true again;
|
|
14
|
+
* `tweak` disguises every take lightly */
|
|
15
|
+
| { record: string; standin?: string; takes?: boolean; tweak?: VoiceTweak }
|
|
16
|
+
|
|
17
|
+
/** a light disguise of his takes, in semitones: `pitch` moves the voice's pitch with its formants kept, `formant` moves
|
|
18
|
+
* the formants (the vocal tract) with the pitch kept; the length never changes */
|
|
19
|
+
export interface VoiceTweak {
|
|
20
|
+
pitch?: number
|
|
21
|
+
formant?: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** the tweak a recorded voice of the brand asks for, by its name; none when it asks none */
|
|
25
|
+
export function voiceTweak(brand: TrailerSoundInput | undefined, name: string): VoiceTweak | undefined {
|
|
26
|
+
return recordVoices(brand).find((v) => v.name === name)?.voice.tweak
|
|
27
|
+
}
|
|
10
28
|
|
|
11
29
|
export interface TrailerSoundInput {
|
|
12
30
|
/** the comfy-ts module folder the free generators run (its tts-voice-clone, tts-voice-design, stable-audio,
|
|
@@ -27,7 +45,31 @@ export const HOUSE_VOICE: TrailerVoice = {
|
|
|
27
45
|
seed: 7,
|
|
28
46
|
}
|
|
29
47
|
|
|
30
|
-
const kinds = (v: TrailerVoice): string[] => ['eleven', 'clone', 'design'].filter((k) => k in v && typeof (v as Record<string, unknown>)[k] === 'string')
|
|
48
|
+
const kinds = (v: TrailerVoice): string[] => ['eleven', 'clone', 'design', 'record'].filter((k) => k in v && typeof (v as Record<string, unknown>)[k] === 'string')
|
|
49
|
+
|
|
50
|
+
export type RecordVoice = Extract<TrailerVoice, { record: string }>
|
|
51
|
+
export const isRecord = (v: TrailerVoice): v is RecordVoice => 'record' in v
|
|
52
|
+
|
|
53
|
+
/** the brand with every recorded voice's `takes` set to `on`: the cut heard in his voice or in its standin's, whatever
|
|
54
|
+
* the brand plays (the trailer page's voice toggle) */
|
|
55
|
+
export function takesAs(brand: TrailerSoundInput | undefined, on: boolean): TrailerSoundInput | undefined {
|
|
56
|
+
if (!brand) return brand
|
|
57
|
+
const set = (v: TrailerVoice): TrailerVoice => (isRecord(v) ? { ...v, takes: on } : v)
|
|
58
|
+
return {
|
|
59
|
+
...brand,
|
|
60
|
+
...(brand.voice ? { voice: set(brand.voice) } : {}),
|
|
61
|
+
...(brand.voices ? { voices: Object.fromEntries(Object.entries(brand.voices).map(([k, v]) => [k, set(v)])) } : {}),
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** the name a take of the default voice is kept under, when the brand's own `voice` is a recorded one */
|
|
66
|
+
export const DEFAULT_VOICE = 'voice'
|
|
67
|
+
|
|
68
|
+
/** the brand's recorded voices by name, its default `voice` under DEFAULT_VOICE */
|
|
69
|
+
export function recordVoices(brand: TrailerSoundInput | undefined): { name: string; voice: RecordVoice }[] {
|
|
70
|
+
const all: [string, TrailerVoice | undefined][] = [[DEFAULT_VOICE, brand?.voice], ...Object.entries(brand?.voices ?? {})]
|
|
71
|
+
return all.flatMap(([name, v]) => (v && isRecord(v) ? [{ name, voice: v }] : []))
|
|
72
|
+
}
|
|
31
73
|
|
|
32
74
|
/** the voice a line reads with: `by` one of the brand's voices, else its voice, else the house narrator */
|
|
33
75
|
export function voiceOf(brand: TrailerSoundInput | undefined, by?: string): TrailerVoice {
|
|
@@ -37,6 +79,14 @@ export function voiceOf(brand: TrailerSoundInput | undefined, by?: string): Trai
|
|
|
37
79
|
throw new Error(`no voice ${by} in the brand: ${names.length ? `its voices are ${names.join(', ')}` : 'it names none (trailer.voices in .shipkit/identity/brand.ts)'}`)
|
|
38
80
|
}
|
|
39
81
|
const k = kinds(v)
|
|
40
|
-
if (k.length !== 1) throw new Error(`the brand's voice${by ? ` ${by}` : ''} names ${k.length ? k.join(' and ') : 'nothing'}: one of eleven (a voice id), clone (a clip)
|
|
82
|
+
if (k.length !== 1) throw new Error(`the brand's voice${by ? ` ${by}` : ''} names ${k.length ? k.join(' and ') : 'nothing'}: one of eleven (a voice id), clone (a clip), design (a description) or record (your own takes)`)
|
|
41
83
|
return v
|
|
42
84
|
}
|
|
85
|
+
|
|
86
|
+
/** who reads a line of a recorded voice while it has no take: its standin, which is no recorded voice itself */
|
|
87
|
+
export function standinOf(brand: TrailerSoundInput | undefined, v: RecordVoice, by: string): { name: string | undefined; voice: TrailerVoice } {
|
|
88
|
+
const name = v.standin
|
|
89
|
+
const voice = name !== undefined ? voiceOf(brand, name) : by === DEFAULT_VOICE ? HOUSE_VOICE : voiceOf(brand)
|
|
90
|
+
if (isRecord(voice)) throw new Error(`the recorded voice ${by} stands in with ${name ?? "the brand's voice"}, recorded too: name a voice that speaks (eleven, clone or design)`)
|
|
91
|
+
return { name, voice }
|
|
92
|
+
}
|
package/src/trailer/sound/gen.ts
CHANGED
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
|
6
6
|
import { tmpdir } from 'node:os'
|
|
7
7
|
import { dirname, join } from 'node:path'
|
|
8
|
-
import { decode, envelope, finish, measure, measureLine, trimOf, waveformPng } from './audio.ts'
|
|
9
|
-
import type { TrailerVoice } from './brand.ts'
|
|
8
|
+
import { decode, envelope, finish, finishVoice, measure, measureLine, trimOf, waveformPng } from './audio.ts'
|
|
9
|
+
import type { TrailerVoice, VoiceTweak } from './brand.ts'
|
|
10
10
|
import { comfyModule, comfyRun } from './comfy.ts'
|
|
11
11
|
import { elevenAsk, elevenCredits, elevenKey, elevenSpeak } from './eleven.ts'
|
|
12
12
|
import { fluidRender } from './fluid.ts'
|
|
13
|
+
import { channelLevels, ffmpeg } from '../ffmpeg.ts'
|
|
13
14
|
import { soundCache } from './run.ts'
|
|
14
15
|
|
|
15
16
|
type Say = (line: string) => void
|
|
@@ -64,9 +65,67 @@ async function designedClip(root: string, comfy: string | undefined, v: Extract<
|
|
|
64
65
|
return { clip, transcript: line }
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
/** the ffmpeg filter that plays these ranges of a sound silent */
|
|
69
|
+
const maskFilter = (mask: readonly (readonly [number, number])[]): string[] => (mask.length === 0 ? [] : [`volume=0:enable='${mask.map(([a, b]) => `between(t,${a.toFixed(3)},${b.toFixed(3)})`).join('+')}'`])
|
|
70
|
+
|
|
71
|
+
/** where a take's own 0 sits on the line's time when he never dragged it: its first sound, the masked ranges silent,
|
|
72
|
+
* 0.05 s early (takes.ts TakeEdit) */
|
|
73
|
+
export async function autoOffset(take: string, mask: readonly (readonly [number, number])[]): Promise<number> {
|
|
74
|
+
return scratch(async (dir) => {
|
|
75
|
+
let src = take
|
|
76
|
+
if (mask.length > 0) {
|
|
77
|
+
src = join(dir, 'masked.wav')
|
|
78
|
+
await ffmpeg(['-y', '-v', 'error', '-i', take, '-af', maskFilter(mask).join(','), '-ac', '2', '-ar', '48000', src])
|
|
79
|
+
}
|
|
80
|
+
const t = trimOf(envelope(await decode(src)), { tailDb: 40 })
|
|
81
|
+
return -Math.max(0, t.start - 0.05)
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** a take as one channel, centred after: the mean of the channels that carry his voice. A mono microphone that
|
|
86
|
+
* MediaRecorder writes as stereo leaves one side silent; a dead channel never halves the voice */
|
|
87
|
+
async function monoOf(take: string): Promise<string> {
|
|
88
|
+
const levels = await channelLevels(take)
|
|
89
|
+
const top = Math.max(...levels)
|
|
90
|
+
const live = levels.flatMap((db, i) => (db > top - 30 ? [i] : []))
|
|
91
|
+
if (live.length === 0) return 'pan=mono|c0=c0'
|
|
92
|
+
return `pan=mono|c0=${live.map((i) => `${(1 / live.length).toFixed(4)}*c${i}`).join('+')}`
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** the filters of a light disguise, the length kept: a pitch move is rubberband with the formants preserved, the same
|
|
96
|
+
* move of both is rubberband with them shifted; a formant move alone is a resample (pitch, formants and length
|
|
97
|
+
* together), then rubberband takes the pitch and the length back */
|
|
98
|
+
export function tweakFilter(t: VoiceTweak | undefined): string[] {
|
|
99
|
+
const p = 2 ** ((t?.pitch ?? 0) / 12)
|
|
100
|
+
const f = 2 ** ((t?.formant ?? 0) / 12)
|
|
101
|
+
const n = (x: number): string => x.toFixed(6)
|
|
102
|
+
if (f === 1 && p === 1) return []
|
|
103
|
+
if (f === 1) return [`rubberband=pitch=${n(p)}:formant=preserved`]
|
|
104
|
+
if (f === p) return [`rubberband=pitch=${n(p)}:formant=shifted`]
|
|
105
|
+
return ['aresample=48000', `asetrate=${n(48000 * f)}`, `rubberband=tempo=${n(1 / f)}:pitch=${n(p / f)}:formant=preserved`, 'aresample=48000']
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** a take he recorded of a line as the cut plays it: one channel, disguised by `tweak`, its masked ranges silent, its
|
|
109
|
+
* own 0 placed at his offset (else at its first sound), cut where the line starts, its tail trimmed, centred, -16
|
|
110
|
+
* LUFS like a made line */
|
|
111
|
+
export async function genTake(o: { take: string; offset: number | null; mask: readonly (readonly [number, number])[]; tweak?: VoiceTweak; out: string; say: Say }): Promise<void> {
|
|
112
|
+
if (!existsSync(o.take)) throw new Error(`no take ${o.take}`)
|
|
113
|
+
const offset = o.offset ?? (await autoOffset(o.take, o.mask))
|
|
114
|
+
await scratch(async (dir) => {
|
|
115
|
+
const placed = join(dir, 'placed.wav')
|
|
116
|
+
const place = offset < 0 ? [`atrim=start=${(-offset).toFixed(3)}`, 'asetpts=PTS-STARTPTS'] : offset > 0 ? [`adelay=${Math.round(offset * 1000)}:all=1`] : []
|
|
117
|
+
const af = [await monoOf(o.take), ...tweakFilter(o.tweak), ...maskFilter(o.mask), ...place, 'pan=stereo|c0=c0|c1=c0'].join(',')
|
|
118
|
+
await ffmpeg(['-y', '-v', 'error', '-i', o.take, '-af', af, '-ar', '48000', '-c:a', 'pcm_s16le', placed])
|
|
119
|
+
const t = trimOf(envelope(await decode(placed)), { tailDb: 40 })
|
|
120
|
+
await finishVoice(placed, join(dir, 'out.wav'), { ...t, start: 0, end: t.end + 0.08 }, LINE_LUFS)
|
|
121
|
+
await land(join(dir, 'out.wav'), o.out, o.say)
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
67
125
|
/** one spoken line in a voice: silence trimmed at both ends, -16 LUFS */
|
|
68
126
|
export async function genVoice(o: { root: string; text: string; voice: TrailerVoice; seed: number; comfy?: string; elevenKey?: string[]; out: string; say: Say }): Promise<void> {
|
|
69
127
|
const v = o.voice
|
|
128
|
+
if ('record' in v) throw new Error(`${v.record} reads this voice: record the line on the hub's trailer page (Voices), then --take <file>`)
|
|
70
129
|
await scratch(async (dir) => {
|
|
71
130
|
let raw: string
|
|
72
131
|
if ('eleven' in v) {
|
|
@@ -5,15 +5,23 @@ import { existsSync } from 'node:fs'
|
|
|
5
5
|
import { isAbsolute, relative } from 'node:path'
|
|
6
6
|
import type { SoundRequest } from '../adapter.ts'
|
|
7
7
|
import type { SoundRun } from '../grammar.ts'
|
|
8
|
-
import type
|
|
9
|
-
import { paidChars, presetOf, type SoundAsk } from './presets.ts'
|
|
8
|
+
import { takesAs, type TrailerSoundInput } from './brand.ts'
|
|
9
|
+
import { paidChars, presetOf, recordedLine, type SoundAsk, type TakeFinder } from './presets.ts'
|
|
10
10
|
import { runSpec, soundRun } from './run.ts'
|
|
11
|
+
import { takeOf } from './takes.ts'
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
/** the brand's sound section; `takes` forces his takes on or off on every recorded voice (undefined: as it says) */
|
|
14
|
+
export async function brandSound(root: string, takes?: boolean): Promise<TrailerSoundInput | undefined> {
|
|
13
15
|
const { loadBrand } = await import('../../assets/run-assets.ts')
|
|
14
16
|
const b = await loadBrand(root)
|
|
15
17
|
if (typeof b === 'string') throw new Error(b)
|
|
16
|
-
return b?.trailer
|
|
18
|
+
return takes === undefined ? b?.trailer : takesAs(b?.trailer, takes)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** the repo's takes, as a recorded voice reads them */
|
|
22
|
+
export const repoTakes = (root: string): TakeFinder => (voice, text) => {
|
|
23
|
+
const t = takeOf(root, voice, text)
|
|
24
|
+
return t ? { path: t.path, offset: t.offset, mask: t.mask } : null
|
|
17
25
|
}
|
|
18
26
|
|
|
19
27
|
/** the run a request makes: its own, else its preset; a file in the repo named by its repo relative path, so the key
|
|
@@ -21,12 +29,12 @@ async function brandSound(root: string): Promise<TrailerSoundInput | undefined>
|
|
|
21
29
|
export function runOf(root: string, r: SoundRequest, brand: TrailerSoundInput | undefined): SoundRun {
|
|
22
30
|
if (r.run) return r.run
|
|
23
31
|
const inside = isAbsolute(r.text) && !relative(root, r.text).startsWith('..')
|
|
24
|
-
return presetOf({ ...r, text: inside ? relative(root, r.text) : r.text }, brand)
|
|
32
|
+
return presetOf({ ...r, text: inside ? relative(root, r.text) : r.text }, brand, repoTakes(root))
|
|
25
33
|
}
|
|
26
34
|
|
|
27
35
|
/** the request's sound file, made when the cache misses */
|
|
28
|
-
export async function resolveSound(root: string, r: SoundRequest, say: (line: string) => void): Promise<string> {
|
|
29
|
-
const run = runOf(root, r, r.run ? undefined : await brandSound(root))
|
|
36
|
+
export async function resolveSound(root: string, r: SoundRequest, say: (line: string) => void, takes?: boolean): Promise<string> {
|
|
37
|
+
const run = runOf(root, r, r.run ? undefined : await brandSound(root, takes))
|
|
30
38
|
return (await soundRun(run, { root, dir: r.dir, ...(r.seconds !== undefined ? { seconds: r.seconds } : {}) }, say)).file
|
|
31
39
|
}
|
|
32
40
|
|
|
@@ -37,17 +45,21 @@ export interface SoundState {
|
|
|
37
45
|
made: boolean
|
|
38
46
|
/** a paid line not made yet: the characters it will cost */
|
|
39
47
|
cost: number | null
|
|
48
|
+
/** a line of a recorded voice he has not read yet: who, and who stands in */
|
|
49
|
+
waiting?: { who: string; standin: string }
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
/** each request's command and whether it is made, for `sk trailer check`; an error is the line's */
|
|
43
|
-
export async function soundStates(root: string, rs: readonly SoundRequest[]): Promise<(SoundState | { line: number; error: string })[]> {
|
|
44
|
-
const brand = rs.some((r) => !r.run) ? await brandSound(root) : undefined
|
|
53
|
+
export async function soundStates(root: string, rs: readonly SoundRequest[], takes?: boolean): Promise<(SoundState | { line: number; error: string })[]> {
|
|
54
|
+
const brand = rs.some((r) => !r.run) ? await brandSound(root, takes) : undefined
|
|
45
55
|
return rs.map((r) => {
|
|
46
56
|
try {
|
|
47
57
|
const run = runOf(root, r, brand)
|
|
48
58
|
const spec = runSpec(run, { root, dir: r.dir, ...(r.seconds !== undefined ? { seconds: r.seconds } : {}) })
|
|
49
59
|
const made = existsSync(spec.file)
|
|
50
|
-
|
|
60
|
+
const rec = r.kind === 'voice' && !r.run ? recordedLine(r, brand, repoTakes(root)) : null
|
|
61
|
+
const waiting = rec && !rec.kept ? { waiting: { who: rec.who, standin: rec.standin.name ?? "the brand's voice" } } : {}
|
|
62
|
+
return { line: r.line, kind: r.kind, cmd: spec.cmd, made, cost: made ? null : paidChars(run, r.text), ...waiting }
|
|
51
63
|
} catch (e) {
|
|
52
64
|
return { line: r.line, error: e instanceof Error ? e.message : String(e) }
|
|
53
65
|
}
|
|
@@ -56,5 +68,7 @@ export async function soundStates(root: string, rs: readonly SoundRequest[]): Pr
|
|
|
56
68
|
|
|
57
69
|
/** a state as the check prints it */
|
|
58
70
|
export const stateLine = (s: SoundState | { line: number; error: string }): string =>
|
|
59
|
-
'error' in s
|
|
71
|
+
'error' in s
|
|
72
|
+
? `line ${s.line}: ${s.error}`
|
|
73
|
+
: `line ${s.line} ${s.kind} ${s.made ? 'made' : `to make${s.cost !== null ? ` (ElevenLabs, about ${s.cost} characters)` : ''}`}${s.waiting ? `, waiting for ${s.waiting.who}'s take (the hub's trailer page, Voices), ${s.waiting.standin} reads it until then` : ''}: ${s.cmd}`
|
|
60
74
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// the house generators as presets of the one sound run: each short form of a .trailer (`voice "<line>"`,
|
|
2
2
|
// `sfx "<prompt>"`, `music "<prompt>"`, `music <file>.mid`) becomes the `sk sound` command that makes it, every input
|
|
3
3
|
// written in its words, so the key holds the voice, the seed and the length (and a .mid's soundfont)
|
|
4
|
-
import { type TrailerSoundInput, type TrailerVoice, voiceOf } from './brand.ts'
|
|
4
|
+
import { DEFAULT_VOICE, isRecord, standinOf, type TrailerSoundInput, type TrailerVoice, voiceOf, type VoiceTweak } from './brand.ts'
|
|
5
5
|
import type { SoundRun } from '../grammar.ts'
|
|
6
6
|
import { ELEVEN_MODEL } from './eleven.ts'
|
|
7
|
+
import type { TakeEdit } from './takes.ts'
|
|
7
8
|
import { fluidIdentity } from './fluid.ts'
|
|
8
9
|
|
|
9
10
|
/** what a line of the trailer asks for */
|
|
@@ -42,18 +43,98 @@ export function voiceFlags(v: TrailerVoice): { flags: string[]; reads: string[]
|
|
|
42
43
|
const txt = v.clone.replace(/\.[a-z0-9]+$/i, '.txt')
|
|
43
44
|
return { flags: ['--clone', q(v.clone), ...opt('transcript', v.transcript), ...opt('engine', v.engine), ...opt('language', v.language)], reads: v.transcript === undefined ? [v.clone, txt] : [v.clone] }
|
|
44
45
|
}
|
|
46
|
+
if (isRecord(v)) throw new Error(`${v.record}'s voice has no flags: a line reads his take (--take) or its standin`)
|
|
45
47
|
return { flags: ['--design', q(v.design), ...opt('design-line', v.line), ...opt('design-seed', v.seed), ...opt('engine', v.engine), ...opt('language', v.language)], reads: [] }
|
|
46
48
|
}
|
|
47
49
|
|
|
50
|
+
/** his take of a line's words (repo relative) and how far he dragged it, or null: what a recorded voice reads
|
|
51
|
+
* (takes.ts takeOf) */
|
|
52
|
+
export type TakeFinder = (voice: string, text: string) => Take | null
|
|
53
|
+
export type Take = { path: string } & TakeEdit
|
|
54
|
+
|
|
55
|
+
/** a line of a recorded voice: his take when he made one and the voice plays takes, else who stands in for him;
|
|
56
|
+
* `kept` is his take whether it plays or not */
|
|
57
|
+
export function recordedLine(a: Pick<SoundAsk, 'by' | 'text'>, brand: TrailerSoundInput | undefined, takes: TakeFinder | undefined): { voice: string; who: string; on: boolean; kept: Take | null; take: Take | null; tweak: VoiceTweak | undefined; standin: { name: string | undefined; voice: TrailerVoice } } | null {
|
|
58
|
+
const voice = voiceOf(brand, a.by)
|
|
59
|
+
if (!isRecord(voice)) return null
|
|
60
|
+
const name = a.by ?? DEFAULT_VOICE
|
|
61
|
+
const on = voice.takes !== false
|
|
62
|
+
const kept = takes?.(name, a.text) ?? null
|
|
63
|
+
return { voice: name, who: voice.record, on, kept, take: on ? kept : null, tweak: voice.tweak, standin: standinOf(brand, voice, name) }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** the run its standin makes for a line of a recorded voice, whether it plays or not: the paid line kept beside his
|
|
67
|
+
* take, so a switch back costs nothing */
|
|
68
|
+
export function standinPreset(a: SoundAsk, brand: TrailerSoundInput | undefined): SoundRun | null {
|
|
69
|
+
const voice = voiceOf(brand, a.by)
|
|
70
|
+
if (!isRecord(voice)) return null
|
|
71
|
+
const s = standinOf(brand, voice, a.by ?? DEFAULT_VOICE)
|
|
72
|
+
return voicePreset(a, s.voice, brand)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** how a take is levelled (audio.ts finishVoice), in its words as a comment: a new leveller makes every take again */
|
|
76
|
+
export const TAKE_LEVEL = 'level 3'
|
|
77
|
+
|
|
78
|
+
/** his take of a line as a made sound, its masks silent, placed at his offset, levelled, disguised by the voice's
|
|
79
|
+
* `tweak`: the build's run, and the hub's the moment it lands or he edits it */
|
|
80
|
+
export const takeRun = (text: string, take: Take, tweak?: VoiceTweak): SoundRun => {
|
|
81
|
+
const tw = tweakWords(tweak)
|
|
82
|
+
return {
|
|
83
|
+
cmd: ['sk sound voice', q(text), '--take', q(take.path), ...(take.offset !== null ? [`--offset=${num(take.offset)}`] : []), ...(take.mask.length > 0 ? ['--mask', take.mask.map(([a, b]) => `${num(a)}-${num(b)}`).join(',')] : []), ...(tw ? ['--tweak', tw] : []), '--out {out}', `# ${TAKE_LEVEL}`].join(' '),
|
|
84
|
+
reads: [take.path],
|
|
85
|
+
light: true,
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** a tweak in its flag's words, `pitch=-1.5,formant=0`; none when it moves nothing */
|
|
90
|
+
export function tweakWords(t: VoiceTweak | undefined): string | null {
|
|
91
|
+
const pitch = t?.pitch ?? 0
|
|
92
|
+
const formant = t?.formant ?? 0
|
|
93
|
+
return pitch === 0 && formant === 0 ? null : `pitch=${num(pitch)},formant=${num(formant)}`
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** `--tweak pitch=-1.5,formant=0.5` as a tweak, in semitones */
|
|
97
|
+
export function tweakOf(words: string | undefined): VoiceTweak {
|
|
98
|
+
if (words === undefined || words.trim() === '') return {}
|
|
99
|
+
const out: VoiceTweak = {}
|
|
100
|
+
for (const w of words.split(',')) {
|
|
101
|
+
const m = /^\s*(pitch|formant)=(-?[\d.]+)\s*$/.exec(w)
|
|
102
|
+
if (!m) throw new Error(`--tweak takes pitch=<semitones>,formant=<semitones>; got ${w}`)
|
|
103
|
+
const v = Number(m[2])
|
|
104
|
+
if (Math.abs(v) > 12) throw new Error(`--tweak ${m[1]} ${v}: at most 12 semitones either way`)
|
|
105
|
+
out[m[1] as 'pitch' | 'formant'] = v
|
|
106
|
+
}
|
|
107
|
+
return out
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** `--mask 0.01-0.12,1.5-1.6` as ranges */
|
|
111
|
+
export function maskOf(words: string | undefined): [number, number][] {
|
|
112
|
+
if (words === undefined || words.trim() === '') return []
|
|
113
|
+
return words.split(',').map((w) => {
|
|
114
|
+
const m = /^\s*([\d.]+)-([\d.]+)\s*$/.exec(w)
|
|
115
|
+
if (!m) throw new Error(`--mask takes ranges in seconds, a-b,c-d; got ${w}`)
|
|
116
|
+
return [Number(m[1]), Number(m[2])] as [number, number]
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** a line read by a voice that speaks */
|
|
121
|
+
function voicePreset(a: SoundAsk, voice: TrailerVoice, brand: TrailerSoundInput | undefined): SoundRun {
|
|
122
|
+
// the comfy-ts folder is in the words, so another folder makes the sound again
|
|
123
|
+
const comfy = brand?.comfy ? ['--comfy', q(brand.comfy)] : []
|
|
124
|
+
const v = voiceFlags(voice)
|
|
125
|
+
return { cmd: ['sk sound voice', q(a.text), ...v.flags, ...('eleven' in voice ? [] : comfy), '--seed', String(a.seed ?? 1), '--out {out}'].join(' '), ...(v.reads.length ? { reads: v.reads } : {}), remote: true }
|
|
126
|
+
}
|
|
127
|
+
|
|
48
128
|
/** the run that makes what the line asks for */
|
|
49
|
-
export function presetOf(a: SoundAsk, brand: TrailerSoundInput | undefined): SoundRun {
|
|
129
|
+
export function presetOf(a: SoundAsk, brand: TrailerSoundInput | undefined, takes?: TakeFinder): SoundRun {
|
|
50
130
|
const seed = ['--seed', String(a.seed ?? 1)]
|
|
51
131
|
// the comfy-ts folder is in the words, so another folder makes the sound again
|
|
52
132
|
const comfy = brand?.comfy ? ['--comfy', q(brand.comfy)] : []
|
|
53
133
|
if (a.kind === 'voice') {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
134
|
+
const rec = recordedLine(a, brand, takes)
|
|
135
|
+
// his take is trimmed and levelled like any line, on this machine; no take yet, or takes off: the standin
|
|
136
|
+
if (rec?.take) return takeRun(a.text, rec.take, rec.tweak)
|
|
137
|
+
return voicePreset(a, rec ? rec.standin.voice : voiceOf(brand, a.by), brand)
|
|
57
138
|
}
|
|
58
139
|
if (a.kind === 'sfx') return { cmd: ['sk sound sfx', q(a.text), '--seconds', num(a.for ?? SFX_SECONDS), ...seed, ...(a.hit ? ['--hit'] : []), ...comfy, '--out {out}'].join(' '), remote: true }
|
|
59
140
|
// the soundfont and fluidsynth are in the words as a comment: another one renders the file again
|
package/src/trailer/sound/run.ts
CHANGED
|
@@ -55,7 +55,7 @@ let queue: Promise<unknown> = Promise.resolve()
|
|
|
55
55
|
export function soundRun(r: SoundRun, p: RunPlace, say: (line: string) => void): Promise<{ file: string; made: boolean }> {
|
|
56
56
|
const spec = runSpec(r, p)
|
|
57
57
|
if (existsSync(spec.file)) return Promise.resolve({ file: spec.file, made: false })
|
|
58
|
-
const job = queue.then(() => make(spec, p.root, r.remote === true, say))
|
|
58
|
+
const job = queue.then(() => make(spec, p.root, r.remote === true || r.light === true, say))
|
|
59
59
|
queue = job.catch(() => undefined)
|
|
60
60
|
return job
|
|
61
61
|
}
|