clavarium 0.2.310-next.1 → 0.2.312-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.310-next.1",
3
+ "version": "0.2.312-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.310-next.1",
9
+ "version": "0.2.312-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.310-next.1",
3
+ "version": "0.2.312-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/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/style.css CHANGED
@@ -2308,6 +2308,9 @@ button.salon-switch[aria-checked="true"]::after { left: 18px; background: var(--
2308
2308
  /* The list's button on each page of its own (03-11), as the conversation's. */
2309
2309
  /* THE TOP BAR of every page (03-11): the conversation's header, the same element and looks (header {...} above). */
2310
2310
  header.topbar { flex-shrink: 0; }
2311
+ /* A place's top bar stays at the top while its page scrolls (05-11), as a conversation's does: the sheet scrolls,
2312
+ so the bar sticks to its top edge, over its padding. */
2313
+ .sheet > header.topbar { position: sticky; top: -14px; z-index: 5; margin-top: -14px; padding-top: 14px; background: var(--panel); }
2311
2314
  header.topbar > .fold-here { font-size: 1rem; line-height: 1; padding: 4px 9px; flex: none; }
2312
2315
  @media (max-width: 700px) { header.topbar > .fold-here { display: none; } }
2313
2316
  header.topbar > b { flex: 1 1 auto; font-size: 1rem; }