clavarium 0.2.155-beta.1 → 0.2.156-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/speech.mjs +3 -0
- package/server/spoken.mjs +60 -0
- package/web/app.js +33 -0
- package/web/style.css +8 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.156-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.156-beta.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
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
|
@@ -424,6 +424,39 @@
|
|
|
424
424
|
return bar;
|
|
425
425
|
}
|
|
426
426
|
for (const top of [...document.querySelectorAll('#places .sheet > .panel-top')]) topBar(top, top.parentElement.id === 'salon' ? { state: 'salon-state' } : {});
|
|
427
|
+
/* A SEARCH ATOP A SETTINGS PAGE (05-11): one field in its top bar; what is typed keeps only the chapters (or
|
|
428
|
+
blocks) whose title or rows say it, opened; the headings left with nothing are hidden. Emptied, all comes back
|
|
429
|
+
as it was. The server's Settings, a conversation's, and any sheet given the same shape. */
|
|
430
|
+
const settingsSearch = (sheet) => {
|
|
431
|
+
const bar = sheet?.querySelector(':scope > header.topbar .bar-right') ?? sheet?.querySelector(':scope > header.topbar') ?? sheet?.querySelector(':scope > .panel-top');
|
|
432
|
+
if (!bar || sheet.querySelector('.settings-search')) return;
|
|
433
|
+
const field = document.createElement('input'); field.type = 'search'; field.className = 'settings-search';
|
|
434
|
+
field.placeholder = 'Search'; field.setAttribute('aria-label', 'Search these settings'); field.autocomplete = 'off';
|
|
435
|
+
bar.prepend(field);
|
|
436
|
+
const items = () => {
|
|
437
|
+
const chapters = [...sheet.querySelectorAll('details.chapter')];
|
|
438
|
+
return chapters.length ? chapters : [...sheet.querySelectorAll(':scope > :not(header.topbar):not(.panel-top)')].filter((e) => e.querySelector(':scope > .panel-top'));
|
|
439
|
+
};
|
|
440
|
+
const wasOpen = new Map();
|
|
441
|
+
const norm = (t) => String(t).toLowerCase().normalize('NFD').replace(/[̀-ͯ]/g, '');
|
|
442
|
+
field.addEventListener('input', () => {
|
|
443
|
+
const q = norm(field.value.trim());
|
|
444
|
+
sheet.dataset.searching = q ? 'on' : '';
|
|
445
|
+
for (const it of items()) {
|
|
446
|
+
if (!q) { it.hidden = false; for (const row of it.querySelectorAll('.search-out')) row.classList.remove('search-out'); if (it.tagName === 'DETAILS' && wasOpen.has(it)) { it.open = wasOpen.get(it); wasOpen.delete(it); } continue; }
|
|
447
|
+
const hit = norm(it.textContent).includes(q);
|
|
448
|
+
it.hidden = !hit;
|
|
449
|
+
/* Within a chapter whose title does not say it: only its rows that do. */
|
|
450
|
+
const head = it.querySelector(':scope > summary, :scope > .panel-top');
|
|
451
|
+
const whole = !head || norm(head.textContent).includes(q);
|
|
452
|
+
for (const row of it.querySelectorAll('.set-row')) row.classList.toggle('search-out', hit && !whole && !norm(row.textContent).includes(q));
|
|
453
|
+
if (hit && it.tagName === 'DETAILS') { if (!wasOpen.has(it)) wasOpen.set(it, it.open); it.open = true; }
|
|
454
|
+
}
|
|
455
|
+
for (const group of sheet.querySelectorAll('.settings-group')) group.hidden = Boolean(q) && ![...group.querySelectorAll('details.chapter')].some((d) => !d.hidden);
|
|
456
|
+
});
|
|
457
|
+
field.addEventListener('keydown', (e) => { if (e.key === 'Escape' && field.value) { e.stopPropagation(); field.value = ''; field.dispatchEvent(new Event('input')); } });
|
|
458
|
+
};
|
|
459
|
+
for (const id of ['settings', 'panel']) settingsSearch($(id));
|
|
427
460
|
/* A room's title: its name, and under it who speaks now (salonLive). */
|
|
428
461
|
/* The device page (/c/) has no rooms sheet (05-11: it stopped app.js there, the page stuck on connecting). */
|
|
429
462
|
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); }
|
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; }
|
|
@@ -2580,3 +2583,8 @@ header.topbar .views .icon-btn { width: auto; height: auto; }
|
|
|
2580
2583
|
.ft *, .ft *::before, .ft *::after, .ft-toast { animation: none !important; transition: none !important; }
|
|
2581
2584
|
.ft-house .ft-wire.lit, .ft-house .ft-link.lit { stroke-dashoffset: 0 !important; }
|
|
2582
2585
|
}
|
|
2586
|
+
|
|
2587
|
+
/* The search atop a settings page (05-11). */
|
|
2588
|
+
:is(header.topbar, .panel-top) .settings-search { margin-left: auto; width: min(240px, 42vw); min-height: 32px; padding: 4px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-size: .875rem; }
|
|
2589
|
+
.sheet[data-searching="on"] .settings-nav { opacity: .5; }
|
|
2590
|
+
.set-row.search-out { display: none; }
|