clavarium 0.2.109-beta.1 → 0.2.110-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/main.mjs +1 -1
- package/server/speech.mjs +25 -3
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.110-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.110-beta.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/main.mjs
CHANGED
|
@@ -602,7 +602,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
602
602
|
void team.refresh().catch((error) => console.error(`operators: ${error.message}`));
|
|
603
603
|
const watching = setInterval(() => { void team.watch().catch(() => {}); }, 60_000); watching.unref?.();
|
|
604
604
|
}
|
|
605
|
-
const speech = new Speech({ dir: `${dataDir}/voices`, log: (line) => events.add({ kind: 'server', text: line }) });
|
|
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
608
|
hear: (wav) => voice.transcribe(wav),
|
package/server/speech.mjs
CHANGED
|
@@ -35,11 +35,31 @@ export function toPcm16k(samples, from) {
|
|
|
35
35
|
return out;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/* A NICER VOICE, ONLINE: ElevenLabs, when the owner put its key among the secrets (by this name).
|
|
39
|
+
The text then leaves this server for theirs; without the key, or when it fails (quota, network),
|
|
40
|
+
the voice of this server answers instead. The voice: chosen by ear on the real box (31-10). */
|
|
41
|
+
export const ELEVEN_SECRET = 'ELEVENLABS_API_KEY';
|
|
42
|
+
export const ELEVEN_VOICE = 'onwK4e9ZLuTAKqWW03F9'; /* "Daniel" */
|
|
43
|
+
export const ELEVEN_MODEL = 'eleven_multilingual_v2';
|
|
44
|
+
|
|
38
45
|
export class Speech {
|
|
39
|
-
#dir; #lang; #engine = null; #loading = null; #fetch; #log;
|
|
46
|
+
#dir; #lang; #engine = null; #loading = null; #fetch; #log; #secret;
|
|
47
|
+
|
|
48
|
+
constructor({ dir, lang = 'fr', fetcher = fetch, log = () => {}, secret = () => undefined }) {
|
|
49
|
+
this.#dir = dir; this.#lang = VOICES[lang] ? lang : 'fr'; this.#fetch = fetcher; this.#log = log; this.#secret = secret;
|
|
50
|
+
}
|
|
40
51
|
|
|
41
|
-
|
|
42
|
-
|
|
52
|
+
async #eleven(text) {
|
|
53
|
+
const key = this.#secret(ELEVEN_SECRET);
|
|
54
|
+
if (!key) return null;
|
|
55
|
+
try {
|
|
56
|
+
const r = await this.#fetch(`https://api.elevenlabs.io/v1/text-to-speech/${ELEVEN_VOICE}?output_format=pcm_16000`, {
|
|
57
|
+
method: 'POST', headers: { 'xi-api-key': key, 'content-type': 'application/json' },
|
|
58
|
+
body: JSON.stringify({ text, model_id: ELEVEN_MODEL }), signal: AbortSignal.timeout(20_000),
|
|
59
|
+
});
|
|
60
|
+
if (!r.ok) { this.#log(`speech: ElevenLabs answered ${r.status}, this server's voice instead`); return null; }
|
|
61
|
+
return Buffer.from(await r.arrayBuffer());
|
|
62
|
+
} catch (error) { this.#log(`speech: ElevenLabs unreachable (${error.message}), this server's voice instead`); return null; }
|
|
43
63
|
}
|
|
44
64
|
|
|
45
65
|
get voice() { return VOICES[this.#lang]; }
|
|
@@ -81,6 +101,8 @@ export class Speech {
|
|
|
81
101
|
|
|
82
102
|
/* Text -> PCM 16 kHz. */
|
|
83
103
|
async speak(text) {
|
|
104
|
+
const online = await this.#eleven(text);
|
|
105
|
+
if (online && online.length) return online;
|
|
84
106
|
const engine = await this.#load();
|
|
85
107
|
const audio = engine.generate({ text, sid: 0, speed: 1.0 });
|
|
86
108
|
return toPcm16k(audio.samples, audio.sampleRate);
|