clavarium 0.2.223-next.1 → 0.2.225-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.
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/boxes.mjs +17 -19
- package/server/voice.mjs +6 -1
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.225-next.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.225-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
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) =>
|
|
142
|
+
const n = (v) => Number.isFinite(v);
|
|
143
143
|
const sec = (v) => `${v.toFixed(1).replace('.', ',')} s`;
|
|
144
|
-
const parts = [];
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (n(ep.
|
|
148
|
-
if (n(ep.
|
|
149
|
-
|
|
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: '
|
|
160
|
-
const score = Number.isFinite(m?.score) ? `
|
|
161
|
-
const cut = m?.cut ? `
|
|
162
|
-
return
|
|
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 `
|
|
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;
|
|
@@ -654,9 +652,9 @@ export class Boxes {
|
|
|
654
652
|
return;
|
|
655
653
|
}
|
|
656
654
|
if (m.t === 'listen.end' && m.ep) {
|
|
657
|
-
const end = endOf(m.ep);
|
|
658
|
-
link.why = `${link.why ? `${link.why}
|
|
659
|
-
this.#log(`voice box ${box.name}:
|
|
655
|
+
const end = endOf(m.ep, m.reason ?? '');
|
|
656
|
+
link.why = `${link.why ? `${link.why} · ` : ''}${end}`;
|
|
657
|
+
this.#log(`voice box ${box.name}: ${end}`);
|
|
660
658
|
}
|
|
661
659
|
if (m.t === 'listen.end' && sentence) {
|
|
662
660
|
const pcm = Buffer.concat(sentence);
|
|
@@ -752,7 +750,7 @@ export class Boxes {
|
|
|
752
750
|
link.relay = 0;
|
|
753
751
|
text = `(réponse entendue de l'appareil, pas de la personne) ${text}`;
|
|
754
752
|
}
|
|
755
|
-
try { await this.#say(box.conversation, text, { id: box.id, name: box.name, ...(box.place ? { place: box.place } : {}), why: `${link.why ? `${link.why}
|
|
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; }
|
|
756
754
|
this.#log(`voice box ${box.name}: ${seconds} s heard, said in ${box.conversation}`);
|
|
757
755
|
link.heardAt = this.#now();
|
|
758
756
|
if (WAITING_WORDS) this.#waitFor(link, text);
|
package/server/voice.mjs
CHANGED
|
@@ -85,10 +85,15 @@ const PHANTOMS = [
|
|
|
85
85
|
/^\s*(?:thank(?:s| you) (?:so much )?for watching[.!,]?\s*(?:(?:and )?see you (?:in the |on the )?next (?:video|time)[.!]?)?|see you (?:in the )?next (?:video|time)[.!]?|merci d'avoir regardé(?: cette vidéo)?\s*[.!]?(?:\s*[àa] bient[ôo]t[.!]?)?)\s*$/giu,
|
|
86
86
|
/untertitel(?:ung)?\s+(?:im\s+auftrag\s+)?des\s+zdf(?:\s+für\s+funk)?,?\s*\d{0,4}[.!]?/giu,
|
|
87
87
|
];
|
|
88
|
+
/* Chinese, Japanese or Korean mixed into Latin words: written on a room's silence (01-11: « Sous 谢谢 大家 »);
|
|
89
|
+
a sentence wholly in one of them is kept. And the « Sous » its credits leave behind, when it is all. */
|
|
90
|
+
const FOREIGN_SCRIPT = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]+/gu;
|
|
88
91
|
export function withoutPhantoms(text) {
|
|
89
92
|
let t = text;
|
|
90
93
|
for (const re of PHANTOMS) t = t.replace(re, ' ');
|
|
91
|
-
|
|
94
|
+
if (/\p{Script=Latin}/u.test(t)) t = t.replace(FOREIGN_SCRIPT, ' ');
|
|
95
|
+
t = t.replace(/\s+/gu, ' ').trim();
|
|
96
|
+
return /^sous[.!,…]*$/iu.test(t) ? '' : t;
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
/* SPEECH HAS A SPEED: nobody says more than ~25 characters a second. More
|