clavarium 0.2.24-next.6 → 0.2.24
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/npm-shrinkwrap.json +6 -6
- package/package.json +2 -2
- package/server/api.mjs +5 -4
- package/server/door.mjs +1 -1
- package/server/voice.mjs +25 -5
- package/web/app.js +12 -12
- package/web/index.html +1 -1
- package/web/style.css +11 -2
- package/web/voice.js +8 -1
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.24
|
|
3
|
+
"version": "0.2.24",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.24
|
|
9
|
+
"version": "0.2.24",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
|
13
13
|
"@xterm/xterm": "^6.0.0",
|
|
14
|
-
"clavarium-binder": "0.1.1
|
|
14
|
+
"clavarium-binder": "0.1.1",
|
|
15
15
|
"clavarium-docket": "0.1.1",
|
|
16
16
|
"clavarium-parley": "0.15.0",
|
|
17
17
|
"mermaid": "11.17.2",
|
|
@@ -688,9 +688,9 @@
|
|
|
688
688
|
}
|
|
689
689
|
},
|
|
690
690
|
"node_modules/clavarium-binder": {
|
|
691
|
-
"version": "0.1.1
|
|
692
|
-
"resolved": "https://registry.npmjs.org/clavarium-binder/-/clavarium-binder-0.1.1
|
|
693
|
-
"integrity": "sha512-
|
|
691
|
+
"version": "0.1.1",
|
|
692
|
+
"resolved": "https://registry.npmjs.org/clavarium-binder/-/clavarium-binder-0.1.1.tgz",
|
|
693
|
+
"integrity": "sha512-9osufAKNzKUcE6CEQBgJn/frYp6qdjwRYRCy3Fn/zIyQVOb/F/mr4r/WmymMy+knUCeTzwGZjWHD5WIpPMQz7A==",
|
|
694
694
|
"license": "MIT",
|
|
695
695
|
"bin": {
|
|
696
696
|
"binder": "bin/binder.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.24
|
|
3
|
+
"version": "0.2.24",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@xterm/addon-fit": "^0.11.0",
|
|
46
46
|
"@xterm/xterm": "^6.0.0",
|
|
47
|
-
"clavarium-binder": "0.1.1
|
|
47
|
+
"clavarium-binder": "0.1.1",
|
|
48
48
|
"clavarium-docket": "0.1.1",
|
|
49
49
|
"clavarium-parley": "0.15.0",
|
|
50
50
|
"mermaid": "11.17.2",
|
package/server/api.mjs
CHANGED
|
@@ -97,11 +97,11 @@
|
|
|
97
97
|
* POST /api/shortcuts {label, text, enter}
|
|
98
98
|
* POST /api/shortcuts/<id>/remove
|
|
99
99
|
* GET /api/voice is dictation available?
|
|
100
|
-
* POST /api/voice
|
|
100
|
+
* POST /api/voice?lang= the body IS a WAV recording -> {text}; lang: the device's language
|
|
101
101
|
* GET /api/dictation the engine chosen in Settings (never a key: a secret's name)
|
|
102
102
|
* POST /api/dictation {provider, url, model, secret, language}: chosen, at once
|
|
103
103
|
* POST /api/dictation/off the environment's engine, if any, again
|
|
104
|
-
* POST /api/dictation/try?provider=&url=&model=&secret=&language= a WAV -> {text}, nothing saved
|
|
104
|
+
* POST /api/dictation/try?provider=&url=&model=&secret=&language=&lang= a WAV -> {text}, nothing saved
|
|
105
105
|
* GET /api/files?c=<conversation>&r=<resource>&p=<path> a listing
|
|
106
106
|
* GET /api/flows who gets what: devices, conversations, assets, the rights between them, the flows
|
|
107
107
|
* POST /api/flows/name {around, name}: a flow named by the owner ('' gives it back its own)
|
|
@@ -187,8 +187,9 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
187
187
|
for await (const chunk of request) { size += chunk.length; if (size > AUDIO_MAX) throw new Refusal(413, 'The recording is too long.'); parts.push(chunk); }
|
|
188
188
|
const audio = Buffer.concat(parts);
|
|
189
189
|
/* "Try it": the choice in the form, in the address's parameters (no key in it: a secret's name). */
|
|
190
|
-
|
|
191
|
-
return send(200, { text:
|
|
190
|
+
/* `lang`: the language of the device that dictates (voice.mjs, languageOf). */
|
|
191
|
+
if (pathname === '/api/dictation/try') return send(200, { text: await voice.try(Object.fromEntries(query), audio, query.get('lang') ?? undefined) }), true;
|
|
192
|
+
return send(200, { text: voice ? await voice.transcribe(audio, query.get('lang') ?? undefined) : await transcribe(undefined, audio) }), true;
|
|
192
193
|
}
|
|
193
194
|
if (request.method === 'GET' && pathname === '/api/files') return send(200, await list(attached(), query.get('p') ?? '')), true;
|
|
194
195
|
if (request.method === 'GET' && pathname === '/api/files/machine') {
|
package/server/door.mjs
CHANGED
|
@@ -167,7 +167,7 @@ export async function handleDoor(request, response, { devices, conversations, re
|
|
|
167
167
|
if (request.headers['content-type'] !== 'audio/wav') return send(400, { error: 'A recording is a WAV file.' });
|
|
168
168
|
const parts = []; let size = 0;
|
|
169
169
|
for await (const chunk of request) { size += chunk.length; if (size > AUDIO_MAX) throw new Refusal(413, 'The recording is too long.'); parts.push(chunk); }
|
|
170
|
-
return send(200, { text: voice ? await voice.transcribe(Buffer.concat(parts)) : await transcribe(undefined, Buffer.concat(parts)) });
|
|
170
|
+
return send(200, { text: voice ? await voice.transcribe(Buffer.concat(parts), url.searchParams.get('lang') ?? undefined) : await transcribe(undefined, Buffer.concat(parts)) });
|
|
171
171
|
}
|
|
172
172
|
/* Its conversation's chat, whatever conversation the address names: the device's own. */
|
|
173
173
|
/* Only for a pairing given its chat: to read it, or to write there too. */
|
package/server/voice.mjs
CHANGED
|
@@ -174,6 +174,25 @@ export const PROVIDERS = {
|
|
|
174
174
|
other: { label: 'Other (compatible)', url: '', model: '' },
|
|
175
175
|
};
|
|
176
176
|
const LANGUAGE = /^[a-z]{2,3}(-[A-Za-z]{2,4})?$/;
|
|
177
|
+
export const AUTOMATIC = 'auto';
|
|
178
|
+
|
|
179
|
+
/* WHICH LANGUAGE IS ASKED FOR. Left to the engine, the language is guessed
|
|
180
|
+
again on every phrase -- a few seconds of audio, often hesitant -- and a
|
|
181
|
+
French phrase came back as Icelandic. So a language is always given: the
|
|
182
|
+
one chosen (Settings, else CLAVARIUM_TRANSCRIPTION_LANGUAGE), else the
|
|
183
|
+
language of the device that dictates (its browser's first, sent with each
|
|
184
|
+
phrase). Guessed only when "auto" is chosen, or nothing is known.
|
|
185
|
+
The device's tag is cut to its language ("fr-CA" -> "fr"): what the engines take. */
|
|
186
|
+
export function deviceLanguage(tag) {
|
|
187
|
+
const primary = String(tag ?? '').trim().toLowerCase().split(/[-_]/)[0];
|
|
188
|
+
return /^[a-z]{2,3}$/.test(primary) ? primary : undefined;
|
|
189
|
+
}
|
|
190
|
+
export function languageOf(chosen, device) {
|
|
191
|
+
const c = String(chosen ?? '').trim();
|
|
192
|
+
if (c === AUTOMATIC) return undefined;
|
|
193
|
+
if (c !== '' && LANGUAGE.test(c)) return c;
|
|
194
|
+
return deviceLanguage(device);
|
|
195
|
+
}
|
|
177
196
|
const MODEL = /^[A-Za-z0-9._:/-]{1,100}$/;
|
|
178
197
|
|
|
179
198
|
/* An address of this server's own network, written as such. */
|
|
@@ -203,7 +222,7 @@ export function dictationProblem(c) {
|
|
|
203
222
|
if (url.protocol !== 'https:' && !(url.protocol === 'http:' && own)) return 'The address must start with https:// (plain http only for an engine on this server\'s own network).';
|
|
204
223
|
if (!MODEL.test(String(c.model ?? ''))) return 'Give the name of a model.';
|
|
205
224
|
if (c.secret !== undefined && c.secret !== '' && !isSecretName(c.secret)) return 'The key is the name of a secret.';
|
|
206
|
-
if (c.language !== undefined && c.language !== '' && !LANGUAGE.test(String(c.language))) return 'The language is a code such as en or fr, or automatic.';
|
|
225
|
+
if (c.language !== undefined && c.language !== '' && c.language !== AUTOMATIC && !LANGUAGE.test(String(c.language))) return 'The language is a code such as en or fr, or automatic.';
|
|
207
226
|
return undefined;
|
|
208
227
|
}
|
|
209
228
|
|
|
@@ -265,18 +284,19 @@ export class Dictation {
|
|
|
265
284
|
}
|
|
266
285
|
/* An expired key is never sent: said in one line instead (still offered, so the line is seen). */
|
|
267
286
|
#fresh(c) { if (c?.secret && this.#expired(c.secret)) throw new Refusal(409, KEY_EXPIRED); }
|
|
268
|
-
|
|
287
|
+
/* `device`: the language of the device that dictates (a tag such as fr-FR), if it said. */
|
|
288
|
+
async transcribe(audio, device) {
|
|
269
289
|
this.#fresh(this.#saved());
|
|
270
290
|
const config = this.current();
|
|
271
291
|
if (config) await this.#guard(config);
|
|
272
|
-
return transcribe(config, audio, this.#fetcher);
|
|
292
|
+
return transcribe(config && { ...config, language: languageOf(config.language, device) }, audio, this.#fetcher);
|
|
273
293
|
}
|
|
274
294
|
/* "Try it": what is in the form, not saved, on one short recording. */
|
|
275
|
-
async try(body, audio) {
|
|
295
|
+
async try(body, audio, device) {
|
|
276
296
|
const checked = this.#checked(body);
|
|
277
297
|
this.#fresh(checked);
|
|
278
298
|
const config = this.#configOf(checked);
|
|
279
299
|
await this.#guard(config);
|
|
280
|
-
return transcribe(config, audio, this.#fetcher);
|
|
300
|
+
return transcribe({ ...config, language: languageOf(config.language, device) }, audio, this.#fetcher);
|
|
281
301
|
}
|
|
282
302
|
}
|
package/web/app.js
CHANGED
|
@@ -3034,6 +3034,15 @@
|
|
|
3034
3034
|
const ASSET_KINDS = [['git', 'Git repositories', 'git-branch'], ['folder', 'Folders', 'folder'], ['mailbox', 'Mailboxes', 'mail'], ['secret', 'Secrets', 'key-round'], ['list', LISTS_WORD.many, '']];
|
|
3035
3035
|
const getJson = (path, fallback) => fetch(`${API}${path}`).then((r) => (r.ok ? r.json() : fallback)).catch(() => fallback);
|
|
3036
3036
|
const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text !== undefined) e.textContent = text; return e; };
|
|
3037
|
+
/* A commit: its line, and the rest of its message under it, opened by a click. */
|
|
3038
|
+
function commitRow(c) {
|
|
3039
|
+
const rest = (c.message ?? '').split('\n').slice(1).join('\n').trim();
|
|
3040
|
+
const head = [el('code', '', c.id.slice(0, 8)), el('b', '', c.subject), el('small', '', `${c.author}, ${new Date(c.date).toLocaleString()}`)];
|
|
3041
|
+
if (!rest) { const line = el('div', 'commit'); line.append(...head); return line; }
|
|
3042
|
+
const line = el('details', 'commit'); const summary = el('summary'); summary.append(...head);
|
|
3043
|
+
line.append(summary, el('pre', '', rest));
|
|
3044
|
+
return line;
|
|
3045
|
+
}
|
|
3037
3046
|
const kindIcon = (kind) => { const name = kind === 'send' ? 'arrow-up' : ASSET_KINDS.find((k) => k[0] === kind)?.[2]; const holder = el('span', 'as-ic'); holder.dataset.kind = kind; const svg = kind === 'list' ? listIcon() : name ? window.clavariumIcons?.icon(name) : null; if (svg) holder.append(svg); return holder; };
|
|
3038
3047
|
/* A list (Binder's): the set has no such sign, so it is drawn here, in its style. */
|
|
3039
3048
|
function listIcon() {
|
|
@@ -3424,7 +3433,7 @@
|
|
|
3424
3433
|
} else if (tab === 'commits') {
|
|
3425
3434
|
for (const r of p) {
|
|
3426
3435
|
body.append(el('h4', '', `${r.name}: ${r.out.branch} → ${r.out.target}`));
|
|
3427
|
-
for (const c of r.out.commits)
|
|
3436
|
+
for (const c of r.out.commits) body.append(commitRow(c));
|
|
3428
3437
|
if ((r.out.count ?? 0) > r.out.commits.length) body.append(el('p', 'hint', `Only the last ${r.out.commits.length} of ${r.out.count} are listed.`));
|
|
3429
3438
|
}
|
|
3430
3439
|
} else {
|
|
@@ -5330,7 +5339,7 @@
|
|
|
5330
5339
|
item(`${counted}; ${g.newBytes === null || g.newBytes === undefined ? 'the size of the new data is unknown' : `${sizeText(g.newBytes)} of new data`}.`);
|
|
5331
5340
|
/* What the review could not show: each said, and Send asks to confirm. */
|
|
5332
5341
|
for (const line of g.incomplete ?? []) item(line);
|
|
5333
|
-
if (g.largest?.length) item(`Largest new files: ${g.largest.slice(0, 5).map((b) => `${b.path || '(no path)'} (${sizeText(b.size)})`).join(', ')}.`);
|
|
5342
|
+
if (g.largest?.length) item(`Largest new files: ${g.largest.filter((b, i, all) => !b.path || all.findIndex((x) => x.path === b.path) === i).slice(0, 5).map((b) => `${b.path || '(no path)'} (${sizeText(b.size)})`).join(', ')}.`);
|
|
5334
5343
|
if (g.unchanged?.length) item(`Changed and changed back, so not in the changes below: ${g.unchanged.join(', ')}${g.unchangedAll > g.unchanged.length ? `, and ${g.unchangedAll - g.unchanged.length} more` : ''}.`);
|
|
5335
5344
|
if (g.merges) item(`${g.merges} merge commit${g.merges === 1 ? '' : 's'}: what they bring from their other parents is in the count, not listed.`);
|
|
5336
5345
|
if (out.cut) item('The changes are too long to be shown whole here.');
|
|
@@ -5473,16 +5482,7 @@
|
|
|
5473
5482
|
...(out.guards?.newBytes !== null && out.guards?.newBytes !== undefined ? [bit(`${sizeText(out.guards.newBytes)} of new data`, 'hint')] : []));
|
|
5474
5483
|
$('gitview-n-files').textContent = String(files.length);
|
|
5475
5484
|
$('gitview-n-commits').textContent = String(out.commits.length);
|
|
5476
|
-
for (const c of out.commits)
|
|
5477
|
-
const line = document.createElement('div'); line.className = 'commit';
|
|
5478
|
-
const id = document.createElement('code'); id.textContent = c.id.slice(0, 8);
|
|
5479
|
-
const what = document.createElement('b'); what.textContent = c.subject;
|
|
5480
|
-
const who = document.createElement('small'); who.textContent = `${c.author}, ${new Date(c.date).toLocaleString()}`;
|
|
5481
|
-
line.append(id, what, who);
|
|
5482
|
-
/* The whole message: what a subject line leaves out is part of what is sent. */
|
|
5483
|
-
if (c.message && c.message !== c.subject) { const body = document.createElement('pre'); body.textContent = c.message.split('\n').slice(1).join('\n').trim(); if (body.textContent) line.append(body); }
|
|
5484
|
-
$('gitview-commits').append(line);
|
|
5485
|
-
}
|
|
5485
|
+
for (const c of out.commits) $('gitview-commits').append(commitRow(c));
|
|
5486
5486
|
$('gitview-stat').textContent = out.stat;
|
|
5487
5487
|
gitFile = 0;
|
|
5488
5488
|
drawDiff(out.diff);
|
package/web/index.html
CHANGED
|
@@ -624,7 +624,7 @@
|
|
|
624
624
|
<div class="set-row"><div class="set-what"><label for="dictation-url">Address</label><small>Its transcription endpoint</small></div><div class="set-control"><input id="dictation-url" type="url" spellcheck="false" placeholder="https://.../v1/audio/transcriptions"></div></div>
|
|
625
625
|
<div class="set-row"><div class="set-what"><label for="dictation-model">Model</label></div><div class="set-control"><input id="dictation-model" spellcheck="false" maxlength="100"></div></div>
|
|
626
626
|
<div class="set-row"><div class="set-what"><label for="dictation-secret">Key</label><small id="dictation-key-hint">One of your secrets. Never shown</small></div><div class="set-control"><select id="dictation-secret"><option value="">No key</option></select></div></div>
|
|
627
|
-
<div class="set-row"><div class="set-what"><label for="dictation-language">Language</label></div><div class="set-control"><select id="dictation-language"><option value="">Automatic</option><option value="en">English (en)</option><option value="fr">French (fr)</option><option value="de">German (de)</option><option value="es">Spanish (es)</option><option value="it">Italian (it)</option><option value="nl">Dutch (nl)</option><option value="pt">Portuguese (pt)</option><option value="other">Another code...</option></select><input id="dictation-language-code" maxlength="8" spellcheck="false" placeholder="code, such as pl" aria-label="Language code" hidden></div></div>
|
|
627
|
+
<div class="set-row"><div class="set-what"><label for="dictation-language">Language</label></div><div class="set-control"><select id="dictation-language"><option value="">Each device's</option><option value="auto">Automatic</option><option value="en">English (en)</option><option value="fr">French (fr)</option><option value="de">German (de)</option><option value="es">Spanish (es)</option><option value="it">Italian (it)</option><option value="nl">Dutch (nl)</option><option value="pt">Portuguese (pt)</option><option value="other">Another code...</option></select><input id="dictation-language-code" maxlength="8" spellcheck="false" placeholder="code, such as pl" aria-label="Language code" hidden></div></div>
|
|
628
628
|
<p class="hint" id="dictation-other-hint" hidden>Any engine with the same interface (<code>/v1/audio/transcriptions</code>); it alone may be on this server's own network.</p>
|
|
629
629
|
<div class="action-row"><span class="hint" id="dictation-saved" role="status"></span><button type="button" id="dictation-off">Turn off</button><button type="button" id="dictation-try">Try it</button><button type="submit" class="primary" id="dictation-save">Save</button></div>
|
|
630
630
|
<p class="hint" id="dictation-heard" role="status" hidden></p>
|
package/web/style.css
CHANGED
|
@@ -1224,6 +1224,9 @@ select.pill { appearance: auto; }
|
|
|
1224
1224
|
:root:not([data-theme="light"]) .rv-diff .d2h-del del, :root:not([data-theme="light"]) .rv-diff .d2h-del .d2h-change { background: #8a2d33; }
|
|
1225
1225
|
:root:not([data-theme="light"]) .rv-diff .d2h-info { background: var(--bar); color: var(--ink2); border-color: var(--line); }
|
|
1226
1226
|
:root:not([data-theme="light"]) .rv-diff .d2h-emptyplaceholder, :root:not([data-theme="light"]) .rv-diff .d2h-code-side-emptyplaceholder { background: var(--bar); border-color: var(--line); }
|
|
1227
|
+
/* Line numbers in the flow of their row: diff2html places them absolutely, and they slide off their lines when the page scrolls. */
|
|
1228
|
+
.rv-diff .d2h-code-linenumber, .rv-diff .d2h-code-side-linenumber, .ts-diffs .d2h-code-linenumber, .ts-diffs .d2h-code-side-linenumber { position: static; }
|
|
1229
|
+
.rv-diff .d2h-code-line, .rv-diff .d2h-code-side-line, .ts-diffs .d2h-code-line, .ts-diffs .d2h-code-side-line { padding: 0 .6em; width: auto; }
|
|
1227
1230
|
/* Syntax colours (highlight.js classes), both themes. */
|
|
1228
1231
|
.rv-diff .hljs-keyword, .rv-diff .hljs-selector-tag, .rv-diff .hljs-built_in { color: #d73a49; }
|
|
1229
1232
|
.rv-diff .hljs-string, .rv-diff .hljs-attr, .rv-diff .hljs-regexp { color: #22863a; }
|
|
@@ -1242,7 +1245,6 @@ select.pill { appearance: auto; }
|
|
|
1242
1245
|
.rv-acts #gitview-push { flex: 1 1 100%; order: -1; }
|
|
1243
1246
|
.rv-body { grid-template-columns: minmax(0, 1fr); }
|
|
1244
1247
|
.rv-tree { position: static; max-height: none; }
|
|
1245
|
-
.rv-diff .d2h-code-linenumber { position: static; }
|
|
1246
1248
|
}
|
|
1247
1249
|
@media (max-width: 700px) {
|
|
1248
1250
|
html:not([data-door="device"]) #room > header { min-height: 44px; padding-block: 3px; }
|
|
@@ -1434,7 +1436,6 @@ button.inline.more-recent { text-decoration: none; }
|
|
|
1434
1436
|
.ts-diff:first-child h4 { margin-top: 0; }
|
|
1435
1437
|
.ts-tree { position: static; max-height: none; margin-bottom: 12px; }
|
|
1436
1438
|
.ts-diffs { min-width: 0; }
|
|
1437
|
-
.ts-diffs .d2h-code-linenumber { position: static; }
|
|
1438
1439
|
.ts-note { grid-column: 2 / -1; margin: 0; font-size: .875rem; }
|
|
1439
1440
|
.ts-note.bad { color: var(--danger); }
|
|
1440
1441
|
.ts-output { white-space: pre-wrap; max-height: 40vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: .8125rem; }
|
|
@@ -1714,3 +1715,11 @@ body .binder-holder .binder { --binder-bg: var(--bg); --binder-text: var(--ink);
|
|
|
1714
1715
|
@media (pointer: coarse) { .binder-holder .binder-tick { min-height: 0; width: 1.75rem; height: 1.75rem; } }
|
|
1715
1716
|
/* On the tab, what waits for the owner's tick: the colour of what asks. */
|
|
1716
1717
|
.views #lists-count { background: var(--brass); color: var(--on-brass, #1b1405); font-weight: 700; }
|
|
1718
|
+
/* A commit with more to its message: a click on its line opens the rest. */
|
|
1719
|
+
details.commit { display: block; }
|
|
1720
|
+
details.commit > summary { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; cursor: pointer; list-style: none; }
|
|
1721
|
+
details.commit > summary::-webkit-details-marker { display: none; }
|
|
1722
|
+
details.commit > summary::before { content: '▸'; color: var(--ink2); width: 1em; flex: none; }
|
|
1723
|
+
details.commit[open] > summary::before { content: '▾'; }
|
|
1724
|
+
div.commit::before { content: ''; width: 1em; flex: none; }
|
|
1725
|
+
details.commit > pre { margin: 6px 0 0 1.6em; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink2); font-size: .85em; }
|
package/web/voice.js
CHANGED
|
@@ -7,6 +7,13 @@ import { RATE, BLOCK, BLOCK_MS, Detector, Segmenter, loudness, toWav } from './v
|
|
|
7
7
|
known once it has signed in (the page writes it on the document). */
|
|
8
8
|
const api = () => (document.documentElement.dataset.door === 'device' ? `/c/api/${document.documentElement.dataset.pairing ?? ''}` : '/api');
|
|
9
9
|
|
|
10
|
+
/* The language this device speaks, sent with each phrase: the server asks the
|
|
11
|
+
engine for it unless another is chosen in Settings (server/voice.mjs). */
|
|
12
|
+
const withLanguage = (to) => {
|
|
13
|
+
const lang = navigator.languages?.[0] || navigator.language || '';
|
|
14
|
+
return lang ? `${to}${to.includes('?') ? '&' : '?'}lang=${encodeURIComponent(lang)}` : to;
|
|
15
|
+
};
|
|
16
|
+
|
|
10
17
|
/* Opens the microphone; resolves with a function that closes it.
|
|
11
18
|
`on.phrase(text)`, `on.state(word)`: calibrating, listening, hearing,
|
|
12
19
|
transcribing; `on.error(message)`. `to`: where phrases go, if not the
|
|
@@ -25,7 +32,7 @@ async function listen(on, { to } = {}) {
|
|
|
25
32
|
onPhrase: async (blocks) => {
|
|
26
33
|
pending++; tell();
|
|
27
34
|
try {
|
|
28
|
-
const r = await fetch(to ?? `${api()}/voice
|
|
35
|
+
const r = await fetch(withLanguage(to ?? `${api()}/voice`), { method: 'POST', headers: { 'content-type': 'audio/wav' }, body: toWav(blocks) });
|
|
29
36
|
const j = await r.json().catch(() => ({}));
|
|
30
37
|
if (!r.ok) throw new Error(j.error || 'The phrase could not be transcribed.');
|
|
31
38
|
if (!closed && j.text) on.phrase(j.text);
|