clavarium 0.2.115-beta.1 → 0.2.116-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/boxes.mjs +20 -3
- package/server/files.mjs +14 -5
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.116-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.116-beta.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
|
@@ -97,6 +97,8 @@ export function forSpeech(text) {
|
|
|
97
97
|
.replace(/\b([01]?\d|2[0-3])\s?[hH](?:\s?([0-5]\d))?\b/g, (_, h, m) => `${h} heure${h === '1' || h === '0' ? '' : 's'}${m ? ` ${m}` : ''}`)
|
|
98
98
|
/* Never its own wake word aloud: the box heard itself and cut its own sentence (31-10). */
|
|
99
99
|
.replace(/\b(?:hey|hé|eh)[\s,]+jarvis\b/giu, 'le mot d\'éveil')
|
|
100
|
+
.replace(/(?<![\p{L}])m[ée]sanges?(?![\p{L}])/giu, 'le mot d\'éveil')
|
|
101
|
+
.replace(/(?<![\p{L}])m[eéè]s[\s-]+anges?(?![\p{L}])/giu, 'le mot d\'éveil') /* what sounds like it: « mes anges » woke it (31-10) */
|
|
100
102
|
.replace(/\s+/g, ' ')
|
|
101
103
|
.trim()
|
|
102
104
|
.slice(0, 1500);
|
|
@@ -128,6 +130,7 @@ export function mix(stream, chunk) {
|
|
|
128
130
|
return out;
|
|
129
131
|
}
|
|
130
132
|
|
|
133
|
+
export const ANSWER_WITHIN_MS = 90_000;
|
|
131
134
|
export const CHAT_WITHIN_MS = 3 * 60_000;
|
|
132
135
|
export const LISTEN_AHEAD = 3 * 32_000; /* bytes: what a box is sent ahead of what it plays (its buffer holds 16 s) */
|
|
133
136
|
|
|
@@ -382,12 +385,15 @@ export class Boxes {
|
|
|
382
385
|
it ends when nobody answers, or on "fin de la conversation". */
|
|
383
386
|
const question = !doing && (asked || /\?\s*$/.test(words));
|
|
384
387
|
for (const l of boxes) {
|
|
385
|
-
|
|
388
|
+
/* An answer -- to a sentence heard within a minute -- may open the conversation; something said
|
|
389
|
+
of itself (a news item, a reminder) does not: the box listened after it for nothing (31-10). */
|
|
390
|
+
const answering = l.heardAt && this.#now() - l.heardAt < ANSWER_WITHIN_MS;
|
|
391
|
+
const chatting = !doing && answering && this.#chatting(l);
|
|
386
392
|
const opening = chatting && !l.chat;
|
|
387
393
|
if (chatting) l.chat = true;
|
|
388
394
|
let pcm;
|
|
389
395
|
try { pcm = await this.#speak(opening ? `Je passe en mode conversation : je reste à l'écoute. ${words}` : words); } catch (error) { this.#log(`voice box: no voice for the answer (${error.message})`); l.send({ t: 'cue', name: 'error' }); continue; }
|
|
390
|
-
l.play(pcm, question || chatting ? 'listen' : null);
|
|
396
|
+
l.play(pcm, question || chatting ? 'listen' : null); /* a question is always listened after: an answer is expected */
|
|
391
397
|
}
|
|
392
398
|
}
|
|
393
399
|
#chatting(link) {
|
|
@@ -524,7 +530,18 @@ export class Boxes {
|
|
|
524
530
|
};
|
|
525
531
|
try {
|
|
526
532
|
const said = [];
|
|
527
|
-
|
|
533
|
+
/* The dictation fails now and then (the network, the engine): tried again by itself, twice, before
|
|
534
|
+
anything is said to the person -- who should not have to repeat (31-10). */
|
|
535
|
+
const hear = async (wav) => {
|
|
536
|
+
for (let attempt = 0; ; attempt++) {
|
|
537
|
+
try { return await this.#hear(wav); } catch (error) {
|
|
538
|
+
if (attempt >= 2 || error?.status === 413 || error?.status === 400) throw error;
|
|
539
|
+
this.#log(`voice box ${box0.name}: dictation failed (${error.message}), tried again`);
|
|
540
|
+
await new Promise((r) => setTimeout(r, 800 * (attempt + 1)));
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
for (const piece of piecesOf(pcm)) said.push(String(await hear(wavOf(piece)) ?? '').trim());
|
|
528
545
|
text = said.filter(Boolean).join(' ');
|
|
529
546
|
} catch (error) { this.#log(`voice box ${box0.name}: ${seconds} s heard, dictation failed (${error.message})`); await lost('Pardon, la dictée ne répond pas. Tu peux répéter ?'); return; }
|
|
530
547
|
if (!text) { this.#log(`voice box ${box0.name}: ${seconds} s heard, nothing recognised (silence?)`); await lost("Pardon, je n'ai rien compris. Tu peux répéter ?"); return; }
|
package/server/files.mjs
CHANGED
|
@@ -162,6 +162,8 @@ export async function importFile(root, relative, name, request, { exists = 'keep
|
|
|
162
162
|
*/
|
|
163
163
|
export const EDIT_MAX = 1024 * 1024;
|
|
164
164
|
export const THUMB_MAX = 8 * 1024 * 1024;
|
|
165
|
+
/* A sound played in the thread: a few minutes of speech or music. */
|
|
166
|
+
export const SOUND_MAX = 40 * 1024 * 1024;
|
|
165
167
|
/* One drop of files or of a folder: as a whole, this many bytes and files at most. */
|
|
166
168
|
export const BATCH_MAX = 2 * 1024 * 1024 * 1024;
|
|
167
169
|
export const BATCH_FILES = 2000;
|
|
@@ -391,6 +393,11 @@ const SIGNATURES = [
|
|
|
391
393
|
['image/jpeg', (b) => b.length >= 3 && b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff],
|
|
392
394
|
['image/gif', (b) => b.length >= 6 && /^GIF8[79]a$/.test(b.subarray(0, 6).toString('latin1'))],
|
|
393
395
|
['image/webp', (b) => b.length >= 12 && b.subarray(0, 4).toString('latin1') === 'RIFF' && b.subarray(8, 12).toString('latin1') === 'WEBP'],
|
|
396
|
+
/* Sounds, played in the thread as the pictures are shown (Parley's player): proved by their bytes too. */
|
|
397
|
+
['audio/wav', (b) => b.length >= 12 && b.subarray(0, 4).toString('latin1') === 'RIFF' && b.subarray(8, 12).toString('latin1') === 'WAVE'],
|
|
398
|
+
['audio/mpeg', (b) => b.length >= 3 && (b.subarray(0, 3).toString('latin1') === 'ID3' || (b[0] === 0xff && (b[1] & 0xe0) === 0xe0))],
|
|
399
|
+
['audio/ogg', (b) => b.length >= 4 && b.subarray(0, 4).toString('latin1') === 'OggS'],
|
|
400
|
+
['audio/mp4', (b) => b.length >= 12 && b.subarray(4, 8).toString('latin1') === 'ftyp'],
|
|
394
401
|
];
|
|
395
402
|
export const IMAGE_HEADERS = Object.freeze({
|
|
396
403
|
'content-security-policy': "default-src 'none'; sandbox",
|
|
@@ -401,15 +408,17 @@ export const IMAGE_HEADERS = Object.freeze({
|
|
|
401
408
|
});
|
|
402
409
|
export async function picture(root, relative) {
|
|
403
410
|
const at = await regular(root, relative);
|
|
404
|
-
|
|
405
|
-
if (
|
|
411
|
+
const sound = /\.(wav|mp3|ogg|oga|opus|m4a)$/i.test(at.name);
|
|
412
|
+
if (!sound && !/\.(png|jpe?g|gif|webp)$/i.test(at.name)) throw new Refusal(415, 'Only a PNG, JPEG, GIF or WebP picture, or a WAV, MP3, Ogg or M4A sound, is shown in the thread.');
|
|
413
|
+
const most = sound ? SOUND_MAX : THUMB_MAX;
|
|
414
|
+
if (at.info.size > most) throw new Refusal(413, sound ? 'This sound is too large to play here.' : 'This picture is too large for a thumbnail.');
|
|
406
415
|
const handle = await open(at.path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
407
416
|
try {
|
|
408
417
|
const info = await handle.stat();
|
|
409
|
-
if (!info.isFile() || info.size >
|
|
418
|
+
if (!info.isFile() || info.size > most) throw new Refusal(413, 'This file is too large to show here.');
|
|
410
419
|
const bytes = await readAll(handle, info.size);
|
|
411
|
-
const type = SIGNATURES.find(([, is]) => is(bytes))?.[0];
|
|
412
|
-
if (!type) throw new Refusal(415,
|
|
420
|
+
const type = SIGNATURES.find(([kind, is]) => kind.startsWith(sound ? 'audio/' : 'image/') && is(bytes))?.[0];
|
|
421
|
+
if (!type) throw new Refusal(415, `This file is not the ${sound ? 'sound' : 'picture'} its name says.`);
|
|
413
422
|
return { type, bytes, version: versionOf(info) };
|
|
414
423
|
} finally { await handle.close(); }
|
|
415
424
|
}
|