clavarium 0.2.295-next.1 → 0.2.296-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.295-next.1",
3
+ "version": "0.2.296-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.295-next.1",
9
+ "version": "0.2.296-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.295-next.1",
3
+ "version": "0.2.296-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
@@ -27,6 +27,11 @@ export const LINK_PATH = '/c/api/box/ws';
27
27
  /* A firmware a box downloads to update itself: a one-use address, kept a few minutes. */
28
28
  export const FIRMWARE_PATH = '/c/api/box/firmware/';
29
29
  export const FIRMWARE_MINUTES = 10;
30
+ /* THE WAKE WORD HEARD AGAIN (03-11): « Mésange » and what a dictation makes of it (mes anges, mais sange...). */
31
+ export const CLIP_MAX_BYTES = 16_000 * 2 * 3;
32
+ export const WAKE_HEARD = /\bm[ae]i?s+\s?an?ge?s?\b|\bmes anges?\b|\bmesange|\bmaisange|\bmessage?s?\b/;
33
+ export const WAKE_DROP = process.env.CLAVARIUM_WAKE_DROP === '1';
34
+ const plainWords = (t) => String(t).toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/[^a-z\s]/g, ' ').replace(/\s+/g, ' ').trim();
30
35
  export const SENTENCE_MAX = 300 * 32_000 + 32_000; /* 5 min of 16 kHz 16-bit mono, and some slack */
31
36
  export const TRIES_PER_MINUTE = 10;
32
37
  export const NAME_MAX = 40;
@@ -620,6 +625,8 @@ export class Boxes {
620
625
  r.out.write(data); r.bytes += data.length;
621
626
  return;
622
627
  }
628
+ /* The wake word's own 1.6 s (wake.clip): kept apart, heard again before the word is trusted. */
629
+ if (link.clip) { if (link.clip.bytes < CLIP_MAX_BYTES) { link.clip.parts.push(Buffer.from(data)); link.clip.bytes += data.length; } return; }
623
630
  if (!sentence || link.muted) return;
624
631
  size += data.length;
625
632
  if (size <= SENTENCE_MAX) sentence.push(Buffer.from(data));
@@ -650,6 +657,8 @@ export class Boxes {
650
657
  r.out.end(() => { void this.#recorded(link, r); });
651
658
  return;
652
659
  }
660
+ if (m.t === 'wake.clip' && m.edge === 'start') { link.clip = { parts: [], bytes: 0 }; return; }
661
+ if (m.t === 'wake.clip' && m.edge === 'end' && link.clip) { const pcm = Buffer.concat(link.clip.parts); link.clip = null; link.wakeCheck = this.#checkWake(link, pcm); return; }
653
662
  if (m.t === 'event' && m.name === 'wake.own') { this.#log(`voice box ${box.name}: heard its own voice say the wake word, ignored`); return; }
654
663
  if (m.t === 'event' && m.name === 'noise.dropped') { this.#log(`voice box ${box.name}: a sound near full scale was cut by its noise guard`); return; }
655
664
  /* The box listens for a sentence while this side still records: the two disagree (a reconnection, a
@@ -659,7 +668,7 @@ export class Boxes {
659
668
  this.#log(`voice box ${box.name}: a sentence while recording here, the recording closed`);
660
669
  r.out.end(() => { void this.#recorded(link, r); });
661
670
  }
662
- if (m.t === 'listen.start') link.why = whyOf(m);
671
+ if (m.t === 'listen.start') { link.why = whyOf(m); if (m.reason !== 'wake') link.wakeCheck = null; }
663
672
  if (m.t === 'listen.start') { if (this.stop(box.id)) this.#log(`voice box ${box.name}: stopped playing, someone speaks`); sentence = []; size = 0; return; }
664
673
  if (m.t === 'listen.end' && sentence && m.reason === 'nobody') {
665
674
  /* Listened again, nobody spoke: a conversation ends there, in silence. */
@@ -732,6 +741,12 @@ export class Boxes {
732
741
  }
733
742
 
734
743
  /* Each step said in the server's log, never what was said: its length only. */
744
+ /* The 1.6 s before the sentence, heard again: is the wake word in it? Its words, and whether it reads as the word. */
745
+ async #checkWake(link, pcm) {
746
+ if (pcm.length < 8_000) return null;
747
+ const heard = String(await this.#hear(wavOf(pcm), link.box().lang) ?? '').trim();
748
+ return { heard, ok: WAKE_HEARD.test(plainWords(heard)) };
749
+ }
735
750
  async #heard(link, pcm) {
736
751
  const box0 = link.box();
737
752
  const seconds = (pcm.length / 32_000).toFixed(1);
@@ -773,6 +788,14 @@ export class Boxes {
773
788
  }
774
789
  if (!text) { this.#log(`voice box ${box0.name}: ${seconds} s heard, nothing recognised (${soundOf(pcm)})`); await lost("Pardon, je n'ai rien compris. Tu peux répéter ?"); return; }
775
790
  const box = link.box();
791
+ /* The wake word heard again (wake.clip): said beside the message; dropped in silence only once that is
792
+ turned on (WAKE_DROP), after its results were looked at -- a real call must never be lost to it. */
793
+ const check = link.wakeCheck ? await link.wakeCheck.catch(() => null) : null; link.wakeCheck = null;
794
+ if (check) {
795
+ link.why = `${link.why ? `${link.why} · ` : ''}mot ${check.ok ? '\u2713' : '\u2717'} « ${check.heard.slice(0, 30)} »`;
796
+ this.#log(`voice box ${box.name}: wake word heard again: ${check.ok ? 'yes' : 'NO'} (« ${check.heard.slice(0, 40)} »)`);
797
+ if (!check.ok && WAKE_DROP) { link.send({ t: 'cue', name: 'done' }); return; }
798
+ }
776
799
  /* Only a short order starts a recording ("lance l'enregistrement de la réunion"): a sentence that merely
777
800
  mentions recording does not (01-11). */
778
801
  if (RECORD_BY_VOICE && RECORD_ASKED.test(text) && text.split(/\s+/).length <= 10 && this.#recordDir && this.#parts) {