dsh-tts-chat-answer 0.4.0 → 0.5.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/README.md +102 -88
- package/lib/client.js +97 -38
- package/lib/index.js +98 -11
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,6 +3,75 @@
|
|
|
3
3
|
`dsh-tts-chat-answer` narrates every completed assistant answer from DeepSeek
|
|
4
4
|
Harness and saves the audio locally for later playback and play from web UI.
|
|
5
5
|
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
The package is a profile **bundle**: installing it also selects it as a layer.
|
|
9
|
+
Pick one source.
|
|
10
|
+
|
|
11
|
+
From the plugin market, add the index source under **Plugins → Discover → Add
|
|
12
|
+
index source**:
|
|
13
|
+
|
|
14
|
+
```text
|
|
15
|
+
https://vladimircores.github.io/dsh-tts-chat-answer/index.json
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
From npm, which serves the same tarball the market installs:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
dsh plugin --profile web add dsh-tts-chat-answer
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
From GitHub, which needs no build step because the JavaScript is committed:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
dsh plugin --profile web add github:VladimirCores/dsh-tts-chat-answer
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
From a checkout, install the plugin's own dependencies and link it:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
cd /absolute/path/to/dsh-tts-chat-answer
|
|
34
|
+
npm install
|
|
35
|
+
dsh plugin --profile web add .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`dsh plugin add` installs the dependency and selects the bundle in
|
|
39
|
+
`~/.dsh/profiles/web/package.json`. If a package ends up installed but not
|
|
40
|
+
selected, add `dsh-tts-chat-answer` to `dsh.profile.bundles`. A running profile
|
|
41
|
+
does not always hot-add a new row, so restart the Host; afterwards
|
|
42
|
+
`~/.local/share/dsh-tts-chat-answer/.ready` proves the plugin mounted. Disable
|
|
43
|
+
it with `dsh plugin --profile web remove dsh-tts-chat-answer`, or set
|
|
44
|
+
`enabled: false` in the profile patch.
|
|
45
|
+
|
|
46
|
+
pnpm 11 applies a **24-hour `minimumReleaseAge` cooldown** by default. A version
|
|
47
|
+
published in the last day is listed in the index but still fails to install with
|
|
48
|
+
`ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION`, and even removing it fails while the
|
|
49
|
+
lockfile holds that version. Wait until the release is a day old, or set
|
|
50
|
+
`minimumReleaseAge: 0` in the profile's `pnpm-workspace.yaml` (for example
|
|
51
|
+
`~/.dsh/profiles/web/pnpm-workspace.yaml`) to install immediately. Restore the
|
|
52
|
+
setting afterwards so later installs keep the cooldown.
|
|
53
|
+
|
|
54
|
+
## Setup
|
|
55
|
+
|
|
56
|
+
After installing, run the interactive setup:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npx -p dsh-tts-chat-answer dsh-tts-chat-answer-setup
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
From a checkout, run `node setup.mjs` instead. The prompt asks for the profile,
|
|
63
|
+
the voice, and the playback mode, then writes a managed `tts-chat-answer`
|
|
64
|
+
override into that profile's `cordis.patch.yml`. Restart the Host afterwards;
|
|
65
|
+
`~/.local/share/dsh-tts-chat-answer/.ready` appears once the plugin mounts.
|
|
66
|
+
|
|
67
|
+
The voice menu is a numbered selector: pick a preset or the custom row and type
|
|
68
|
+
any Edge voice id. The playback menu offers `inline` (in-page audio) or `native`
|
|
69
|
+
(system player with in-page fallback). Options: `--profile web` skips the
|
|
70
|
+
profile question, `--yes` accepts the defaults, and `--dry-run` prints the
|
|
71
|
+
generated YAML without writing. Re-running updates the block delimited by
|
|
72
|
+
`# >>> dsh-tts-chat-answer setup >>>` in place and saves a timestamped copy of
|
|
73
|
+
the previous patch file.
|
|
74
|
+
|
|
6
75
|
## Storage
|
|
7
76
|
|
|
8
77
|
The plugin stores audio files in `~/.local/share/dsh-tts-chat-answer/`, grouped
|
|
@@ -42,6 +111,18 @@ GET /dsh-tts-chat-answer/status?session=<session-id>&turn=<turn>
|
|
|
42
111
|
While the MP3 is being generated it shows `Generating…`; once ready it shows
|
|
43
112
|
`Play`. The host reports `playMode` in the same response.
|
|
44
113
|
|
|
114
|
+
Messages that existed before the plugin was installed have no MP3, so their
|
|
115
|
+
control shows `Generate` instead of `Play`. Clicking it narrates that existing
|
|
116
|
+
answer and then polls until the audio is ready:
|
|
117
|
+
|
|
118
|
+
```text
|
|
119
|
+
POST /dsh-tts-chat-answer/generate
|
|
120
|
+
{"session":"<session-id>","turn":<turn>}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
A turn whose last attempt failed shows `Retry`. Generation uses the same queue,
|
|
124
|
+
voice, and output layout as automatic narration.
|
|
125
|
+
|
|
45
126
|
`playMode: "inline"` (the default) plays in the Web UI through one shared
|
|
46
127
|
`HTMLAudioElement`. The control becomes `Pause` while playing and `Resume`
|
|
47
128
|
while paused; a `Stop` button resets it. Pressing Play on another answer stops
|
|
@@ -102,97 +183,24 @@ Choose the last menu row to enter any other Edge voice id. The setup derives
|
|
|
102
183
|
section lets you override it. The fallback is only used when Edge returns no
|
|
103
184
|
audio for the primary voice.
|
|
104
185
|
|
|
105
|
-
##
|
|
106
|
-
|
|
107
|
-
The package is a profile **bundle**. Install it from the checkout:
|
|
108
|
-
|
|
109
|
-
```bash
|
|
110
|
-
cd /absolute/path/to/plugins/dsh-tts-chat-answer
|
|
111
|
-
npm install
|
|
112
|
-
dsh plugin --profile web add .
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
`dsh plugin add` installs the dependency and normally selects the bundle in
|
|
116
|
-
`~/.dsh/profiles/web/package.json`. If it is installed but not selected, add it
|
|
117
|
-
to `dsh.profile.bundles`:
|
|
118
|
-
|
|
119
|
-
```json
|
|
120
|
-
{
|
|
121
|
-
"dsh": {
|
|
122
|
-
"profile": {
|
|
123
|
-
"bundles": [
|
|
124
|
-
"@deepseek-ai/dsh-base",
|
|
125
|
-
"dsh-tts-chat-answer"
|
|
126
|
-
]
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
Alternatively, insert it directly in `~/.dsh/profiles/web/cordis.patch.yml`:
|
|
133
|
-
|
|
134
|
-
```yaml
|
|
135
|
-
- insert:
|
|
136
|
-
- id: tts-chat-answer
|
|
137
|
-
name: 'dsh-tts-chat-answer'
|
|
138
|
-
config:
|
|
139
|
-
enabled: true
|
|
140
|
-
outputDir: '~/.local/share/dsh-tts-chat-answer'
|
|
141
|
-
engine: 'edge'
|
|
142
|
-
playMode: 'inline'
|
|
143
|
-
voice: 'en-US-AriaNeural'
|
|
144
|
-
rate: '+10%'
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
Restart the DSH Host once after the first installation. A running profile does
|
|
148
|
-
not always hot-add a new module row; restarting is deterministic. After restart,
|
|
149
|
-
this file proves the plugin mounted:
|
|
150
|
-
|
|
151
|
-
```bash
|
|
152
|
-
cat ~/.local/share/dsh-tts-chat-answer/.ready
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
Remove the bundle from `dsh.profile.bundles` (or set `enabled: false`) to
|
|
156
|
-
disable it.
|
|
157
|
-
|
|
158
|
-
## Interactive setup
|
|
159
|
-
|
|
160
|
-
`setup.mjs` prompts for the narration settings and writes a managed
|
|
161
|
-
`tts-chat-answer` override into a profile's `cordis.patch.yml`. The voice
|
|
162
|
-
prompt is a numbered selector; pick a listed voice or choose the custom row
|
|
163
|
-
to type any Edge voice id. The playback prompt offers `inline` (in-page audio)
|
|
164
|
-
or `native` (system app with in-page fallback):
|
|
165
|
-
|
|
166
|
-
```bash
|
|
167
|
-
node setup.mjs # prompt, profile defaults to web
|
|
168
|
-
node setup.mjs --profile web # skip the profile prompt
|
|
169
|
-
node setup.mjs --profile web --yes
|
|
170
|
-
node setup.mjs --dry-run # print the generated YAML, write nothing
|
|
171
|
-
```
|
|
186
|
+
## Plugin market
|
|
172
187
|
|
|
173
|
-
The
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
patch file is created before each write. The script does not install the
|
|
177
|
-
package; install it first with `dsh plugin add`, then run setup and restart the
|
|
178
|
-
Host.
|
|
188
|
+
The package is published on npm as `dsh-tts-chat-answer` and declares
|
|
189
|
+
`dsh.bundle`, an `engines.dsh` range, an icon, an English locale, and its
|
|
190
|
+
repository/author metadata, so a DSH plugin index can list it.
|
|
179
191
|
|
|
180
|
-
|
|
192
|
+
`site/index.json` is deployed by `.github/workflows/pages.yml` and served at
|
|
193
|
+
<https://vladimircores.github.io/dsh-tts-chat-answer/>.
|
|
181
194
|
|
|
182
|
-
|
|
183
|
-
locale, and its repository/author metadata, so it can be listed by a DSH plugin
|
|
184
|
-
index. A ready index lives at `site/index.json`; regenerate it after a release
|
|
185
|
-
with the reference generator:
|
|
195
|
+
Regenerate the entry with the reference generator after a release:
|
|
186
196
|
|
|
187
197
|
```bash
|
|
188
198
|
pnpm --filter @deepseek-ai/dsh-plugin-market-generator start \
|
|
189
199
|
--input plugins.txt --output site/index.json --title "TTS Chat Answer"
|
|
190
200
|
```
|
|
191
201
|
|
|
192
|
-
`plugins.txt` holds one line per source: the
|
|
193
|
-
|
|
194
|
-
published. Serve the `site/` directory over HTTPS and add its `index.json` URL
|
|
195
|
-
under **Plugins → Discover**. See the
|
|
202
|
+
`plugins.txt` holds one line per source: the npm name produces an npm entry; an
|
|
203
|
+
`https://` Git URL produces a commit-pinned entry instead. See the
|
|
196
204
|
[plugin index guide](https://deepseek-harness.github.io/deepseek-harness/en/guide/plugin-market).
|
|
197
205
|
|
|
198
206
|
## Publish a release
|
|
@@ -215,14 +223,20 @@ path at publish time.
|
|
|
215
223
|
Then publish and tag:
|
|
216
224
|
|
|
217
225
|
```bash
|
|
218
|
-
npm
|
|
219
|
-
|
|
226
|
+
npm version patch # bumps package.json, commits, tags vX.Y.Z
|
|
227
|
+
npm publish
|
|
228
|
+
git push --follow-tags
|
|
220
229
|
```
|
|
221
230
|
|
|
222
|
-
After the registry accepts the version,
|
|
223
|
-
|
|
224
|
-
`{"type": "npm"}
|
|
225
|
-
|
|
231
|
+
After the registry accepts the version, prepend it to `site/index.json`: set
|
|
232
|
+
`version`, set `publishTimestamp` to the registry time (`npm view
|
|
233
|
+
dsh-tts-chat-answer time --json`), and keep `source` as `{"type": "npm"}`. Keep
|
|
234
|
+
earlier versions in the array so the page can install them. The Pages workflow
|
|
235
|
+
republishes `site/` on the next push.
|
|
236
|
+
|
|
237
|
+
Expect a one-day gap before the new entry is installable: pnpm's default
|
|
238
|
+
24-hour release-age cooldown rejects any version younger than that. The
|
|
239
|
+
[Install](#install) note explains the workaround and when to restore the setting.
|
|
226
240
|
|
|
227
241
|
## Requirements
|
|
228
242
|
|
package/lib/client.js
CHANGED
|
@@ -191,9 +191,10 @@ window.__ModuleLoader__.load({
|
|
|
191
191
|
* Poll the host for this turn's narration state.
|
|
192
192
|
* @param {string} sessionId - slot-injected session id.
|
|
193
193
|
* @param {number} turn - turn number.
|
|
194
|
+
* @param {number} revision - bump to restart polling after a generation request.
|
|
194
195
|
* @returns {[object, Function]} state and setter.
|
|
195
196
|
*/
|
|
196
|
-
function useAudioStatus(sessionId, turn) {
|
|
197
|
+
function useAudioStatus(sessionId, turn, revision) {
|
|
197
198
|
const [status, setStatus] = React.useState({ state: "loading", error: null });
|
|
198
199
|
|
|
199
200
|
React.useEffect(() => {
|
|
@@ -246,7 +247,7 @@ window.__ModuleLoader__.load({
|
|
|
246
247
|
controller.abort();
|
|
247
248
|
if (timer !== undefined) clearTimeout(timer);
|
|
248
249
|
};
|
|
249
|
-
}, [sessionId, turn]);
|
|
250
|
+
}, [sessionId, turn, revision]);
|
|
250
251
|
|
|
251
252
|
return [status, setStatus];
|
|
252
253
|
}
|
|
@@ -283,6 +284,30 @@ window.__ModuleLoader__.load({
|
|
|
283
284
|
}, [enabled, sessionId, turn, setStatus]);
|
|
284
285
|
}
|
|
285
286
|
|
|
287
|
+
/**
|
|
288
|
+
* Pick the footer button caption for the current narration state.
|
|
289
|
+
* A turn without audio offers Generate; a failed one offers Retry.
|
|
290
|
+
*
|
|
291
|
+
* @param {{state: string, error?: string|null}} status - host status.
|
|
292
|
+
* @param {{active: boolean, playing: boolean, inlineLoading: boolean,
|
|
293
|
+
* busyAction: boolean, generating: boolean, playbackError: string|null}} view
|
|
294
|
+
* - local control state.
|
|
295
|
+
* @returns {string} button caption.
|
|
296
|
+
*/
|
|
297
|
+
function controlLabel(status, view) {
|
|
298
|
+
if (view.generating) return "Generating…";
|
|
299
|
+
if (view.busyAction) return "Opening…";
|
|
300
|
+
if (view.inlineLoading) return "Starting…";
|
|
301
|
+
if (view.active) return view.playing ? "Pause" : "Resume";
|
|
302
|
+
if (status.state === "missing") return "Generate";
|
|
303
|
+
if (status.state === "error") return "Retry";
|
|
304
|
+
if (status.state === "loading" || status.state === "queued" || status.state === "processing") {
|
|
305
|
+
return "Generating…";
|
|
306
|
+
}
|
|
307
|
+
if (view.playbackError !== null) return "Audio error";
|
|
308
|
+
return "Play";
|
|
309
|
+
}
|
|
310
|
+
|
|
286
311
|
/**
|
|
287
312
|
* Play/Pause and Stop controls rendered in the completed-turn footer.
|
|
288
313
|
* @param {{turn: number|{turn: number}, sessionId: string}} props - slot props and injected session.
|
|
@@ -292,7 +317,9 @@ window.__ModuleLoader__.load({
|
|
|
292
317
|
// The turnTail slot exposes the whole Turn owner object, while older
|
|
293
318
|
// slots passed the bare number. Accept both and key everything by number.
|
|
294
319
|
const turnNumber = typeof turn === "number" ? turn : turn?.turn;
|
|
295
|
-
const [
|
|
320
|
+
const [revision, setRevision] = React.useState(0);
|
|
321
|
+
const [generating, setGenerating] = React.useState(false);
|
|
322
|
+
const [status, setStatus] = useAudioStatus(sessionId, turnNumber, revision);
|
|
296
323
|
const inlineState = useInlineState();
|
|
297
324
|
const [fallbackInline, setFallbackInline] = React.useState(false);
|
|
298
325
|
const [busyAction, setBusyAction] = React.useState(false);
|
|
@@ -302,6 +329,7 @@ window.__ModuleLoader__.load({
|
|
|
302
329
|
const key = `${String(sessionId)}:${String(turnNumber)}`;
|
|
303
330
|
const ready = status.state === "ready";
|
|
304
331
|
const busy = status.state === "loading" || status.state === "queued" || status.state === "processing";
|
|
332
|
+
const canGenerate = status.state === "missing" || status.state === "error";
|
|
305
333
|
const inlineActive = inlineState.key === key
|
|
306
334
|
&& (inlineState.state === "playing" || inlineState.state === "paused" || inlineState.state === "loading");
|
|
307
335
|
const nativePlayback = usingInline ? undefined : status.playback;
|
|
@@ -406,32 +434,64 @@ window.__ModuleLoader__.load({
|
|
|
406
434
|
nativePlaying, sessionId, turnNumber, key, audioUrl, status, setStatus,
|
|
407
435
|
]);
|
|
408
436
|
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
:
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
437
|
+
const onGenerate = React.useCallback(async () => {
|
|
438
|
+
if (!canGenerate || generating) return;
|
|
439
|
+
setGenerating(true);
|
|
440
|
+
try {
|
|
441
|
+
const response = await fetch("/dsh-tts-chat-answer/generate", {
|
|
442
|
+
method: "POST",
|
|
443
|
+
credentials: "same-origin",
|
|
444
|
+
headers: { "content-type": "application/json" },
|
|
445
|
+
body: JSON.stringify({ session: sessionId, turn: turnNumber }),
|
|
446
|
+
});
|
|
447
|
+
const body = await response.json().catch(() => ({}));
|
|
448
|
+
if (!response.ok) throw new Error(body.error ?? `HTTP ${response.status}`);
|
|
449
|
+
setStatus({
|
|
450
|
+
state: body.state === "ready" ? "ready" : "queued",
|
|
451
|
+
playMode: status.playMode,
|
|
452
|
+
error: null,
|
|
453
|
+
});
|
|
454
|
+
// Re-run the status hook so it polls until the queue produces audio.
|
|
455
|
+
setRevision((value) => value + 1);
|
|
456
|
+
} catch (error) {
|
|
457
|
+
setStatus({ state: "error", error: error?.message ?? "Could not generate audio" });
|
|
458
|
+
} finally {
|
|
459
|
+
setGenerating(false);
|
|
460
|
+
}
|
|
461
|
+
}, [canGenerate, generating, sessionId, turnNumber, status.playMode, setStatus]);
|
|
462
|
+
|
|
463
|
+
const label = controlLabel(status, {
|
|
464
|
+
active,
|
|
465
|
+
playing,
|
|
466
|
+
inlineLoading: inlineActive && inlineState.state === "loading",
|
|
467
|
+
busyAction,
|
|
468
|
+
generating,
|
|
469
|
+
playbackError,
|
|
470
|
+
});
|
|
471
|
+
const hint = generating
|
|
472
|
+
? "Generating audio…"
|
|
473
|
+
: canGenerate
|
|
474
|
+
? status.state === "error"
|
|
475
|
+
? status.error
|
|
476
|
+
: "No audio for this message yet — generate it"
|
|
477
|
+
: status.state === "error"
|
|
478
|
+
? status.error
|
|
479
|
+
: playbackError !== null
|
|
480
|
+
? playbackError
|
|
481
|
+
: active
|
|
482
|
+
? `${playing ? "Playing" : "Paused"} ${formatTime(positionMs)}${durationMs > 0 ? ` / ${formatTime(durationMs)}` : ""}`
|
|
483
|
+
: busy
|
|
484
|
+
? "Preparing audio…"
|
|
485
|
+
: busyAction
|
|
486
|
+
? "Opening in the system player…"
|
|
487
|
+
: null;
|
|
488
|
+
const actionTitle = canGenerate
|
|
489
|
+
? status.state === "error"
|
|
490
|
+
? "Retry narration"
|
|
491
|
+
: "Generate narration"
|
|
492
|
+
: active
|
|
493
|
+
? playing ? "Pause narration" : "Resume narration"
|
|
494
|
+
: "Play narration";
|
|
435
495
|
|
|
436
496
|
return React.createElement(
|
|
437
497
|
"span",
|
|
@@ -440,18 +500,16 @@ window.__ModuleLoader__.load({
|
|
|
440
500
|
"button",
|
|
441
501
|
{
|
|
442
502
|
type: "button",
|
|
443
|
-
onClick: onPrimary,
|
|
444
|
-
disabled: !ready
|
|
503
|
+
onClick: canGenerate ? onGenerate : onPrimary,
|
|
504
|
+
disabled: busyAction || generating || (!ready && !canGenerate),
|
|
445
505
|
style: {
|
|
446
506
|
...BUTTON_STYLE,
|
|
447
|
-
opacity: ready ? 1 : 0.55,
|
|
448
|
-
cursor: ready ? "pointer" : "default",
|
|
507
|
+
opacity: ready || canGenerate ? 1 : 0.55,
|
|
508
|
+
cursor: ready || canGenerate ? "pointer" : "default",
|
|
449
509
|
},
|
|
450
|
-
title:
|
|
451
|
-
"aria-label":
|
|
452
|
-
|
|
453
|
-
: "Play narration",
|
|
454
|
-
"aria-busy": busy,
|
|
510
|
+
title: actionTitle,
|
|
511
|
+
"aria-label": actionTitle,
|
|
512
|
+
"aria-busy": busy || generating,
|
|
455
513
|
"data-state": active ? (playing ? "playing" : "paused") : status.state,
|
|
456
514
|
},
|
|
457
515
|
label,
|
|
@@ -493,6 +551,7 @@ window.__ModuleLoader__.load({
|
|
|
493
551
|
inlineStop,
|
|
494
552
|
ensureInlineAudio,
|
|
495
553
|
getInlineSnapshot,
|
|
554
|
+
controlLabel,
|
|
496
555
|
};
|
|
497
556
|
return module.exports;
|
|
498
557
|
},
|
package/lib/index.js
CHANGED
|
@@ -167,7 +167,7 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
167
167
|
// `inject` keeps non-web profiles working: without these services the
|
|
168
168
|
// callback never runs, but generation and the ready marker still load.
|
|
169
169
|
if (typeof ctx.inject === "function") {
|
|
170
|
-
ctx.inject(["webServer", "connection"], (webCtx) => {
|
|
170
|
+
ctx.inject(["webServer", "connection", "sessions"], (webCtx) => {
|
|
171
171
|
registerAudioRoute(webCtx);
|
|
172
172
|
});
|
|
173
173
|
}
|
|
@@ -441,6 +441,77 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
441
441
|
sendJson(res, 200, payload);
|
|
442
442
|
},
|
|
443
443
|
}),
|
|
444
|
+
webCtx.webServer.register({
|
|
445
|
+
kind: "exact",
|
|
446
|
+
path: "/dsh-tts-chat-answer/generate",
|
|
447
|
+
handler: async (req, res) => {
|
|
448
|
+
if (!authorize(req, res)) return;
|
|
449
|
+
if (req.method !== "POST") {
|
|
450
|
+
res.statusCode = 405;
|
|
451
|
+
res.setHeader("allow", "POST");
|
|
452
|
+
res.end();
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const contentType = String(req.headers["content-type"] ?? "").split(";", 1)[0].trim().toLowerCase();
|
|
456
|
+
if (contentType !== "application/json") {
|
|
457
|
+
sendJson(res, 415, { error: "content-type must be application/json" });
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
let body;
|
|
461
|
+
try {
|
|
462
|
+
body = await readJsonBody(req, 4096);
|
|
463
|
+
} catch {
|
|
464
|
+
sendJson(res, 400, { error: "request body is not valid JSON" });
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const sessionId = typeof body?.session === "string" ? body.session : "";
|
|
468
|
+
const turn = Number(body?.turn);
|
|
469
|
+
if (sessionId.length === 0 || !Number.isInteger(turn) || turn < 0) {
|
|
470
|
+
sendJson(res, 400, { error: "session and non-negative integer turn are required" });
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const existing = await findAudio(cfg.outputDir, sessionId, turn);
|
|
474
|
+
if (existing !== undefined) {
|
|
475
|
+
sendJson(res, 200, { ok: true, state: "ready" });
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
const running = state.jobs.get(`${sessionId}:${turn}`);
|
|
479
|
+
if (running !== undefined) {
|
|
480
|
+
sendJson(res, 200, {
|
|
481
|
+
ok: true,
|
|
482
|
+
state: running.status === "processing" ? "processing" : "queued",
|
|
483
|
+
});
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
const sessions = Reflect.get(webCtx, "sessions");
|
|
487
|
+
const session = sessions?.get?.(sessionId);
|
|
488
|
+
if (session === undefined) {
|
|
489
|
+
sendJson(res, 404, { error: "session is not loaded; open the conversation first" });
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
const picked = pickAssistantText(session, turn);
|
|
493
|
+
if (picked === undefined) {
|
|
494
|
+
sendJson(res, 422, { error: "no assistant answer for this turn" });
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
const speech = prepareSpeech(picked.text, cfg);
|
|
498
|
+
if (speech.length < cfg.minChars) {
|
|
499
|
+
sendJson(res, 422, { error: "answer is too short to narrate" });
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
if (state.queue.length >= cfg.maxQueue) {
|
|
503
|
+
sendJson(res, 429, { error: "narration queue is full" });
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const job = buildJob(session, turn, picked, speech, undefined);
|
|
507
|
+
state.seen.add(job.key);
|
|
508
|
+
state.jobs.set(job.key, { status: "queued", createdAt: job.createdAt });
|
|
509
|
+
state.queue.push(job);
|
|
510
|
+
log.info(`generate ${job.key} workspace=${job.workspaceKey} (${speech.length} speakable)`);
|
|
511
|
+
void drain();
|
|
512
|
+
sendJson(res, 200, { ok: true, state: "queued" });
|
|
513
|
+
},
|
|
514
|
+
}),
|
|
444
515
|
webCtx.webServer.register({
|
|
445
516
|
kind: "exact",
|
|
446
517
|
path: "/dsh-tts-chat-answer/open",
|
|
@@ -598,16 +669,39 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
598
669
|
}
|
|
599
670
|
|
|
600
671
|
state.seen.add(key);
|
|
672
|
+
const job = buildJob(session, turn, picked, speech, event?.seq);
|
|
673
|
+
state.jobs.set(job.key, { status: "queued", createdAt: job.createdAt });
|
|
674
|
+
state.queue.push(job);
|
|
675
|
+
log.info(
|
|
676
|
+
`queued ${job.key} workspace=${job.workspaceKey} ` +
|
|
677
|
+
`(${picked.text.length} chars, ${speech.length} speakable)`,
|
|
678
|
+
);
|
|
679
|
+
void drain();
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Describe one synthesis job: output paths, text, and workspace.
|
|
684
|
+
* Automatic turn/end narration and on-demand generation share this shape.
|
|
685
|
+
*
|
|
686
|
+
* @param {object} session - Session that owns the turn.
|
|
687
|
+
* @param {number} turn - turn number.
|
|
688
|
+
* @param {{text: string}} picked - assistant answer chosen for narration.
|
|
689
|
+
* @param {string} speech - speech-ready text.
|
|
690
|
+
* @param {number|undefined} eventSeq - originating event sequence, when any.
|
|
691
|
+
* @returns {object} job.
|
|
692
|
+
*/
|
|
693
|
+
function buildJob(session, turn, picked, speech, eventSeq) {
|
|
694
|
+
const sessionId = String(session?.id ?? session?.header?.id ?? "unknown");
|
|
601
695
|
const workspace = workspaceInfo(session?.header?.cwd, cfg.groupByWorkspace);
|
|
602
696
|
const dir = join(cfg.outputDir, ...workspace.dirParts, dayStamp());
|
|
603
697
|
const base = baseName(sessionId, turn);
|
|
604
|
-
|
|
605
|
-
key
|
|
698
|
+
return {
|
|
699
|
+
key: `${sessionId}:${turn}`,
|
|
606
700
|
sessionId,
|
|
607
701
|
turn,
|
|
608
702
|
workspaceKey: workspace.key,
|
|
609
703
|
workspacePath: workspace.path,
|
|
610
|
-
eventSeq
|
|
704
|
+
eventSeq,
|
|
611
705
|
createdAt: new Date().toISOString(),
|
|
612
706
|
text: picked.text,
|
|
613
707
|
speech,
|
|
@@ -618,13 +712,6 @@ export function apply(ctx, rawConfig = {}) {
|
|
|
618
712
|
json: join(dir, `${base}.json`),
|
|
619
713
|
},
|
|
620
714
|
};
|
|
621
|
-
state.jobs.set(key, { status: "queued", createdAt: job.createdAt });
|
|
622
|
-
state.queue.push(job);
|
|
623
|
-
log.info(
|
|
624
|
-
`queued ${key} workspace=${workspace.key} ` +
|
|
625
|
-
`(${picked.text.length} chars, ${speech.length} speakable)`,
|
|
626
|
-
);
|
|
627
|
-
void drain();
|
|
628
715
|
}
|
|
629
716
|
|
|
630
717
|
/** Process queued jobs one at a time. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-tts-chat-answer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Narrate completed assistant answers with Edge TTS, save audio locally, and play it in-page or in a native MPRIS player.",
|
|
5
5
|
"author": "Vladimir Cores",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"type": "module",
|
|
26
26
|
"main": "lib/index.js",
|
|
27
27
|
"bin": {
|
|
28
|
-
"
|
|
28
|
+
"setup": "setup.mjs"
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
31
|
"setup": "node setup.mjs",
|