clavarium 0.2.313-next.1 → 0.2.314-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 +6 -6
- package/package.json +2 -2
- package/web/app.js +19 -1
- package/web/index.html +2 -2
- package/web/style.css +4 -0
- package/web/voice-core.js +25 -0
- package/web/voice.js +9 -3
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.314-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.314-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
|
13
13
|
"@xterm/xterm": "^6.0.0",
|
|
14
14
|
"clavarium-binder": "0.1.60-next.1",
|
|
15
15
|
"clavarium-docket": "0.1.2-next.2",
|
|
16
|
-
"clavarium-parley": "0.17.
|
|
16
|
+
"clavarium-parley": "0.17.65-next.1",
|
|
17
17
|
"clavarium-tether": "0.1.0-next.49",
|
|
18
18
|
"mammoth": "1.13.0",
|
|
19
19
|
"mermaid": "11.17.2",
|
|
@@ -787,9 +787,9 @@
|
|
|
787
787
|
}
|
|
788
788
|
},
|
|
789
789
|
"node_modules/clavarium-parley": {
|
|
790
|
-
"version": "0.17.
|
|
791
|
-
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.
|
|
792
|
-
"integrity": "sha512-
|
|
790
|
+
"version": "0.17.65-next.1",
|
|
791
|
+
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.65-next.1.tgz",
|
|
792
|
+
"integrity": "sha512-EZVq6df0eRWdrOC4yoFstBIahevIdFFOXpXa5PQBM8yol//V1sOgerr2Zk2INYKxY8T4bIBqsU5wCbloRtyjfQ==",
|
|
793
793
|
"license": "MIT",
|
|
794
794
|
"bin": {
|
|
795
795
|
"parley": "bin/parley.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.314-next.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.",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@xterm/xterm": "^6.0.0",
|
|
47
47
|
"clavarium-binder": "0.1.60-next.1",
|
|
48
48
|
"clavarium-docket": "0.1.2-next.2",
|
|
49
|
-
"clavarium-parley": "0.17.
|
|
49
|
+
"clavarium-parley": "0.17.65-next.1",
|
|
50
50
|
"clavarium-tether": "0.1.0-next.49",
|
|
51
51
|
"mammoth": "1.13.0",
|
|
52
52
|
"mermaid": "11.17.2",
|
package/web/app.js
CHANGED
|
@@ -6205,7 +6205,24 @@
|
|
|
6205
6205
|
});
|
|
6206
6206
|
/* "Try it", per engine: a few seconds from this microphone, sent to the engine in its card (nothing saved). */
|
|
6207
6207
|
let stopTrying = null;
|
|
6208
|
-
|
|
6208
|
+
/* How loud the microphone is, in five thin bars beside what it says (voice.js: on.level): drawn once a
|
|
6209
|
+
frame; it rises at once and falls slowly. Decorative: the words say the state. */
|
|
6210
|
+
let tryLevels = []; let tryFrame = null;
|
|
6211
|
+
const tryLevel = (slot, n) => {
|
|
6212
|
+
if (!stopTrying || !window.clavariumVoice?.levelBars) return;
|
|
6213
|
+
tryLevels = [Math.max(n, (tryLevels[0] ?? 0) * 0.8), ...tryLevels].slice(0, 3);
|
|
6214
|
+
dq(slot, 'level').hidden = false;
|
|
6215
|
+
tryFrame ??= requestAnimationFrame(() => {
|
|
6216
|
+
tryFrame = null;
|
|
6217
|
+
if (!stopTrying) return;
|
|
6218
|
+
const bars = dq(slot, 'level').children;
|
|
6219
|
+
window.clavariumVoice.levelBars(tryLevels).forEach((h, i) => { if (bars[i]) bars[i].style.transform = `scaleY(${h})`; });
|
|
6220
|
+
});
|
|
6221
|
+
};
|
|
6222
|
+
const endTry = () => {
|
|
6223
|
+
stopTrying?.(); stopTrying = null; tryLevels = [];
|
|
6224
|
+
for (const slot of ['main', 'backup']) { dq(slot, 'try').textContent = 'Try it'; dq(slot, 'level').hidden = true; for (const bar of dq(slot, 'level').children) bar.style.transform = ''; }
|
|
6225
|
+
};
|
|
6209
6226
|
for (const slot of ['main', 'backup']) dq(slot, 'try').addEventListener('click', async () => {
|
|
6210
6227
|
if (stopTrying) { endTry(); return; }
|
|
6211
6228
|
dictationSay(null);
|
|
@@ -6220,6 +6237,7 @@
|
|
|
6220
6237
|
let spoke = began;
|
|
6221
6238
|
const stop = await window.clavariumVoice.listen({
|
|
6222
6239
|
state: (w) => { if (w === 'transcribing') spoke = Date.now(); if (stopTrying) heard.textContent = words[w] ?? w; },
|
|
6240
|
+
level: (n) => tryLevel(slot, n),
|
|
6223
6241
|
phrase: (text) => { endTry(); heard.textContent = `Heard: ${text}`; heard.title = `${((Date.now() - spoke) / 1000).toFixed(1)} s`; },
|
|
6224
6242
|
error: (message) => { endTry(); heard.hidden = true; dictationSay(message); },
|
|
6225
6243
|
}, { to });
|
package/web/index.html
CHANGED
|
@@ -924,7 +924,7 @@
|
|
|
924
924
|
<div class="set-row" id="dictation-secret-row"><div class="set-what"><label for="dictation-secret">Key</label><small>One of your secrets. Never shown</small></div><div class="set-control"><select id="dictation-secret"><option value="">No key</option></select></div></div>
|
|
925
925
|
<div class="set-row" id="dictation-newkey" hidden><div class="set-what"><label for="dictation-newkey-value">New key</label><small id="dictation-newkey-name"></small></div><div class="set-control"><input id="dictation-newkey-value" type="password" autocomplete="off" spellcheck="false" placeholder="Paste the key"><button type="button" class="primary" id="dictation-newkey-keep">Keep in secrets</button></div></div>
|
|
926
926
|
<p class="hint" id="dictation-other-hint" hidden>Any engine with the same interface (<code>/v1/audio/transcriptions</code>); it alone may be on this server's own network.</p>
|
|
927
|
-
<div class="action-row"><span class="hint" id="dictation-heard" role="status" hidden></span><button type="button" id="dictation-try" data-slot="main">Try it</button></div>
|
|
927
|
+
<div class="action-row"><span class="voice-level" id="dictation-level" aria-hidden="true" hidden><i></i><i></i><i></i><i></i><i></i></span><span class="hint" id="dictation-heard" role="status" hidden></span><button type="button" id="dictation-try" data-slot="main">Try it</button></div>
|
|
928
928
|
</div>
|
|
929
929
|
<div class="set-rows set-card dict-engine" id="dictation-backup-card" data-slot="backup">
|
|
930
930
|
<div class="dict-head"><span class="dict-dot" id="dictation-backup-dot"></span><b>Backup</b><small>if the main one is down</small></div>
|
|
@@ -934,7 +934,7 @@
|
|
|
934
934
|
<div class="set-row" id="dictation-backup-secret-row"><div class="set-what"><label for="dictation-backup-secret">Key</label><small>One of your secrets. Never shown</small></div><div class="set-control"><select id="dictation-backup-secret"><option value="">No key</option></select></div></div>
|
|
935
935
|
<div class="set-row" id="dictation-backup-newkey" hidden><div class="set-what"><label for="dictation-backup-newkey-value">New key</label><small id="dictation-backup-newkey-name"></small></div><div class="set-control"><input id="dictation-backup-newkey-value" type="password" autocomplete="off" spellcheck="false" placeholder="Paste the key"><button type="button" class="primary" id="dictation-backup-newkey-keep">Keep in secrets</button></div></div>
|
|
936
936
|
<p class="hint" id="dictation-backup-other-hint" hidden>Any engine with the same interface (<code>/v1/audio/transcriptions</code>); it alone may be on this server's own network.</p>
|
|
937
|
-
<div class="action-row"><span class="hint" id="dictation-backup-heard" role="status" hidden></span><button type="button" id="dictation-backup-try" data-slot="backup">Try it</button></div>
|
|
937
|
+
<div class="action-row"><span class="voice-level" id="dictation-backup-level" aria-hidden="true" hidden><i></i><i></i><i></i><i></i><i></i></span><span class="hint" id="dictation-backup-heard" role="status" hidden></span><button type="button" id="dictation-backup-try" data-slot="backup">Try it</button></div>
|
|
938
938
|
</div>
|
|
939
939
|
<div class="set-rows set-card">
|
|
940
940
|
<div class="set-row"><div class="set-what"><label for="dictation-language">Language</label></div><div class="set-control"><select id="dictation-language"><option value="">Each device's</option><option value="auto">Automatic</option><option value="en">English (en)</option><option value="fr">French (fr)</option><option value="de">German (de)</option><option value="es">Spanish (es)</option><option value="it">Italian (it)</option><option value="nl">Dutch (nl)</option><option value="pt">Portuguese (pt)</option><option value="other">Another code...</option></select><input id="dictation-language-code" maxlength="8" spellcheck="false" placeholder="code, such as pl" aria-label="Language code" hidden></div></div>
|
package/web/style.css
CHANGED
|
@@ -1735,6 +1735,10 @@ button.inline.more-recent { text-decoration: none; }
|
|
|
1735
1735
|
@media (max-width: 560px) { .set-row { grid-template-columns: minmax(0, 1fr); } .set-row > .set-control { justify-content: flex-start; } .set-row > .set-control > :is(input, select) { width: 100%; } }
|
|
1736
1736
|
.action-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
|
|
1737
1737
|
.action-row > [role=status] { margin-right: auto; }
|
|
1738
|
+
/* Dictation's "Try it": five thin bars that follow how loud the microphone is (app.js, tryLevel). */
|
|
1739
|
+
.voice-level { display: inline-flex; align-items: center; gap: 2px; height: 14px; color: var(--ok); }
|
|
1740
|
+
.voice-level i { display: block; width: 3px; height: 100%; border-radius: 2px; background: currentColor; transform: scaleY(.2); transition: transform 90ms linear; }
|
|
1741
|
+
@media (prefers-reduced-motion: reduce) { .voice-level i { transform: scaleY(.2) !important; transition: none; } }
|
|
1738
1742
|
/* Settings > Dictation: two engines, main and backup, each its card. */
|
|
1739
1743
|
.dict-form { display: flex; flex-direction: column; gap: 12px; }
|
|
1740
1744
|
.dict-form > .set-rows { display: flex; flex-direction: column; }
|
package/web/voice-core.js
CHANGED
|
@@ -32,6 +32,31 @@ export function loudness(samples) {
|
|
|
32
32
|
return Number.isFinite(rms) ? rms : 0;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/* HOW LOUD, TO DRAW: the loudness of a block as a level from 0 to 1 that an eye reads as a voice reads to
|
|
36
|
+
an ear, in decibels: a quiet room (-60 dB and below) is 0, a near shout (-12 dB) is 1. */
|
|
37
|
+
export const LEVEL_QUIET_DB = -60;
|
|
38
|
+
export const LEVEL_LOUD_DB = -12;
|
|
39
|
+
export function levelOf(rms) {
|
|
40
|
+
if (typeof rms !== 'number' || !Number.isFinite(rms) || rms <= 0) return 0;
|
|
41
|
+
const db = 20 * Math.log10(rms);
|
|
42
|
+
return Math.round(Math.min(1, Math.max(0, (db - LEVEL_QUIET_DB) / (LEVEL_LOUD_DB - LEVEL_QUIET_DB))) * 100) / 100;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* The same level as the heights of a few thin bars (a share of their full height), as Parley draws it: the
|
|
46
|
+
newest level in the middle, the ones before towards the sides, lower there; a dot when quiet. */
|
|
47
|
+
export const LEVEL_BARS = 5;
|
|
48
|
+
export const LEVEL_DOT = 0.2;
|
|
49
|
+
export function levelBars(recent, n = LEVEL_BARS) {
|
|
50
|
+
const levels = (Array.isArray(recent) ? recent : [recent]).map((v) => (Number.isFinite(v) ? Math.min(1, Math.max(0, v)) : 0));
|
|
51
|
+
const middle = (n - 1) / 2;
|
|
52
|
+
return Array.from({ length: n }, (_, i) => {
|
|
53
|
+
const away = Math.abs(i - middle);
|
|
54
|
+
const level = levels[Math.round(away)] ?? levels.at(-1) ?? 0;
|
|
55
|
+
const shape = middle > 0 ? 1 - 0.4 * (away / middle) : 1;
|
|
56
|
+
return Math.round((LEVEL_DOT + (1 - LEVEL_DOT) * level * shape) * 100) / 100;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
35
60
|
/* THE THRESHOLD FOLLOWS THE ROOM. An absolute threshold measures the world;
|
|
36
61
|
what matters is what rises above the noise HERE. The floor is a low
|
|
37
62
|
quantile of the last thirty seconds; speech is three times the floor. */
|
package/web/voice.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* DICTATION IN THE PAGE: the microphone stays open, each spoken phrase is
|
|
2
2
|
transcribed and handed to whoever listens. The page types it into the
|
|
3
3
|
terminal. See voice-core.js for how a phrase is found. */
|
|
4
|
-
import { RATE, BLOCK, BLOCK_MS, Detector, Segmenter, loudness, toWav } from './voice-core.js';
|
|
4
|
+
import { RATE, BLOCK, BLOCK_MS, Detector, Segmenter, loudness, levelOf, levelBars, toWav } from './voice-core.js';
|
|
5
5
|
|
|
6
6
|
/* The operator's pages ask /api; a paired device asks /c/api/<its pairing>,
|
|
7
7
|
known once it has signed in (the page writes it on the document). */
|
|
@@ -16,7 +16,9 @@ const withLanguage = (to) => {
|
|
|
16
16
|
|
|
17
17
|
/* Opens the microphone; resolves with a function that closes it.
|
|
18
18
|
`on.phrase(text)`, `on.state(word)`: calibrating, listening, hearing,
|
|
19
|
-
transcribing; `on.error(message)
|
|
19
|
+
transcribing; `on.error(message)`; `on.level(n)`, if given: how loud the
|
|
20
|
+
microphone is, 0 to 1, each block (about 30 times a second), measured on
|
|
21
|
+
the same stream (no second microphone) for a few bars to follow. `to`: where phrases go, if not the
|
|
20
22
|
usual engine (Settings' "Try it" sends them to the one in its form). */
|
|
21
23
|
async function listen(on, { to } = {}) {
|
|
22
24
|
const stream = await navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: false, autoGainControl: false } });
|
|
@@ -44,7 +46,9 @@ async function listen(on, { to } = {}) {
|
|
|
44
46
|
node.onaudioprocess = (event) => {
|
|
45
47
|
const samples = Float32Array.from(event.inputBuffer.getChannelData(0));
|
|
46
48
|
const was = segmenter.speaking;
|
|
47
|
-
|
|
49
|
+
const rms = loudness(samples);
|
|
50
|
+
segmenter.feed(detector.hear(rms), count++ * BLOCK_MS, samples);
|
|
51
|
+
if (!closed) { try { on.level?.(levelOf(rms)); } catch { /* a drawing never stops the dictation */ } }
|
|
48
52
|
if (was !== segmenter.speaking || count === 33) tell();
|
|
49
53
|
};
|
|
50
54
|
source.connect(node); node.connect(context.destination);
|
|
@@ -60,5 +64,7 @@ async function listen(on, { to } = {}) {
|
|
|
60
64
|
window.clavariumVoice = {
|
|
61
65
|
available: async () => { try { const r = await fetch(`${api()}/voice`); return r.ok && (await r.json()).available === true; } catch { return false; } },
|
|
62
66
|
listen,
|
|
67
|
+
/* The heights of the bars that show how loud it is (Settings' "Try it" draws them). */
|
|
68
|
+
levelBars,
|
|
63
69
|
};
|
|
64
70
|
window.dispatchEvent(new Event('clavarium-voice-ready'));
|