decklight 0.8.1 → 0.9.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/PLATFORM.md +666 -0
- package/README.md +224 -150
- package/SPEC.md +732 -886
- package/cli/agent-review.mjs +245 -0
- package/cli/agents.mjs +25 -5
- package/cli/associate.mjs +12 -12
- package/cli/audit.mjs +42 -10
- package/cli/banner.mjs +41 -17
- package/cli/bundle-audio.mjs +183 -0
- package/cli/bundle.mjs +383 -31
- package/cli/cast.mjs +7 -7
- package/cli/check.mjs +961 -0
- package/cli/clone-deck.mjs +179 -0
- package/cli/commands.mjs +345 -0
- package/cli/comments.mjs +64 -18
- package/cli/commit-flow.mjs +44 -19
- package/cli/commit-message.mjs +51 -74
- package/cli/commit-split.mjs +601 -0
- package/cli/deck-refs.mjs +59 -0
- package/cli/deck-routes.mjs +67 -0
- package/cli/deckfile.mjs +3 -5
- package/cli/decklight.mjs +68 -289
- package/cli/design-system-deps.mjs +209 -0
- package/cli/design-system-edit.mjs +194 -0
- package/cli/design-system-refs.mjs +409 -0
- package/cli/design-system.mjs +429 -0
- package/cli/doctor.mjs +115 -0
- package/cli/edit-git.mjs +353 -0
- package/cli/edit-handover.mjs +445 -0
- package/cli/edit-look.mjs +388 -0
- package/cli/edit-slides.mjs +683 -0
- package/cli/edit.mjs +2126 -842
- package/cli/enhance.mjs +483 -0
- package/cli/extension.mjs +10 -10
- package/cli/font-refs.mjs +273 -0
- package/cli/font.mjs +246 -0
- package/cli/git-tree.mjs +1 -1
- package/cli/git.mjs +65 -11
- package/cli/import.mjs +56 -10
- package/cli/init.mjs +400 -234
- package/cli/library.mjs +127 -0
- package/cli/loader.mjs +3 -1
- package/cli/marketplace.mjs +215 -21
- package/cli/narrate.mjs +176 -0
- package/cli/open-browser.mjs +63 -0
- package/cli/open.mjs +943 -0
- package/cli/pdf.mjs +41 -13
- package/cli/pkg.mjs +44 -2
- package/cli/plugin.mjs +43 -41
- package/cli/port-conflict.mjs +53 -23
- package/cli/pptx-export.mjs +57 -24
- package/cli/publish.mjs +8 -4
- package/cli/qr.mjs +1 -1
- package/cli/record.mjs +14 -12
- package/cli/remote.mjs +11 -11
- package/cli/restore.mjs +11 -4
- package/cli/review-ref.mjs +125 -0
- package/cli/review-remote.mjs +92 -48
- package/cli/review-routes.mjs +254 -0
- package/cli/review-store.mjs +47 -7
- package/cli/review-submit.mjs +47 -57
- package/cli/runtime-link.mjs +560 -0
- package/cli/serve.mjs +235 -44
- package/cli/setup.mjs +112 -0
- package/cli/sign.mjs +1 -1
- package/cli/skill-content.mjs +190 -33
- package/cli/skills.mjs +107 -24
- package/cli/start.mjs +110 -0
- package/cli/supervise.mjs +6 -6
- package/cli/theme-refs.mjs +515 -0
- package/cli/theme.mjs +181 -137
- package/cli/trust.mjs +83 -0
- package/cli/units.mjs +39 -42
- package/cli/update-check.mjs +1 -5
- package/cli/upgrade.mjs +194 -28
- package/cli/upstream.mjs +4 -3
- package/cli/util.mjs +4 -4
- package/cli/wizard.mjs +6 -6
- package/dist/build-info.json +1 -1
- package/dist/decklight.css +1126 -49
- package/dist/decklight.js +212 -115
- package/dist/decklight.js.map +4 -4
- package/docs/GLOSSARY.md +141 -0
- package/docs/architecture.svg +17 -17
- package/package.json +4 -2
- package/themes/README.md +9 -8
- package/themes/reveal-solarized.css +10 -0
- package/tools/args.mjs +20 -0
- package/tools/atomic-write.mjs +48 -0
- package/tools/brand-palette.mjs +717 -0
- package/tools/bridge.mjs +1 -1
- package/tools/build-groups.mjs +42 -0
- package/tools/color.mjs +48 -0
- package/tools/deck-html.mjs +396 -11
- package/tools/design-system-format.mjs +753 -0
- package/tools/elevenlabs-tts.mjs +110 -17
- package/tools/exec.mjs +1 -1
- package/tools/extension-check.mjs +31 -7
- package/tools/font-format.mjs +190 -0
- package/tools/font-stacks.mjs +24 -0
- package/tools/gemini-tts.mjs +3 -0
- package/tools/lipsync-config.mjs +103 -0
- package/tools/lipsync-engines.mjs +205 -2
- package/tools/lipsync-server.mjs +264 -41
- package/tools/lipsync.mjs +37 -18
- package/tools/local-voice.mjs +32 -42
- package/tools/narration-manifest.mjs +196 -0
- package/tools/narration-synth.mjs +416 -0
- package/tools/pptx.mjs +776 -19
- package/tools/publish-targets.mjs +1 -1
- package/tools/publish-voices.mjs +3 -3
- package/tools/recording-impact.mjs +7 -3
- package/tools/render-theme.mjs +33 -0
- package/tools/review-anchor.mjs +28 -12
- package/tools/semver.mjs +40 -0
- package/tools/sentences.mjs +180 -0
- package/tools/shot.mjs +14 -7
- package/tools/site-voices.mjs +232 -0
- package/tools/template-theme.mjs +1 -1
- package/tools/test-impact.mjs +17 -10
- package/tools/theme-check.mjs +30 -3
- package/tools/tts-cache.mjs +4 -3
- package/tools/tts-engines.mjs +38 -20
- package/tools/tts-setup.mjs +7 -7
- package/tools/video-options.mjs +34 -0
- package/tools/video.mjs +461 -48
- package/tools/voiceover-server.mjs +185 -104
- package/tools/voiceover.mjs +119 -261
- package/tools/zip.mjs +1 -1
- package/cli/dev.mjs +0 -623
- package/cli/present.mjs +0 -853
- package/cli/review.mjs +0 -361
- package/tools/publish-site-voices.mjs +0 -75
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// narration ON THE FLY (SPEC PRESENTING live voice). The browser can't mint Google
|
|
7
7
|
// credentials (nor run piper), so this process holds them and exposes:
|
|
8
8
|
//
|
|
9
|
-
// GET /ping → { ok, engine, model, voices, stylable } (player probes)
|
|
9
|
+
// GET /ping → { ok, engine, model, voices, stylable, audioTags } (player probes)
|
|
10
10
|
// GET /voices → [[name, flavor], …]
|
|
11
11
|
// POST /tts → audio/wav { text, voice, style }
|
|
12
12
|
//
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
// 127.0.0.1 only. Responses are cached in memory AND on disk (tools/tts-cache.mjs)
|
|
36
36
|
// by (engine, model, format, voice, style, text), so stepping back through
|
|
37
37
|
// slides replays instantly, a restarted bridge replays for free, and
|
|
38
|
-
// `decklight
|
|
38
|
+
// `decklight narrate` reuses whatever this bridge already said.
|
|
39
39
|
|
|
40
40
|
import { createServer } from 'node:http';
|
|
41
41
|
import { createInterface } from 'node:readline/promises';
|
|
42
|
-
import { canBind, resolvePortConflict } from '../cli/port-conflict.mjs';
|
|
42
|
+
import { canBind, resolvePortConflict, describePortOutcome } from '../cli/port-conflict.mjs';
|
|
43
43
|
import { execFile } from 'node:child_process';
|
|
44
44
|
import { cacheHome, clipKey, createTtsCache, extFor } from './tts-cache.mjs';
|
|
45
45
|
|
|
@@ -65,8 +65,9 @@ export function openVoiceSettings(exec = execFile, platform = process.platform)
|
|
|
65
65
|
}
|
|
66
66
|
import { resolveEngine, engineBlocker, engineMenu, engineStatus, ENGINES } from './tts-engines.mjs';
|
|
67
67
|
import { loadTtsConfig, runSetupWizard, ttsConfigPath } from './tts-setup.mjs';
|
|
68
|
-
import { argReader, isMain } from './args.mjs';
|
|
68
|
+
import { argReader, isMain, parsePort, badPort } from './args.mjs';
|
|
69
69
|
import { corsHeaders, readBody } from './bridge.mjs';
|
|
70
|
+
import { forEngine } from './sentences.mjs';
|
|
70
71
|
import { installedVoices } from '../cli/units.mjs';
|
|
71
72
|
import { readyLine } from '../cli/banner.mjs';
|
|
72
73
|
|
|
@@ -100,7 +101,7 @@ export async function ttsMain(args) {
|
|
|
100
101
|
// coverage only when it exits through process.exit, so a bridge the suite
|
|
101
102
|
// stops with SIGKILL — or with an unhandled SIGTERM — reports NOTHING, and
|
|
102
103
|
// the request handler that is this file's whole point read as 27% covered
|
|
103
|
-
// while thirty tests drove it. The edit and
|
|
104
|
+
// while thirty tests drove it. The edit and no-trust mode already do this.
|
|
104
105
|
process.on('SIGTERM', () => process.exit(0));
|
|
105
106
|
if (args.includes('--help')) {
|
|
106
107
|
console.log(`usage: decklight tts [--port 8787] [--engine ${ENGINES.join('|')}|<installed>] [--project <id>]
|
|
@@ -115,23 +116,24 @@ export async function ttsMain(args) {
|
|
|
115
116
|
piper local neural TTS — offline, unlimited, no credentials, no cost.
|
|
116
117
|
elevenlabs your ElevenLabs account's own voices — the ones you cloned included, listed
|
|
117
118
|
first in the picker. Needs $ELEVENLABS_API_KEY (never written to disk).
|
|
118
|
-
--tts-model
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
--tts-model eleven_v4 (default) reads a script's audio tags ([whispers],
|
|
120
|
+
[laughs], [long pause]) as direction, and the picker's tone step appears
|
|
121
|
+
for it / eleven_v4_turbo for latency / eleven_v3, the first tag model —
|
|
122
|
+
higher latency, more variable / eleven_multilingual_v2, no tags (a tag
|
|
123
|
+
in the notes is taken out rather than read aloud).
|
|
122
124
|
--tts-stability creative|natural|robust — how hard v3 follows a tag (v3 only;
|
|
123
125
|
refused on any other model rather than silently doing nothing).
|
|
124
126
|
--tts-format mp3 if your plan has no PCM output (costs you the panel's
|
|
125
127
|
Record this deck… and lip-sync, both of which read WAV).
|
|
126
128
|
|
|
127
|
-
<installed> any engine from a marketplace (decklight
|
|
129
|
+
<installed> any engine from a marketplace (decklight library add engine <name>) — --engine
|
|
128
130
|
takes its name like any of the six above, and the picker treats it the same.
|
|
129
131
|
|
|
130
132
|
project also read from $GOOGLE_CLOUD_PROJECT (gemini and chirp only)
|
|
131
133
|
|
|
132
134
|
cache every synthesis is kept in ${cacheHome()} under a key made of
|
|
133
135
|
(engine, model, format, voice, style, text), so a restarted bridge
|
|
134
|
-
replays for free and 'decklight
|
|
136
|
+
replays for free and 'decklight narrate' reuses what you already
|
|
135
137
|
previewed instead of paying for it twice. Oldest clips are dropped
|
|
136
138
|
past 400 MB. --no-cache re-synthesizes everything, for a fresh take.
|
|
137
139
|
|
|
@@ -142,7 +144,8 @@ export async function ttsMain(args) {
|
|
|
142
144
|
return;
|
|
143
145
|
}
|
|
144
146
|
const { opt } = argReader(args);
|
|
145
|
-
const port =
|
|
147
|
+
const port = parsePort(opt('--port', 8787));
|
|
148
|
+
if (port === null) { console.error(`decklight tts: ${badPort('--port', opt('--port'))}`); process.exitCode = 1; return; }
|
|
146
149
|
const saved = loadTtsConfig();
|
|
147
150
|
const tty = Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
148
151
|
const engineName = opt('--engine') ?? saved?.engine ?? 'gemini';
|
|
@@ -173,13 +176,16 @@ export async function ttsMain(args) {
|
|
|
173
176
|
engine = await resolveEngine({
|
|
174
177
|
engine: engineName,
|
|
175
178
|
project: opt('--project') ?? process.env.GOOGLE_CLOUD_PROJECT ?? saved?.project,
|
|
176
|
-
|
|
177
|
-
|
|
179
|
+
// every setting reads the saved config under its flag: `decklight
|
|
180
|
+
// setup voice --model …` (and the guided setup) is how a value is
|
|
181
|
+
// given once, now that `decklight <deck>` no longer passes the flags
|
|
182
|
+
model: opt('--tts-model') ?? savedFor?.model,
|
|
183
|
+
location: opt('--location') ?? saved?.location,
|
|
178
184
|
voice: opt('--voice') ?? savedFor?.voice,
|
|
179
185
|
dataDir: opt('--data-dir') ?? savedFor?.dataDir,
|
|
180
|
-
lang: opt('--lang'),
|
|
186
|
+
lang: opt('--lang') ?? saved?.lang,
|
|
181
187
|
format: opt('--tts-format') ?? savedFor?.format,
|
|
182
|
-
stability: opt('--tts-stability'),
|
|
188
|
+
stability: opt('--tts-stability') ?? savedFor?.stability,
|
|
183
189
|
});
|
|
184
190
|
} catch (e) {
|
|
185
191
|
// an explicit --engine/--project is a hand on the wheel — fail exactly
|
|
@@ -213,20 +219,83 @@ export async function ttsMain(args) {
|
|
|
213
219
|
// deck can now change which engine that is (SPEC `NARRATION`), and a roster
|
|
214
220
|
// or an id map left behind from the previous one would offer voices the
|
|
215
221
|
// current engine cannot say.
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
222
|
+
//
|
|
223
|
+
// SEVERAL ENGINES AT ONCE. One bridge serves every tab, and each tab speaks
|
|
224
|
+
// with the engine ITS live voice was picked on — a deck on ElevenLabs and a
|
|
225
|
+
// speaker view, or a second deck, on the system voice. When the bridge held
|
|
226
|
+
// ONE engine and a tab switched it (POST /engine, or a deck restoring its
|
|
227
|
+
// saved engine on load), every other tab went on sending voice names the
|
|
228
|
+
// new engine did not have, and fell silent without a word. So the bridge
|
|
229
|
+
// keeps each engine it is asked for, built once, beside the one it started
|
|
230
|
+
// with (the DEFAULT — what a request naming no engine gets, as before):
|
|
231
|
+
// /ping, /voices, /engines and /tts take `?engine=` / `{ engine }`.
|
|
232
|
+
const held = new Map(); // name → { engine, refs, refIds }
|
|
233
|
+
const hold = (e) => {
|
|
234
|
+
const refs = installedVoices(e.name);
|
|
235
|
+
const h = { engine: e, refs, refIds: new Map(refs.map((r) => [r.label, r.voiceId])) };
|
|
236
|
+
held.set(e.name, h);
|
|
237
|
+
if (refs.length) console.log(` voices: +${refs.length} installed for ${e.name} (decklight library list voice)`);
|
|
238
|
+
return h;
|
|
223
239
|
};
|
|
224
|
-
|
|
240
|
+
hold(engine);
|
|
241
|
+
const useEngine = (e) => { engine = e; if (!held.has(e.name)) hold(e); };
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The engine a request asked for — built the first time it is asked, and
|
|
245
|
+
* refused with the blocker when this machine cannot run it (checked BEFORE
|
|
246
|
+
* building: two of the six build fine and only fail on the first sentence).
|
|
247
|
+
* No name: the default. Throws `{ status, body }` for the route to send.
|
|
248
|
+
*/
|
|
249
|
+
const building = new Map();
|
|
250
|
+
async function engineFor(name) {
|
|
251
|
+
if (!name || name === engine.name) return held.get(engine.name);
|
|
252
|
+
if (held.has(name)) return held.get(name);
|
|
253
|
+
if (!building.has(name)) {
|
|
254
|
+
building.set(name, (async () => {
|
|
255
|
+
const opts = menuOpts();
|
|
256
|
+
const status = engineStatus(name, opts);
|
|
257
|
+
if (ENGINES.includes(name) && !status.ready) {
|
|
258
|
+
throw { status: 409, body: { ok: false, error: status.reason, ...status, ...(engineBlocker(status, opts) ?? {}) } };
|
|
259
|
+
}
|
|
260
|
+
let next;
|
|
261
|
+
try { next = await resolveEngine({ ...opts, engine: name, model: undefined }); }
|
|
262
|
+
catch (e) { throw { status: 409, body: { ok: false, error: String(e.message ?? e).slice(0, 200) } }; }
|
|
263
|
+
console.log(` engine: ${name} ready too (asked for by a deck)`);
|
|
264
|
+
if (next.caveat) console.log(` ${next.caveat}`);
|
|
265
|
+
return hold(next);
|
|
266
|
+
})().finally(() => building.delete(name)));
|
|
267
|
+
}
|
|
268
|
+
return building.get(name);
|
|
269
|
+
}
|
|
225
270
|
|
|
226
|
-
const voiceRoster = async () => [
|
|
227
|
-
|
|
228
|
-
|
|
271
|
+
const voiceRoster = async (h = held.get(engine.name)) => [
|
|
272
|
+
// [name, flavor, group, langs] — the languages ride fourth, for engines
|
|
273
|
+
// that know them (ElevenLabs), so the picker can filter and open on the deck's
|
|
274
|
+
...(h.engine.listVoices
|
|
275
|
+
? (await h.engine.listVoices()).map((v) => (v.langs?.length ? [v.name, v.flavor, null, v.langs] : [v.name, v.flavor]))
|
|
276
|
+
: h.engine.voices),
|
|
277
|
+
...h.refs.map((r) => [r.label, r.marketplace ?? 'installed']),
|
|
229
278
|
];
|
|
279
|
+
/** What a deck is told about one engine — /ping's answer, and a switch's. */
|
|
280
|
+
const describe = async (h) => ({
|
|
281
|
+
ok: true,
|
|
282
|
+
engine: h.engine.name,
|
|
283
|
+
model: h.engine.model,
|
|
284
|
+
stylable: h.engine.stylable, // gemini alone can be told HOW to say it
|
|
285
|
+
// ElevenLabs v3/v4 act on [whispers]-style tags; for any other engine
|
|
286
|
+
// the player (and /tts) take them out rather than have them read aloud
|
|
287
|
+
audioTags: h.engine.audioTags === true,
|
|
288
|
+
// the engine's standing note — for `say` with no Siri voice this is
|
|
289
|
+
// the download hint, and the picker keys its install row off it
|
|
290
|
+
...(h.engine.caveat ? { caveat: h.engine.caveat } : {}),
|
|
291
|
+
...(h.engine.cost ? { cost: h.engine.cost } : {}),
|
|
292
|
+
// A roster the bridge cannot fetch is not a reason to report itself dead:
|
|
293
|
+
// the player falls back to its built-in list, and a synth would say why.
|
|
294
|
+
voices: await voiceRoster(h).catch((e) => {
|
|
295
|
+
console.error(` voices: ${String(e.message ?? e).slice(0, 160)}`);
|
|
296
|
+
return [];
|
|
297
|
+
}),
|
|
298
|
+
});
|
|
230
299
|
|
|
231
300
|
// The engine's NAME is part of every cache key, so a swap cannot serve one
|
|
232
301
|
// engine's audio under another's voice — the cache survives the switch, and
|
|
@@ -254,7 +323,7 @@ export async function ttsMain(args) {
|
|
|
254
323
|
const menuOpts = () => ({
|
|
255
324
|
env: process.env,
|
|
256
325
|
project: opt('--project') ?? process.env.GOOGLE_CLOUD_PROJECT ?? saved?.project,
|
|
257
|
-
voice: opt('--voice'), dataDir: opt('--data-dir'), lang: opt('--lang'),
|
|
326
|
+
voice: opt('--voice') ?? savedFor?.voice, dataDir: opt('--data-dir') ?? savedFor?.dataDir, lang: opt('--lang') ?? saved?.lang,
|
|
258
327
|
});
|
|
259
328
|
|
|
260
329
|
// the player reads the cost estimate for its debug window
|
|
@@ -262,33 +331,25 @@ export async function ttsMain(args) {
|
|
|
262
331
|
let totalCost = 0;
|
|
263
332
|
let totalChars = 0;
|
|
264
333
|
|
|
334
|
+
const sendJson = (res, status, body) => {
|
|
335
|
+
res.writeHead(status, { ...CORS, 'content-type': 'application/json' });
|
|
336
|
+
res.end(JSON.stringify(body));
|
|
337
|
+
};
|
|
265
338
|
const server = createServer(async (req, res) => {
|
|
266
339
|
if (req.method === 'OPTIONS') { res.writeHead(204, CORS); return res.end(); }
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
});
|
|
274
|
-
res.writeHead(200, { ...CORS, 'content-type': 'application/json' });
|
|
275
|
-
return res.end(JSON.stringify({
|
|
276
|
-
ok: true,
|
|
277
|
-
engine: engine.name,
|
|
278
|
-
model: engine.model,
|
|
279
|
-
stylable: engine.stylable, // gemini alone can be told HOW to say it
|
|
280
|
-
// the engine's standing note — for `say` with no Siri voice this is
|
|
281
|
-
// the download hint, and the picker keys its install row off it
|
|
282
|
-
...(engine.caveat ? { caveat: engine.caveat } : {}),
|
|
283
|
-
voices, // piper speaks one voice, not the star roster
|
|
284
|
-
}));
|
|
340
|
+
// routes by PATH: `?engine=` rides the query (the edit server forwards it)
|
|
341
|
+
const url = new URL(req.url, 'http://127.0.0.1');
|
|
342
|
+
const asked = url.searchParams.get('engine') || null;
|
|
343
|
+
if (req.method === 'GET' && url.pathname === '/tts/ping') {
|
|
344
|
+
try { return sendJson(res, 200, await describe(await engineFor(asked))); }
|
|
345
|
+
catch (e) { return e?.status ? sendJson(res, e.status, e.body) : sendJson(res, 500, { ok: false, error: String(e) }); }
|
|
285
346
|
}
|
|
286
347
|
// ── the one exec a deck may trigger: open the voice-download pane ──
|
|
287
348
|
// Darwin only, loopback only (like every route here), and the argv is a
|
|
288
349
|
// FROZEN CONSTANT — no byte of the request reaches it. It opens a System
|
|
289
350
|
// Settings pane and does nothing else; the download itself stays a human
|
|
290
351
|
// clicking, which is the whole point of the pane.
|
|
291
|
-
if (req.method === 'POST' &&
|
|
352
|
+
if (req.method === 'POST' && url.pathname === '/tts/voices/install') {
|
|
292
353
|
if (process.platform !== 'darwin' && process.platform !== 'win32') { res.writeHead(404); return res.end(); }
|
|
293
354
|
try {
|
|
294
355
|
openVoiceSettings();
|
|
@@ -303,79 +364,88 @@ export async function ttsMain(args) {
|
|
|
303
364
|
}
|
|
304
365
|
}
|
|
305
366
|
// ── which engine is speaking, and what else could (SPEC `NARRATION`) ──
|
|
306
|
-
if (req.method === 'GET' &&
|
|
367
|
+
if (req.method === 'GET' && url.pathname === '/tts/engines') {
|
|
307
368
|
// Ready or not, every engine is listed. Hiding the ones this machine
|
|
308
369
|
// cannot use would answer "where did ElevenLabs go?" with silence — the
|
|
309
370
|
// useful answer is that it is there and needs a key.
|
|
310
371
|
const opts = menuOpts();
|
|
311
|
-
|
|
372
|
+
// `current` is the ASKING tab's engine (`?engine=`), not the default:
|
|
373
|
+
// two tabs on two engines each see their own ticked
|
|
374
|
+
const mine = asked && held.has(asked) ? asked : engine.name;
|
|
375
|
+
const menu = engineMenu(opts).map((e) => ({ ...e, current: e.name === mine }));
|
|
312
376
|
// An engine the bridge was STARTED with is ready by definition — it is
|
|
313
377
|
// speaking. Detection can disagree (a marketplace engine is not one of
|
|
314
378
|
// the six, and a project passed by flag is invisible to a later probe),
|
|
315
379
|
// and a picker that greyed out the running engine would be absurd.
|
|
316
380
|
if (!menu.some((e) => e.current)) {
|
|
317
|
-
|
|
381
|
+
const h = held.get(mine);
|
|
382
|
+
menu.unshift({ name: mine, ready: true, reason: 'ok', current: true, cost: h?.engine.cost });
|
|
318
383
|
}
|
|
384
|
+
// an engine this bridge already holds is ready by definition — it speaks
|
|
385
|
+
for (const e of menu) if (held.has(e.name)) Object.assign(e, { ready: true, reason: 'ok' });
|
|
319
386
|
res.writeHead(200, { ...CORS, 'content-type': 'application/json' });
|
|
320
|
-
return res.end(JSON.stringify({ ok: true, engine:
|
|
387
|
+
return res.end(JSON.stringify({ ok: true, engine: mine, engines: menu }));
|
|
321
388
|
}
|
|
322
|
-
|
|
389
|
+
// Makes an engine the DEFAULT — what a request naming none gets. Kept for
|
|
390
|
+
// decks built before `?engine=`, which switch the bridge this way; a
|
|
391
|
+
// current deck names its engine on every request instead, and never calls
|
|
392
|
+
// this, so no tab can switch another's voice (see `held` above).
|
|
393
|
+
if (req.method === 'POST' && url.pathname === '/tts/engine') {
|
|
323
394
|
let name;
|
|
324
395
|
try { ({ engine: name } = JSON.parse((await readBody(req)).toString())); }
|
|
325
396
|
catch { name = null; }
|
|
326
|
-
if (typeof name !== 'string' || !name) {
|
|
327
|
-
|
|
328
|
-
|
|
397
|
+
if (typeof name !== 'string' || !name) return sendJson(res, 400, { ok: false, error: 'name the engine' });
|
|
398
|
+
let h;
|
|
399
|
+
try { h = await engineFor(name); }
|
|
400
|
+
catch (e) { return e?.status ? sendJson(res, e.status, e.body) : sendJson(res, 500, { ok: false, error: String(e) }); }
|
|
401
|
+
const changed = h.engine.name !== engine.name;
|
|
402
|
+
if (changed) {
|
|
403
|
+
console.log(` engine: default ${engine.name} → ${h.engine.name} (asked for by the deck)`);
|
|
404
|
+
useEngine(h.engine);
|
|
329
405
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
const opts = menuOpts();
|
|
336
|
-
// Checked BEFORE building, because two of the six build perfectly well
|
|
337
|
-
// and only fail on the first sentence — which mid-talk is a keypress into
|
|
338
|
-
// silence. A refusal here is recoverable; that one is not.
|
|
339
|
-
const status = engineStatus(name, opts);
|
|
340
|
-
if (ENGINES.includes(name) && !status.ready) {
|
|
341
|
-
// The blocker travels WITH the refusal. The deck's picker normally has
|
|
342
|
-
// it already (it came down with /engines), but a menu can be a minute
|
|
343
|
-
// stale — a key exported and un-exported, a model deleted — and a
|
|
344
|
-
// refusal the deck cannot put words to is a row that does nothing when
|
|
345
|
-
// clicked.
|
|
346
|
-
res.writeHead(409, { ...CORS, 'content-type': 'application/json' });
|
|
347
|
-
return res.end(JSON.stringify({
|
|
348
|
-
ok: false, error: status.reason, ...status, ...(engineBlocker(status, opts) ?? {}),
|
|
349
|
-
}));
|
|
350
|
-
}
|
|
351
|
-
let next;
|
|
406
|
+
return sendJson(res, 200, { ...(await describe(h)), changed });
|
|
407
|
+
}
|
|
408
|
+
// The voice LIBRARY (ElevenLabs): search by language — free, changes
|
|
409
|
+
// nothing — and add one to the account, on the presenter's own ⏎.
|
|
410
|
+
if (req.method === 'GET' && url.pathname === '/tts/voices/library') {
|
|
352
411
|
try {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
useEngine(next);
|
|
362
|
-
console.log(` engine: ${was} → ${engine.name} (asked for by the deck)`);
|
|
363
|
-
if (engine.caveat) console.log(` ${engine.caveat}`);
|
|
364
|
-
const voices = await voiceRoster().catch(() => []);
|
|
365
|
-
res.writeHead(200, { ...CORS, 'content-type': 'application/json' });
|
|
366
|
-
return res.end(JSON.stringify({ ok: true, engine: engine.name, model: engine.model,
|
|
367
|
-
stylable: engine.stylable, cost: engine.cost, caveat: engine.caveat, voices, changed: true }));
|
|
412
|
+
const h = await engineFor(asked);
|
|
413
|
+
if (!h.engine.searchLibrary) return sendJson(res, 404, { ok: false, error: `${h.engine.name} has no voice library — ElevenLabs does` });
|
|
414
|
+
const page = Number(url.searchParams.get('page')) || 0;
|
|
415
|
+
const r = await h.engine.searchLibrary({
|
|
416
|
+
language: url.searchParams.get('language') || undefined, search: url.searchParams.get('search') || undefined, page,
|
|
417
|
+
});
|
|
418
|
+
return sendJson(res, 200, { ok: true, engine: h.engine.name, page, ...r });
|
|
419
|
+
} catch (e) { return e?.status ? sendJson(res, e.status, e.body) : sendJson(res, 502, { ok: false, error: String(e.message ?? e) }); }
|
|
368
420
|
}
|
|
369
|
-
if (req.method === '
|
|
370
|
-
|
|
371
|
-
|
|
421
|
+
if (req.method === 'POST' && url.pathname === '/tts/voices/library/add') {
|
|
422
|
+
try {
|
|
423
|
+
const { engine: wanted, owner, id, name } = JSON.parse((await readBody(req)).toString());
|
|
424
|
+
const h = await engineFor(wanted || asked);
|
|
425
|
+
if (!h.engine.addLibraryVoice) return sendJson(res, 404, { ok: false, error: `${h.engine.name} has no voice library — ElevenLabs does` });
|
|
426
|
+
const added = await h.engine.addLibraryVoice({ owner, id, name });
|
|
427
|
+
console.log(` voices: added "${added.name}" to the ElevenLabs account, from the voice library`);
|
|
428
|
+
return sendJson(res, 200, { ok: true, ...added, voices: await voiceRoster(h) });
|
|
429
|
+
} catch (e) { return e?.status ? sendJson(res, e.status, e.body) : sendJson(res, 502, { ok: false, error: String(e.message ?? e) }); }
|
|
372
430
|
}
|
|
373
|
-
if (req.method === '
|
|
431
|
+
if (req.method === 'GET' && url.pathname === '/tts/voices') {
|
|
432
|
+
try { return sendJson(res, 200, await voiceRoster(await engineFor(asked))); }
|
|
433
|
+
catch (e) { return e?.status ? sendJson(res, e.status, e.body) : sendJson(res, 500, { ok: false, error: String(e) }); }
|
|
434
|
+
}
|
|
435
|
+
if (req.method === 'POST' && url.pathname === '/tts') {
|
|
374
436
|
try {
|
|
375
|
-
const { text, voice: picked, style } = JSON.parse((await readBody(req)).toString());
|
|
437
|
+
const { text: said, voice: picked, style, engine: wanted } = JSON.parse((await readBody(req)).toString());
|
|
438
|
+
// the engine THIS tab speaks with — never whichever another tab last chose
|
|
439
|
+
let h;
|
|
440
|
+
try { h = await engineFor(wanted || asked); }
|
|
441
|
+
catch (e) { if (e?.status) return sendJson(res, e.status, e.body); throw e; }
|
|
442
|
+
const { engine, refIds } = h;
|
|
443
|
+
// an audio tag is direction for a voice that can act on it and is
|
|
444
|
+
// never read aloud by one that cannot (SPEC `PRESENTING`)
|
|
445
|
+
const text = forEngine(engine, said);
|
|
376
446
|
if (!text?.trim()) { res.writeHead(400, CORS); return res.end('no text'); }
|
|
377
447
|
const voice = refIds.get(picked) ?? picked;
|
|
378
|
-
// The key is the SAME function `decklight
|
|
448
|
+
// The key is the SAME function `decklight narrate` hashes with, and
|
|
379
449
|
// that is the point: a sentence previewed here and then batch-recorded
|
|
380
450
|
// is one synthesis, not two identical bills (SPEC `NARRATION`).
|
|
381
451
|
const ext = extFor(engine.synth.mimeType ?? 'audio/wav');
|
|
@@ -452,7 +522,7 @@ export async function ttsMain(args) {
|
|
|
452
522
|
// it, so they were the one place the deck could still look broken.
|
|
453
523
|
//
|
|
454
524
|
// On a TTY it names the occupant and offers a choice; anywhere else — and
|
|
455
|
-
//
|
|
525
|
+
// `open` spawns these with a piped stdin, so that is the usual case — it
|
|
456
526
|
// moves to the next free port and says so. The player finds the bridge by
|
|
457
527
|
// probing, so a moved port costs nothing.
|
|
458
528
|
// `canBind`, NOT `isPortOpen`: this file's own note says why, and getting it
|
|
@@ -470,11 +540,17 @@ export async function ttsMain(args) {
|
|
|
470
540
|
kind: 'bridge',
|
|
471
541
|
ask: process.stdin.isTTY && process.stdout.isTTY ? askLine : undefined,
|
|
472
542
|
log: console.log,
|
|
543
|
+
// Under `open`, how it ended is this bridge's row on the banner: ✓ when
|
|
544
|
+
// one is already there and serves the deck, ✗ when the port is somebody
|
|
545
|
+
// else's and the bridge may not move. Standalone, the lines as before.
|
|
546
|
+
outcome: process.env.DECKLIGHT_BANNER
|
|
547
|
+
? (o) => console.log(readyLine({ key: 'voice', text: describePortOutcome({ ...o, kind: 'bridge' }), mark: o.ending === 'reuse' ? 'ok' : 'fail' }))
|
|
548
|
+
: null,
|
|
473
549
|
})
|
|
474
550
|
: port;
|
|
475
551
|
// null is "stand down" — either a bridge is already serving this port, or
|
|
476
552
|
// somebody else holds it and this one cannot move (the deck only ever calls
|
|
477
|
-
// the one number). Exiting is the honest outcome:
|
|
553
|
+
// the one number). Exiting is the honest outcome: `open` prints "carrying on
|
|
478
554
|
// without it" and the deck degrades where you can see it, instead of a
|
|
479
555
|
// bridge running somewhere nothing will ever knock.
|
|
480
556
|
if (asked === null) process.exit(0);
|
|
@@ -486,12 +562,15 @@ export async function ttsMain(args) {
|
|
|
486
562
|
// `cost` is optional (SPEC ENGINE_UNITS) — an installed engine that
|
|
487
563
|
// quotes no list price says nothing here rather than "(undefined)".
|
|
488
564
|
const price = engine.cost ? ` (${engine.cost})` : '';
|
|
489
|
-
// Under
|
|
565
|
+
// Under `open` this is a banner ROW, not a line: `open` prints one block
|
|
490
566
|
// ending in the DECK's url, and a bridge url above it is the wrong thing
|
|
491
567
|
// to click. Standalone, the bridge is the whole program and says so.
|
|
492
568
|
if (process.env.DECKLIGHT_BANNER) {
|
|
493
|
-
|
|
494
|
-
|
|
569
|
+
// the row is what is on and where; the price and the caveat are for
|
|
570
|
+
// the standalone line below, or a DECKLIGHT_DEBUG run
|
|
571
|
+
console.log(readyLine({ key: 'voice', text: `${engine.name} · ${engine.model} · :${bound}`, mark: 'ok' }));
|
|
572
|
+
if (process.env.DECKLIGHT_DEBUG && engine.cost) console.log(`cost: ${engine.cost}`);
|
|
573
|
+
if (process.env.DECKLIGHT_DEBUG && engine.caveat) console.log(engine.caveat);
|
|
495
574
|
} else {
|
|
496
575
|
console.log(`decklight tts bridge on http://127.0.0.1:${bound} — ${engine.name} · ${engine.model}${price} — Ctrl-C stops`);
|
|
497
576
|
// Stated here, once, where the presenter is still choosing — not
|
|
@@ -507,4 +586,6 @@ export async function ttsMain(args) {
|
|
|
507
586
|
});
|
|
508
587
|
}
|
|
509
588
|
|
|
510
|
-
if (isMain(import.meta.url))
|
|
589
|
+
if (isMain(import.meta.url)) {
|
|
590
|
+
ttsMain(process.argv.slice(2)).catch((e) => { console.error(`decklight tts: ${e.message}`); process.exitCode = 1; });
|
|
591
|
+
}
|