clavarium 0.2.222-next.1 → 0.2.224-next.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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.222-next.1",
3
+ "version": "0.2.224-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.222-next.1",
9
+ "version": "0.2.224-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.222-next.1",
3
+ "version": "0.2.224-next.1",
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.",
package/server/boxes.mjs CHANGED
@@ -137,18 +137,16 @@ export function sentencesOf(text) {
137
137
  export const WAITING_WORDS = false;
138
138
  /* WHAT THE BOX MEASURED, its sentence ended (firmware 0.1.38): how long, when a voice was heard, the bar it
139
139
  used -- beside the message, with what reached this side. */
140
- export function endOf(ep) {
140
+ export function endOf(ep, reason = '') {
141
141
  if (!ep || typeof ep !== 'object') return '';
142
- const n = (v) => (Number.isFinite(v) ? v : null);
142
+ const n = (v) => Number.isFinite(v);
143
143
  const sec = (v) => `${v.toFixed(1).replace('.', ',')} s`;
144
- const parts = [];
145
- if (n(ep.s) !== null) parts.push(`écoute ${sec(ep.s)}`);
146
- parts.push(n(ep.heard_at) !== null && ep.heard_at >= 0 ? `voix dès ${sec(ep.heard_at)}` : 'aucune voix détectée');
147
- if (n(ep.bar) !== null) parts.push(`seuil ${Math.round(ep.bar)}`);
148
- if (n(ep.voice) !== null && ep.voice > 0) parts.push(`voix ${Math.round(ep.voice)}`);
149
- if (n(ep.mean) !== null) parts.push(`moyenne ${Math.round(ep.mean)}`);
150
- if (n(ep.room) !== null) parts.push(`pièce ${Math.round(ep.room)}`);
151
- return `boîtier : ${parts.join(', ')}`;
144
+ const parts = [`fin ${String(reason).slice(0, 12)}${n(ep.s) ? ` ${sec(ep.s)}` : ''}`.replace(/\s+/g, ' ').trim()];
145
+ parts.push(n(ep.heard_at) && ep.heard_at >= 0 ? `voix dès ${sec(ep.heard_at)}` : 'sans voix');
146
+ if (n(ep.bar)) parts.push(`seuil ${Math.round(ep.bar)}`);
147
+ if (n(ep.voice) && ep.voice > 0) parts.push(`voix ${Math.round(ep.voice)}`);
148
+ if (n(ep.mean)) parts.push(`moy ${Math.round(ep.mean)}`);
149
+ return parts.join(' · ');
152
150
  }
153
151
  export const THINKING_AFTER_MS = 3_500;
154
152
  export const LONGER_AFTER_MS = 12_000;
@@ -156,10 +154,10 @@ export const THINKING = ['Hmm…', 'Voyons…', 'Hmm, voyons voir…'];
156
154
  /* WHY A BOX LISTENED, in a few words beside the message (01-11): what woke it (and the wake word's score), and
157
155
  what it cut short. */
158
156
  export function whyOf(m) {
159
- const reason = { wake: 'mot d\'éveil', button: 'bouton', follow: 'suite de la conversation', knock: 'toc-toc' }[m?.reason] ?? (m?.reason ? String(m.reason).slice(0, 30) : 'inconnu');
160
- const score = Number.isFinite(m?.score) ? ` (${Math.round(m.score * 100)} %)` : '';
161
- const cut = m?.cut ? ` ; a interrompu ${String(m.cut) === 'its own speech' ? 'sa propre phrase' : 'un son'}` : '';
162
- return `réveil : ${reason}${score}${cut}`;
157
+ const reason = { wake: 'éveil', button: 'bouton', follow: 'suite', knock: 'toc-toc' }[m?.reason] ?? (m?.reason ? String(m.reason).slice(0, 20) : 'inconnu');
158
+ const score = Number.isFinite(m?.score) ? ` ${Math.round(m.score * 100)} %` : '';
159
+ const cut = m?.cut ? ` · a coupé ${String(m.cut) === 'its own speech' ? 'sa phrase' : 'un son'}` : '';
160
+ return `${reason}${score}${cut}`;
163
161
  }
164
162
 
165
163
  /* HOW LOUD WHAT THE BOX SENT WAS (01-11): beside the message, so a sentence that came empty (a wake, then
@@ -173,7 +171,7 @@ export function levelOf(pcm) {
173
171
  export const QUIET_LEVEL = 150;
174
172
  export function soundOf(pcm) {
175
173
  const level = levelOf(pcm);
176
- return `son ${(pcm.length / 32_000).toFixed(1).replace('.', ',')} s, niveau ${level}${level < QUIET_LEVEL ? ' (presque silencieux)' : ''}`;
174
+ return `reçu ${(pcm.length / 32_000).toFixed(1).replace('.', ',')} s niv ${level}${level < QUIET_LEVEL ? ' (silence)' : ''}`;
177
175
  }
178
176
 
179
177
  export const DOING_WITHIN_MS = 120_000;
@@ -182,6 +180,9 @@ export const TEST_MIC = 'Test du micro. Parle-moi, je t\'écoute.';
182
180
  export const TEST_MIC_MS = 45_000;
183
181
  /* A LONG RECORDING (a meeting, a class): asked in words, stopped by the button or the wake word. */
184
182
  export const RECORD_ASKED = /\b(?:lance|d[ée]marre|commence|d[ée]bute)\w*\b.{0,25}\benregistrement\b|\benregistre\b.{0,20}\b(?:r[ée]union|conversation|cours|discussion|consultation)\b/i;
183
+ /* Off (01-11): a recording started without being asked, twice in a morning; back once it is asked for on
184
+ purpose (a button on the page). */
185
+ export const RECORD_BY_VOICE = false;
185
186
  export const RECORD_MAX_BYTES = 4 * 3600 * 32_000; /* four hours */
186
187
  export const mmss = (s) => `${String(Math.floor(s / 60)).padStart(2, '0')}:${String(Math.floor(s % 60)).padStart(2, '0')}`;
187
188
  /* THE MIXER of a box that plays a stream: words said meanwhile go over it, the stream lowered to DUCK while
@@ -651,9 +652,9 @@ export class Boxes {
651
652
  return;
652
653
  }
653
654
  if (m.t === 'listen.end' && m.ep) {
654
- const end = endOf(m.ep);
655
- link.why = `${link.why ? `${link.why} ; ` : ''}fin : ${String(m.reason ?? '').slice(0, 20)} ; ${end}`;
656
- this.#log(`voice box ${box.name}: listen ended (${String(m.reason ?? '').slice(0, 20)}), ${end}`);
655
+ const end = endOf(m.ep, m.reason ?? '');
656
+ link.why = `${link.why ? `${link.why} · ` : ''}${end}`;
657
+ this.#log(`voice box ${box.name}: ${end}`);
657
658
  }
658
659
  if (m.t === 'listen.end' && sentence) {
659
660
  const pcm = Buffer.concat(sentence);
@@ -739,7 +740,7 @@ export class Boxes {
739
740
  const box = link.box();
740
741
  /* Only a short order starts a recording ("lance l'enregistrement de la réunion"): a sentence that merely
741
742
  mentions recording does not (01-11). */
742
- if (RECORD_ASKED.test(text) && text.split(/\s+/).length <= 10 && this.#recordDir && this.#parts) {
743
+ if (RECORD_BY_VOICE && RECORD_ASKED.test(text) && text.split(/\s+/).length <= 10 && this.#recordDir && this.#parts) {
743
744
  this.#log(`voice box ${box.name}: a recording asked`);
744
745
  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 */ }
745
746
  link.send({ t: 'record', on: true });
@@ -749,7 +750,7 @@ export class Boxes {
749
750
  link.relay = 0;
750
751
  text = `(réponse entendue de l'appareil, pas de la personne) ${text}`;
751
752
  }
752
- try { await this.#say(box.conversation, text, { id: box.id, name: box.name, ...(box.place ? { place: box.place } : {}), why: `${link.why ? `${link.why} ; ` : ''}${soundOf(pcm)}` }); } catch (error) { this.#log(`voice box ${box.name}: ${seconds} s heard and dictated, but not said in ${box.conversation} (${error.message})`); await lost("Pardon, je n'ai pas pu transmettre ta phrase. Tu peux répéter ?"); return; }
753
+ try { await this.#say(box.conversation, text, { id: box.id, name: box.name, ...(box.place ? { place: box.place } : {}), why: `${link.why ? `${link.why} · ` : ''}${soundOf(pcm)}` }); } catch (error) { this.#log(`voice box ${box.name}: ${seconds} s heard and dictated, but not said in ${box.conversation} (${error.message})`); await lost("Pardon, je n'ai pas pu transmettre ta phrase. Tu peux répéter ?"); return; }
753
754
  this.#log(`voice box ${box.name}: ${seconds} s heard, said in ${box.conversation}`);
754
755
  link.heardAt = this.#now();
755
756
  if (WAITING_WORDS) this.#waitFor(link, text);