clavarium 0.2.309-next.1 → 0.2.311-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.309-next.1",
3
+ "version": "0.2.311-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.309-next.1",
9
+ "version": "0.2.311-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.309-next.1",
3
+ "version": "0.2.311-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
@@ -31,7 +31,7 @@ export const FIRMWARE_PATH = '/c/api/box/firmware/';
31
31
  export const FIRMWARE_MINUTES = 10;
32
32
  /* THE WAKE WORD HEARD AGAIN (03-11): « Mésange » and what a dictation makes of it (mes anges, mais sange...). */
33
33
  export const CLIP_MAX_BYTES = 16_000 * 2 * 3;
34
- export const WAKE_HEARD = /\bm[ae]i?s+\s?an?ge?s?\b|\bmes anges?\b|\bmesange|\bmaisange|\bmessage?s?\b|\bmessenge?s?\b/; /* « Messenges »: Whisper's reading of the server's own voice saying it */
34
+ export const WAKE_HEARD = /\bm[ae]i?s+\s?an?ge?s?\b|\b[ml][ae]s anges?\b|\bmesange|\bmaisange|\bmessage?s?\b|\bmessenge?s?\b/; /* « Messenges »: Whisper's reading of the server's own voice saying it */
35
35
  export const WAKE_DROP = process.env.CLAVARIUM_WAKE_DROP === '1';
36
36
  const plainWords = (t) => String(t).toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/[^a-z\s]/g, ' ').replace(/\s+/g, ' ').trim();
37
37
  export const SENTENCE_MAX = 300 * 32_000 + 32_000; /* 5 min of 16 kHz 16-bit mono, and some slack */
package/server/speech.mjs CHANGED
@@ -12,6 +12,7 @@ import { pipeline } from 'node:stream/promises';
12
12
  import { Readable } from 'node:stream';
13
13
  import { execFile } from 'node:child_process';
14
14
  import { promisify } from 'node:util';
15
+ import { spokenFr } from './spoken.mjs';
15
16
 
