clavarium 0.2.113-beta.1 → 0.2.114-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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.113-beta.1",
3
+ "version": "0.2.114-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.113-beta.1",
9
+ "version": "0.2.114-beta.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.113-beta.1",
3
+ "version": "0.2.114-beta.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
@@ -336,7 +336,10 @@ export class Boxes {
336
336
  addressed to (`to`: box ids, #215). Anything else stays in the thread, silent -- a box
337
337
  read a whole technical message aloud once (31-10), which nobody wants. */
338
338
  async agentSaid(conversation, text, to = null, { doing = false, asked = false } = {}) {
339
- const words = forSpeech(text);
339
+ /* What it is doing is written for a screen ("Tâche de fond : bêta 0.2.113…"): read aloud, it was words
340
+ from nowhere (31-10). Aloud, only a short plain one; otherwise a word that it is at work. */
341
+ const plain = forSpeech(text);
342
+ const words = doing && (plain.length > 70 || /[\d:;/()[\]→=_]/.test(plain)) ? 'Je regarde, un instant.' : plain;
340
343
  if (!words) return;
341
344
  let boxes;
342
345
  if (doing) {
package/server/main.mjs CHANGED
@@ -605,7 +605,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
605
605
  const speech = new Speech({ dir: `${dataDir}/voices`, log: (line) => events.add({ kind: 'server', text: line }), secret: (name) => { try { return secrets.reveal(name) ?? undefined; } catch { return undefined; } } });
606
606
  boxes = new Boxes({ file: new JsonFile(`${dataDir}/boxes.json`, []),
607
607
  exists: (name) => all.list().some((c) => c.name === name),
608
- hear: (wav) => voice.transcribe(wav), /* the language of the dictation settings, or found by the engine: no language is assumed (a box has no browser to tell one) */
608
+ hear: (wav) => voice.transcribe(wav, undefined, { oneVoice: true }), /* the language of the dictation settings, or found by the engine: no language is assumed (a box has no browser to tell one) */
609
609
  /* Said as the person's own message, the room named (one speaker for now). */
610
610
  say: (name, text, by) => talk.say(name, text, undefined, undefined, 'voice', { by }),
611
611
  /* Each conversation's thread knows its boxes: their names, and the ids its agent answers. */
package/server/voice.mjs CHANGED
@@ -116,7 +116,17 @@ export function cleanDictation(raw, seconds) {
116
116
  const noTemperature = new Set();
117
117
 
118
118
  /* `audio` is a WAV file, as bytes. Resolves with the text to type. */
119
- export async function transcribe(config, audio, fetcher = fetch) {
119
+ /* ONE VOICE: a voice box hears a room, a TV included. OVH's engine tells voices apart (diarize): only the
120
+ voice that spoke first -- the person who called the box -- is kept (31-10). Other engines: the whole text. */
121
+ const DIARIZES = /^https:\/\/oai\.endpoints\.kepler\.ai\.cloud\.ovh\.net\//;
122
+ export function firstVoice(body) {
123
+ const parts = Array.isArray(body?.diarization) ? body.diarization.filter((p) => typeof p?.text === 'string') : [];
124
+ if (parts.length === 0) return null;
125
+ const who = parts[0].speaker;
126
+ return parts.filter((p) => p.speaker === who).map((p) => p.text.trim()).join(' ');
127
+ }
128
+
129
+ export async function transcribe(config, audio, fetcher = fetch, { oneVoice = false } = {}) {
120
130
  if (!config) throw new Refusal(503, 'No speech-to-text engine is configured.');
121
131
  if (audio.length === 0) throw new Refusal(400, 'The recording is empty.');
122
132
  if (audio.length > AUDIO_MAX) throw new Refusal(413, 'The recording is too long.');
@@ -132,7 +142,9 @@ export async function transcribe(config, audio, fetcher = fetch) {
132
142
  form.append('file', new Blob([audio], { type: 'audio/wav' }), 'dictation.wav');
133
143
  form.append('model', config.model);
134
144
  if (config.language) form.append('language', config.language);
135
- form.append('response_format', 'json');
145
+ const diarize = oneVoice && DIARIZES.test(String(config.url));
146
+ form.append('response_format', diarize ? 'verbose_json' : 'json');
147
+ if (diarize) form.append('diarize', 'true');
136
148
  if (withTemperature) form.append('temperature', '0');
137
149
  return fetcher(config.url, { method: 'POST', redirect: 'error', headers: config.key ? { authorization: `Bearer ${config.key}` } : {}, body: form, signal: AbortSignal.timeout(TIMEOUT_MS) });
138
150
  };
@@ -152,7 +164,7 @@ export async function transcribe(config, audio, fetcher = fetch) {
152
164
  if (!response.ok) throw new Refusal(502, `The speech-to-text engine answered ${response.status}.`);
153
165
  const body = await response.json().catch(() => undefined);
154
166
  if (typeof body?.text !== 'string') throw new Refusal(502, 'The speech-to-text engine gave no text.');
155
- return cleanDictation(body.text, wavSeconds(audio));
167
+ return cleanDictation((oneVoice && firstVoice(body)) || body.text, wavSeconds(audio));
156
168
  }
157
169
 
158
170
  /* ---------- THE ENGINE CHOSEN IN SETTINGS ----------
@@ -288,11 +300,11 @@ export class Dictation {
288
300
  /* An expired key is never sent: said in one line instead (still offered, so the line is seen). */
289
301
  #fresh(c) { if (c?.secret && this.#expired(c.secret)) throw new Refusal(409, KEY_EXPIRED); }
290
302
  /* `device`: the language of the device that dictates (a tag such as fr-FR), if it said. */
291
- async transcribe(audio, device) {
303
+ async transcribe(audio, device, how = {}) {
292
304
  this.#fresh(this.#saved());
293
305
  const config = this.current();
294
306
  if (config) await this.#guard(config);
295
- return transcribe(config && { ...config, language: languageOf(config.language, device) }, audio, this.#fetcher);
307
+ return transcribe(config && { ...config, language: languageOf(config.language, device) }, audio, this.#fetcher, how);
296
308
  }
297
309
  /* "Try it": what is in the form, not saved, on one short recording. */
298
310
  async try(body, audio, device) {