clavarium 0.2.118-beta.1 → 0.2.119-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 -2
- package/server/pocket.mjs +9 -1
- package/server/speech.mjs +3 -1
- package/web/app.js +42 -0
- package/web/style.css +6 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.119-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.119-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
|
@@ -654,7 +654,9 @@ export class Boxes {
|
|
|
654
654
|
} catch (error) { this.#log(`voice box ${box0.name}: ${seconds} s heard, dictation failed (${error.message})`); await lost('Pardon, la dictée ne répond pas. Tu peux répéter ?'); return; }
|
|
655
655
|
if (!text) { this.#log(`voice box ${box0.name}: ${seconds} s heard, nothing recognised (silence?)`); await lost("Pardon, je n'ai rien compris. Tu peux répéter ?"); return; }
|
|
656
656
|
const box = link.box();
|
|
657
|
-
|
|
657
|
+
/* Only a short order starts a recording ("lance l'enregistrement de la réunion"): a sentence that merely
|
|
658
|
+
mentions recording does not (01-11). */
|
|
659
|
+
if (RECORD_ASKED.test(text) && text.split(/\s+/).length <= 10 && this.#recordDir && this.#parts) {
|
|
658
660
|
this.#log(`voice box ${box.name}: a recording asked`);
|
|
659
661
|
try { link.play(await this.#speak("J'enregistre. Pour arrêter, appuie sur le bouton ou dis le mot d'éveil.")); } catch { /* no voice: the light says it */ }
|
|
660
662
|
link.send({ t: 'record', on: true });
|
|
@@ -699,7 +701,10 @@ export class Boxes {
|
|
|
699
701
|
* POST /api/boxes/<id>/revoke
|
|
700
702
|
* POST /api/boxes/<id>/volume {level 0-100}
|
|
701
703
|
* POST /api/boxes/<id>/wifi-scan -> {networks}
|
|
702
|
-
* POST /api/boxes/<id>/wifi-join {ssid, password}: the password goes to the box, and is kept nowhere here
|
|
704
|
+
* POST /api/boxes/<id>/wifi-join {ssid, password}: the password goes to the box, and is kept nowhere here;
|
|
705
|
+
* the box ADDS it to the networks it knows (8 at most) and goes to the strongest
|
|
706
|
+
* POST /api/boxes/<id>/wifi-known -> {networks, current}: the names it knows (never a password)
|
|
707
|
+
* POST /api/boxes/<id>/wifi-forget {ssid}: not the one it uses now
|
|
703
708
|
* POST /api/boxes/<id>/alert {text?}
|
|
704
709
|
* POST /api/boxes/<id>/reboot
|
|
705
710
|
*/
|
|
@@ -734,6 +739,8 @@ export async function handleBoxes(request, response, boxes, originOk, headers =
|
|
|
734
739
|
case 'revoke': boxes.revoke(id); return send(200, { ok: true });
|
|
735
740
|
case 'volume': return answered(await boxes.setVolume(id, body.level));
|
|
736
741
|
case 'wifi-scan': { const r = await boxes.command(id, { t: 'wifi.scan' }); return send(200, { networks: Array.isArray(r.networks) ? r.networks : [] }); }
|
|
742
|
+
case 'wifi-known': { const r = await boxes.command(id, { t: 'wifi.list' }); return send(200, { networks: Array.isArray(r.networks) ? r.networks.map(String) : [], current: String(r.current ?? '') }); }
|
|
743
|
+
case 'wifi-forget': return answered(await boxes.command(id, { t: 'wifi.forget', ssid: String(body.ssid ?? '').slice(0, 32) }));
|
|
737
744
|
case 'wifi-join': return answered(await boxes.command(id, { t: 'wifi.join', ssid: String(body.ssid ?? ''), password: String(body.password ?? '') }, 90_000));
|
|
738
745
|
case 'alert': return answered(await boxes.command(id, { t: 'alert', text: String(body.text ?? '').slice(0, 300) }, 10 * 60_000));
|
|
739
746
|
case 'reboot': return answered(await boxes.command(id, { t: 'reboot' }));
|
package/server/pocket.mjs
CHANGED
|
@@ -94,8 +94,16 @@ export class Pocket {
|
|
|
94
94
|
return this.#starting;
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/* Never waited for: while it is fetched or starts (minutes, the first time), the next voice speaks and this
|
|
98
|
+
one gets ready behind (01-11: answers held minutes while it downloaded). */
|
|
99
|
+
#warm() {
|
|
100
|
+
if (this.#child && this.#port) return this.#port;
|
|
101
|
+
if (!this.#starting) this.#ready().catch((error) => this.#log(`speech: Pocket TTS could not start (${error.message})`));
|
|
102
|
+
throw new Error('Pocket TTS is getting ready');
|
|
103
|
+
}
|
|
104
|
+
|
|
97
105
|
async #clause(text) {
|
|
98
|
-
const port =
|
|
106
|
+
const port = this.#warm();
|
|
99
107
|
const form = new FormData(); form.append('text', text);
|
|
100
108
|
const r = await this.#fetch(`http://127.0.0.1:${port}/tts`, { method: 'POST', body: form, signal: AbortSignal.timeout(30_000) });
|
|
101
109
|
if (!r.ok) throw new Error(`Pocket TTS answered ${r.status}`);
|
package/server/speech.mjs
CHANGED
|
@@ -105,7 +105,9 @@ export class Speech {
|
|
|
105
105
|
async speak(text) {
|
|
106
106
|
/* Pocket first; failed, it rests five minutes and the next voice answers meanwhile. */
|
|
107
107
|
if (this.#pocket && Date.now() - this.#pocketDown > 5 * 60_000) {
|
|
108
|
-
try { const pcm = await this.#pocket.speak(text); if (pcm.length) return pcm; } catch (error) {
|
|
108
|
+
try { const pcm = await this.#pocket.speak(text); if (pcm.length) return pcm; } catch (error) {
|
|
109
|
+
if (!/getting ready/.test(error.message)) { this.#pocketDown = Date.now(); this.#log(`speech: Pocket TTS failed (${error.message}), another voice meanwhile`); }
|
|
110
|
+
}
|
|
109
111
|
}
|
|
110
112
|
const online = await this.#eleven(text);
|
|
111
113
|
if (online && online.length) return online;
|
package/web/app.js
CHANGED
|
@@ -8874,6 +8874,48 @@
|
|
|
8874
8874
|
const volRow = el('label', 'box-volume'); volRow.append('Volume ', vol, volSaid);
|
|
8875
8875
|
const acts = el('div', 'action-row'); acts.append(whereRow, place, volRow, rename, remove);
|
|
8876
8876
|
card.append(head, acts);
|
|
8877
|
+
/* ITS WI-FI NETWORKS (01-11): the box knows several and goes to the strongest it hears; one is added
|
|
8878
|
+
here before it moves, from the networks it hears itself -- no phone, no button. */
|
|
8879
|
+
if (b.online) {
|
|
8880
|
+
const wifi = el('div', 'box-wifi');
|
|
8881
|
+
const known = el('div', 'box-wifi-known');
|
|
8882
|
+
const add = el('button', '', 'Add a Wi-Fi'); add.type = 'button';
|
|
8883
|
+
const paintKnown = async () => {
|
|
8884
|
+
known.replaceChildren(el('small', 'hint', 'Its Wi-Fi networks…'));
|
|
8885
|
+
const r = await post(`${API}/boxes/${b.id}/wifi-known`, {}).catch(() => null);
|
|
8886
|
+
known.replaceChildren();
|
|
8887
|
+
if (!r) { known.append(el('small', 'hint', 'Its networks cannot be read just now.')); return; }
|
|
8888
|
+
for (const ssid of r.networks) {
|
|
8889
|
+
const chip = el('span', 'box-wifi-net', ssid === r.current ? `${ssid} (now)` : ssid);
|
|
8890
|
+
if (ssid !== r.current) {
|
|
8891
|
+
const x = el('button', 'quiet', '×'); x.type = 'button'; x.setAttribute('aria-label', `Forget ${ssid}`);
|
|
8892
|
+
x.addEventListener('click', async () => { await post(`${API}/boxes/${b.id}/wifi-forget`, { ssid }).catch(() => {}); await paintKnown(); });
|
|
8893
|
+
chip.append(x);
|
|
8894
|
+
}
|
|
8895
|
+
known.append(chip);
|
|
8896
|
+
}
|
|
8897
|
+
};
|
|
8898
|
+
add.addEventListener('click', async () => {
|
|
8899
|
+
add.disabled = true; add.textContent = 'Listening for networks…';
|
|
8900
|
+
const r = await post(`${API}/boxes/${b.id}/wifi-scan`, {}).catch(() => ({ networks: [] }));
|
|
8901
|
+
add.disabled = false; add.textContent = 'Add a Wi-Fi';
|
|
8902
|
+
const pick = el('select'); pick.setAttribute('aria-label', 'Network');
|
|
8903
|
+
for (const n of r.networks ?? []) { const o = el('option', '', `${n.ssid}${n.secure ? '' : ' (open)'}`); o.value = n.ssid; pick.append(o); }
|
|
8904
|
+
const pass = el('input'); pass.type = 'password'; pass.placeholder = 'Password'; pass.autocomplete = 'off'; pass.setAttribute('aria-label', 'Password of the network');
|
|
8905
|
+
const join = el('button', 'primary', 'Add'); join.type = 'button';
|
|
8906
|
+
const said = el('small', 'hint', '');
|
|
8907
|
+
join.addEventListener('click', async () => {
|
|
8908
|
+
join.disabled = true; said.textContent = 'The box tries it (up to 20 s); it comes back on its network after.';
|
|
8909
|
+
try { await post(`${API}/boxes/${b.id}/wifi-join`, { ssid: pick.value, password: pass.value }); said.textContent = `Added: ${pick.value}.`; form.remove(); await paintKnown(); }
|
|
8910
|
+
catch (error) { said.textContent = `Not joined: ${error.message}`; join.disabled = false; }
|
|
8911
|
+
});
|
|
8912
|
+
const form = el('div', 'action-row box-wifi-add'); form.append(pick, pass, join, said);
|
|
8913
|
+
wifi.append(form); focusField(pass);
|
|
8914
|
+
});
|
|
8915
|
+
wifi.append(el('small', 'hint', 'Wi-Fi it knows (it goes to the strongest): '), known, add);
|
|
8916
|
+
card.append(wifi);
|
|
8917
|
+
void paintKnown();
|
|
8918
|
+
}
|
|
8877
8919
|
rows.append(card);
|
|
8878
8920
|
}
|
|
8879
8921
|
}
|
package/web/style.css
CHANGED
|
@@ -2075,3 +2075,9 @@ body.as-dragging #assets-rows .as-row { touch-action: none; }
|
|
|
2075
2075
|
.box-qr { width: 180px; max-width: 100%; background: #fff; border-radius: 8px; padding: 6px; }
|
|
2076
2076
|
.box-qr svg { display: block; width: 100%; height: auto; }
|
|
2077
2077
|
.button-link { display: inline-block; padding: 8px 12px; border-radius: 7px; background: var(--accent, #d4a64a); color: #111; font-weight: 600; text-decoration: none; }
|
|
2078
|
+
|
|
2079
|
+
/* A voice box's Wi-Fi networks: names as small chips, the one it uses marked. */
|
|
2080
|
+
.box-wifi { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
|
|
2081
|
+
.box-wifi-known { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
2082
|
+
.box-wifi-net { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border: 1px solid var(--line, #ccc); border-radius: 999px; font-size: 0.85em; }
|
|
2083
|
+
.box-wifi-add { width: 100%; }
|