clavarium 0.2.134-beta.1 → 0.2.135-beta.1
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 +2 -2
- package/package.json +1 -1
- package/server/boxes.mjs +9 -4
- package/server/main.mjs +2 -2
- package/server/voice.mjs +20 -2
- package/web/app.js +1 -1
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.135-beta.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.135-beta.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/boxes.mjs
CHANGED
|
@@ -142,6 +142,8 @@ export function endOf(ep, reason = '') {
|
|
|
142
142
|
const n = (v) => Number.isFinite(v);
|
|
143
143
|
const sec = (v) => `${v.toFixed(1).replace('.', ',')} s`;
|
|
144
144
|
const parts = [`fin ${String(reason).slice(0, 12)}${n(ep.s) ? ` ${sec(ep.s)}` : ''}`.replace(/\s+/g, ' ').trim()];
|
|
145
|
+
/* The four slots of the chip, when the box says them (0.1.43): which one carries the voice. Short, the line is short. */
|
|
146
|
+
if (Array.isArray(ep.slots) && ep.slots.length === 4) { parts.push(`voies ${ep.slots.map((v) => Math.round(Number(v) || 0)).join('/')}`); if (n(ep.voice) && ep.voice > 0) parts.push(`voix ${Math.round(ep.voice)}`); return parts.join(' · '); }
|
|
145
147
|
parts.push(n(ep.heard_at) && ep.heard_at >= 0 ? `voix dès ${sec(ep.heard_at)}` : 'sans voix');
|
|
146
148
|
if (n(ep.bar)) parts.push(`seuil ${Math.round(ep.bar)}`);
|
|
147
149
|
if (n(ep.voice) && ep.voice > 0) parts.push(`voix ${Math.round(ep.voice)}`);
|
|
@@ -458,10 +460,13 @@ export class Boxes {
|
|
|
458
460
|
}
|
|
459
461
|
|
|
460
462
|
/* Where it is (a home, a family house): grouped by it, named with it. */
|
|
461
|
-
zone(id, zone) {
|
|
463
|
+
zone(id, zone, lang) {
|
|
462
464
|
const z = zoneOf(zone);
|
|
463
465
|
if (!z) throw new Refusal(400, 'Not a time zone.');
|
|
464
|
-
|
|
466
|
+
/* Its language too, from the page that manages it (02-11: unsaid, the dictation guessed Danish on a
|
|
467
|
+
short French sentence). A tag such as fr or fr-FR, nothing else. */
|
|
468
|
+
const l = /^[a-z]{2,3}(-[A-Za-z]{2,4})?$/.test(String(lang ?? '')) ? String(lang) : null;
|
|
469
|
+
this.#change(id, { zone: z, ...(l ? { lang: l } : {}) });
|
|
465
470
|
this.#links.get(id)?.send({ t: 'clock', offset: offsetOf(z, this.#now()) });
|
|
466
471
|
}
|
|
467
472
|
place(id, place) { this.#change(id, { place: String(place ?? '').trim().slice(0, NAME_MAX) }); }
|
|
@@ -720,7 +725,7 @@ export class Boxes {
|
|
|
720
725
|
anything is said to the person -- who should not have to repeat (31-10). */
|
|
721
726
|
const hear = async (wav) => {
|
|
722
727
|
for (let attempt = 0; ; attempt++) {
|
|
723
|
-
try { return await this.#hear(wav); } catch (error) {
|
|
728
|
+
try { return await this.#hear(wav, box0.lang); } catch (error) {
|
|
724
729
|
if (attempt >= 2 || error?.status === 413 || error?.status === 400) throw error;
|
|
725
730
|
this.#log(`voice box ${box0.name}: dictation failed (${error.message}), tried again`);
|
|
726
731
|
await new Promise((r) => setTimeout(r, 800 * (attempt + 1)));
|
|
@@ -822,7 +827,7 @@ export async function handleBoxes(request, response, boxes, originOk, headers =
|
|
|
822
827
|
case 'rename': boxes.rename(id, body.name); return send(200, { ok: true });
|
|
823
828
|
case 'move': boxes.move(id, String(body.conversation ?? '')); return send(200, { ok: true });
|
|
824
829
|
case 'place': boxes.place(id, body.place); return send(200, { ok: true });
|
|
825
|
-
case 'zone': boxes.zone(id, body.zone); return send(200, { ok: true });
|
|
830
|
+
case 'zone': boxes.zone(id, body.zone, body.lang); return send(200, { ok: true });
|
|
826
831
|
case 'revoke': boxes.revoke(id); return send(200, { ok: true });
|
|
827
832
|
case 'volume': return answered(await boxes.setVolume(id, body.level));
|
|
828
833
|
case 'wifi-scan': { const r = await boxes.command(id, { t: 'wifi.scan' }); return send(200, { networks: Array.isArray(r.networks) ? r.networks : [] }); }
|
package/server/main.mjs
CHANGED
|
@@ -29,7 +29,7 @@ import { Vms, runner } from './vm.mjs';
|
|
|
29
29
|
import { Resources } from './resources.mjs';
|
|
30
30
|
import { makeGate, makeOriginCheck, readOperators } from './gate.mjs';
|
|
31
31
|
import { Shortcuts } from './shortcuts.mjs';
|
|
32
|
-
import { Dictation } from './voice.mjs';
|
|
32
|
+
import { hearBox, Dictation } from './voice.mjs';
|
|
33
33
|
import QRCode from 'qrcode';
|
|
34
34
|
import { Devices } from './devices.mjs';
|
|
35
35
|
import { handleDoor, deviceTerminal } from './door.mjs';
|
|
@@ -616,7 +616,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
616
616
|
/* A long recording (a meeting): transcribed in parts, kept beside the conversation for its assistant. */
|
|
617
617
|
react: (said) => voice.reaction(said),
|
|
618
618
|
recordDir: `${dataDir}/recordings`, parts: (wav) => voice.transcribeParts(wav), keep: (name, file, text) => talk.keepText(name, file, text),
|
|
619
|
-
hear: (wav) => voice
|
|
619
|
+
hear: (wav, lang) => hearBox(voice, wav, lang), /* any language heard; one neither the box's (its page's) nor English heard again in the box's (voice.mjs) */
|
|
620
620
|
/* Said as the person's own message, the room named (one speaker for now). */
|
|
621
621
|
say: (name, text, by) => talk.say(name, text, undefined, undefined, 'voice', { by }),
|
|
622
622
|
/* Each conversation's thread knows its boxes: their names, and the ids its agent answers. */
|
package/server/voice.mjs
CHANGED
|
@@ -134,7 +134,7 @@ export function firstVoice(body) {
|
|
|
134
134
|
return parts.filter((p) => p.speaker === who).map((p) => p.text.trim()).join(' ');
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
export async function transcribe(config, audio, fetcher = fetch, { oneVoice = false } = {}) {
|
|
137
|
+
export async function transcribe(config, audio, fetcher = fetch, { oneVoice = false, withLanguage = false } = {}) {
|
|
138
138
|
if (!config) throw new Refusal(503, 'No speech-to-text engine is configured.');
|
|
139
139
|
if (audio.length === 0) throw new Refusal(400, 'The recording is empty.');
|
|
140
140
|
if (audio.length > AUDIO_MAX) throw new Refusal(413, 'The recording is too long.');
|
|
@@ -172,7 +172,25 @@ export async function transcribe(config, audio, fetcher = fetch, { oneVoice = fa
|
|
|
172
172
|
if (!response.ok) throw new Refusal(502, `The speech-to-text engine answered ${response.status}.`);
|
|
173
173
|
const body = await response.json().catch(() => undefined);
|
|
174
174
|
if (typeof body?.text !== 'string') throw new Refusal(502, 'The speech-to-text engine gave no text.');
|
|
175
|
-
|
|
175
|
+
const text = cleanDictation((oneVoice && firstVoice(body)) || body.text, wavSeconds(audio));
|
|
176
|
+
/* The language the engine heard, when asked for (a voice box checks it, 02-11). */
|
|
177
|
+
return withLanguage ? { text, language: codeOfLanguage(body.language) } : text;
|
|
178
|
+
}
|
|
179
|
+
/* "french" or "fr" -> "fr": the engines name it either way. */
|
|
180
|
+
const LANGUAGE_NAMES = { french: 'fr', english: 'en', german: 'de', spanish: 'es', italian: 'it', portuguese: 'pt', dutch: 'nl', danish: 'da', norwegian: 'no', swedish: 'sv', chinese: 'zh', japanese: 'ja', russian: 'ru', polish: 'pl', arabic: 'ar' };
|
|
181
|
+
export function codeOfLanguage(given) {
|
|
182
|
+
const g = String(given ?? '').trim().toLowerCase();
|
|
183
|
+
if (!g) return null;
|
|
184
|
+
return LANGUAGE_NAMES[g] ?? (/^[a-z]{2,3}(-|$)/.test(g) ? g.slice(0, 2) : null);
|
|
185
|
+
}
|
|
186
|
+
/* A VOICE BOX'S SENTENCE (02-11): heard in any language -- but a short sentence is sometimes taken for
|
|
187
|
+
another (Danish for French): when the engine heard neither the box's language nor English, it is heard
|
|
188
|
+
again in the box's language. Universal, and not fooled. */
|
|
189
|
+
export async function hearBox(dictation, wav, lang) {
|
|
190
|
+
const first = await dictation.transcribe(wav, undefined, { oneVoice: true, withLanguage: true });
|
|
191
|
+
const want = codeOfLanguage(lang); const got = codeOfLanguage(first?.language);
|
|
192
|
+
if (!want || !got || got === want || got === 'en') return first?.text ?? first;
|
|
193
|
+
return dictation.transcribe(wav, lang, { oneVoice: true });
|
|
176
194
|
}
|
|
177
195
|
|
|
178
196
|
/* A LONG RECORDING, in parts of a few minutes (a voice box records a meeting): each part's text, with who
|
package/web/app.js
CHANGED
|
@@ -9126,7 +9126,7 @@
|
|
|
9126
9126
|
const place = el('input'); place.value = b.place ?? ''; place.maxLength = 40; place.placeholder = 'Place (a home)'; place.setAttribute('list', 'box-places'); place.setAttribute('aria-label', `Place of ${b.name}`);
|
|
9127
9127
|
place.addEventListener('change', async () => { await post(`${API}/boxes/${b.id}/place`, { place: place.value.trim() }).catch(() => {}); await paintBoxes(); });
|
|
9128
9128
|
/* A box paired before it knew its time zone takes this page's: its lights follow the hours here. */
|
|
9129
|
-
if (!b.zone) void post(`${API}/boxes/${b.id}/zone`, { zone: Intl.DateTimeFormat().resolvedOptions().timeZone }).catch(() => {});
|
|
9129
|
+
if (!b.zone || !b.lang) void post(`${API}/boxes/${b.id}/zone`, { zone: b.zone || Intl.DateTimeFormat().resolvedOptions().timeZone, lang: navigator.language }).catch(() => {});
|
|
9130
9130
|
/* Louder, softer: kept here, given to the box now or when it comes back. */
|
|
9131
9131
|
const vol = el('input'); vol.type = 'range'; vol.min = '0'; vol.max = '100'; vol.step = '5'; vol.value = String(b.volume ?? 80); vol.setAttribute('aria-label', `Volume of ${b.name}`);
|
|
9132
9132
|
const volSaid = el('small', 'hint', `${vol.value} %`);
|