16
17
  export const VOICES = Object.freeze({
17
18
  fr: 'vits-piper-fr_FR-upmc-medium', /* chosen by ear on the real box (31-10), over Siwis, Tom, Gilles and Kokoro */
@@ -131,6 +132,8 @@ export class Speech {
131
132
 
132
133
  /* Text -> PCM 16 kHz. */
133
134
  async speak(text) {
135
+ /* Numbers, times and amounts in words, in French (05-11: digits were unintelligible aloud). */
136
+ if (this.#lang === 'fr') text = spokenFr(text);
134
137
  /* Pocket first; failed, it rests five minutes and the next voice answers meanwhile. */
135
138
  /* One voice from the start of an answer to its end (03-11: "tu as bougé de voix au milieu"): a sentence it
136
139
  misses is asked of it once more, a moment later, before another voice says it. */
@@ -0,0 +1,60 @@
1
+ /* NUMBERS SAID IN WORDS (05-11): the box's voice read digits in the middle of a French sentence badly
2
+ * (« 22 h 34 », « 12,02 € » came out unintelligible). Before a French text is spoken, its times, amounts,
3
+ * decimals, percentages, versions and whole numbers are written in words. Only French: other languages
4
+ * are left as they are. */
5
+
6
+ const UNITS = ['zéro', 'un', 'deux', 'trois', 'quatre', 'cinq', 'six', 'sept', 'huit', 'neuf', 'dix', 'onze', 'douze', 'treize', 'quatorze', 'quinze', 'seize'];
7
+ const TENS = { 20: 'vingt', 30: 'trente', 40: 'quarante', 50: 'cinquante', 60: 'soixante' };
8
+
9
+ function below100(n) {
10
+ if (n <= 16) return UNITS[n];
11
+ if (n < 20) return `dix-${UNITS[n - 10]}`;
12
+ if (n < 70) { const t = Math.floor(n / 10) * 10, u = n % 10; return u === 0 ? TENS[t] : u === 1 ? `${TENS[t]} et un` : `${TENS[t]}-${UNITS[u]}`; }
13
+ if (n < 80) { const u = n - 60; return u === 11 ? 'soixante et onze' : `soixante-${below100(u)}`; }
14
+ const u = n - 80;
15
+ return u === 0 ? 'quatre-vingts' : `quatre-vingt-${below100(u)}`;
16
+ }
17
+ function below1000(n) {
18
+ const h = Math.floor(n / 100), r = n % 100;
19
+ if (h === 0) return below100(r);
20
+ const head = h === 1 ? 'cent' : `${UNITS[h]} cent${r === 0 ? 's' : ''}`;
21
+ return r === 0 ? head : `${head} ${below100(r)}`;
22
+ }
23
+ /* A whole number in French words, 0 to 999 999 999 999. */
24
+ export function numberFr(n) {
25
+ n = Math.floor(Number(n));
26
+ if (!Number.isFinite(n) || n < 0 || n > 999_999_999_999) return String(n);
27
+ if (n < 1000) return below1000(n);
28
+ const parts = [];
29
+ for (const [size, one, many] of [[1e9, 'un milliard', 'milliards'], [1e6, 'un million', 'millions'], [1e3, 'mille', 'mille']]) {
30
+ const q = Math.floor(n / size); n %= size;
31
+ if (q === 0) continue;
32
+ if (q === 1) parts.push(one);
33
+ else { let w = below1000(q); if (size === 1e3) w = w.replace(/cents$/, 'cent').replace(/vingts$/, 'vingt'); parts.push(`${w} ${many}`); }
34
+ }
35
+ if (n) parts.push(below1000(n));
36
+ return parts.join(' ');
37
+ }
38
+ /* Digits after a decimal comma, said as a number unless it starts with zeros (« zéro deux »). */
39
+ const fraction = (d) => (/^0/.test(d) ? [...d].map((c) => UNITS[c]).join(' ') : numberFr(Number(d)));
40
+ const whole = (s) => numberFr(Number(String(s).replace(/[\s  .]/g, '')));
41
+
42
+ export function spokenFr(text) {
43
+ let t = String(text ?? '');
44
+ /* Versions and dotted numbers: 0.1.51 */
45
+ t = t.replace(/\b(\d+)\.(\d+)\.(\d+)\b/g, (_, a, b, c) => `${numberFr(a)} point ${numberFr(b)} point ${numberFr(c)}`);
46
+ /* Times: 22 h 34, 22h34, 22:34, 7 h */
47
+ t = t.replace(/\b([01]?\d|2[0-3])\s?(?:h|:)\s?([0-5]\d)\b/g, (_, h, m) => `${numberFr(h)} heure${Number(h) > 1 ? 's' : ''} ${Number(m) ? numberFr(m) : ''}`.trim());
48
+ t = t.replace(/\b([01]?\d|2[0-3])\s?h\b/g, (_, h) => `${numberFr(h)} heure${Number(h) > 1 ? 's' : ''}`);
49
+ /* Amounts: 1 823,03 €, 12,02 euros, 15 € */
50
+ t = t.replace(/\b(\d{1,3}(?:[   ]\d{3})+|\d+)(?:,(\d{1,2}))?[   ]?(?:€|euros?\b)/g, (_, e, c) => `${whole(e)} euro${whole(e) === 'un' ? '' : 's'}${c && Number(c.padEnd(2, '0')) ? ` ${numberFr(Number(c.padEnd(2, '0')))}` : ''}`);
51
+ t = t.replace(/(\d)\s?€/g, '$1 euros');
52
+ /* Percentages: 94 %, 1,18 % */
53
+ t = t.replace(/\b(\d+)(?:,(\d+))?\s?%/g, (_, i, d) => `${numberFr(i)}${d ? ` virgule ${fraction(d)}` : ''} pour cent`);
54
+ /* Decimals: 12,02 */
55
+ t = t.replace(/\b(\d+),(\d+)\b/g, (_, i, d) => `${numberFr(i)} virgule ${fraction(d)}`);
56
+ /* Whole numbers with a non-breaking or thin space between thousands (21 876); a plain space is left alone (« 99 100 » may be two numbers). */
57
+ t = t.replace(/\b\d{1,3}(?:[  ]\d{3})+\b/g, (s) => whole(s));
58
+ t = t.replace(/\b\d+\b/g, (s) => numberFr(s));
59
+ return t.replace(/\s{2,}/g, ' ');
60
+ }
package/web/app.js CHANGED
@@ -425,9 +425,10 @@
425
425
  }
426
426
  for (const top of [...document.querySelectorAll('#places .sheet > .panel-top')]) topBar(top, top.parentElement.id === 'salon' ? { state: 'salon-state' } : {});
427
427
  /* A room's title: its name, and under it who speaks now (salonLive). */
428
- { const t = $('salon-title'); const name = document.createElement('span'); name.id = 'salon-name'; name.textContent = t.textContent; const live = document.createElement('small'); live.id = 'salon-live'; live.className = 'salon-live'; live.hidden = true; t.replaceChildren(name, live); }
428
+ /* The device page (/c/) has no rooms sheet (05-11: it stopped app.js there, the page stuck on connecting). */
429
+ if ($('salon')) { const t = $('salon-title'); const name = document.createElement('span'); name.id = 'salon-name'; name.textContent = t.textContent; const live = document.createElement('small'); live.id = 'salon-live'; live.className = 'salon-live'; live.hidden = true; t.replaceChildren(name, live); }
429
430
  /* A room's settings: on its bar's right, in the same group of views a conversation's settings sit in. */
430
- { const views = document.createElement('div'); views.className = 'views'; views.setAttribute('role', 'group'); views.setAttribute('aria-label', 'Room'); views.append($('salon-settings')); $('salon').querySelector('.topbar .bar-right').prepend(views); }
431
+ if ($('salon')) { const views = document.createElement('div'); views.className = 'views'; views.setAttribute('role', 'group'); views.setAttribute('aria-label', 'Room'); views.append($('salon-settings')); $('salon').querySelector('.topbar .bar-right')?.prepend(views); }
431
432
  const applyFold = (folded) => {
432
433
  app.dataset.list = folded ? 'folded' : 'open';
433
434
  for (const f of [$('fold'), ...document.querySelectorAll('.fold-here')]) {