shadok-ai 0.20.35 → 0.20.36
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/README.md +3 -1
- package/package.json +1 -1
- package/public/index.html +22 -6
- package/public/live-dictation.js +21 -3
package/README.md
CHANGED
|
@@ -355,7 +355,9 @@ Enter to skip; you can add it later from the web UI).
|
|
|
355
355
|
browser's maker. To keep it on your server, an admin picks version menu →
|
|
356
356
|
*Web dictation* → *On this server (whisper)*: the clip is transcribed by the
|
|
357
357
|
local model, after a wait. Other browsers and Telegram/WhatsApp voice notes
|
|
358
|
-
always use the local model
|
|
358
|
+
always use the local model, and so does a browser whose recogniser fails
|
|
359
|
+
(a network that cannot reach its speech service, say): the same click
|
|
360
|
+
switches to recording for the server, and says so.
|
|
359
361
|
- **Dictate a prompt on the web** — a 🎙 button beside *Send* records your
|
|
360
362
|
microphone and transcribes it with the **same local whisper.cpp** the voice
|
|
361
363
|
notes use (nothing leaves the machine). The text drops into the composer
|
package/package.json
CHANGED
package/public/index.html
CHANGED
|
@@ -13082,7 +13082,7 @@
|
|
|
13082
13082
|
const cur = promptInput.value;
|
|
13083
13083
|
const at = promptInput.selectionStart ?? cur.length;
|
|
13084
13084
|
const before = cur.slice(0, at), after = cur.slice(promptInput.selectionEnd ?? at);
|
|
13085
|
-
let heard = false;
|
|
13085
|
+
let heard = false, lastError = null;
|
|
13086
13086
|
rec.onresult = (e) => {
|
|
13087
13087
|
if (liveRec !== rec) return;
|
|
13088
13088
|
const t = ld.liveTranscript(Array.from(e.results, (r) => ({ final: r.isFinal, text: r[0] ? r[0].transcript : "" })));
|
|
@@ -13095,18 +13095,31 @@
|
|
|
13095
13095
|
autosizePrompt();
|
|
13096
13096
|
updateSendDisabled();
|
|
13097
13097
|
};
|
|
13098
|
+
// The verdict waits for `end`, which always follows an `error`: that is
|
|
13099
|
+
// where a recogniser that failed WITHOUT naming an error shows up too.
|
|
13098
13100
|
rec.onerror = (e) => {
|
|
13099
13101
|
if (liveRec !== rec) return;
|
|
13100
|
-
|
|
13101
|
-
//
|
|
13102
|
-
|
|
13103
|
-
if (f.fallback) liveBroken = true;
|
|
13104
|
-
if (f.message && !(e.error === "no-speech" && heard)) micMsg(f.message);
|
|
13102
|
+
lastError = e.error || "unknown";
|
|
13103
|
+
// Kept in the console: the one trace there is when a browser refuses.
|
|
13104
|
+
console.warn("live dictation: recogniser error", lastError);
|
|
13105
13105
|
};
|
|
13106
13106
|
rec.onend = () => {
|
|
13107
13107
|
if (liveRec !== rec) return;
|
|
13108
|
+
const f = ld.recognitionEnd({ requested: rec.shadokStopRequested === true, heard, error: lastError });
|
|
13108
13109
|
liveRec = null;
|
|
13109
13110
|
endRecordingUI();
|
|
13111
|
+
if (f.fallback) {
|
|
13112
|
+
// A recogniser that refuses here will refuse again: record for the
|
|
13113
|
+
// server now, in the same click, rather than leave the person to
|
|
13114
|
+
// guess that a second one would work.
|
|
13115
|
+
liveBroken = true;
|
|
13116
|
+
if (!lastError) console.warn("live dictation: recogniser ended with no result and no error");
|
|
13117
|
+
// Said only once the recording runs: a refused microphone keeps
|
|
13118
|
+
// startRecording's own message.
|
|
13119
|
+
startRecording().then(() => { if (micRec) micMsg(f.message); });
|
|
13120
|
+
return;
|
|
13121
|
+
}
|
|
13122
|
+
if (f.message && !(lastError === "no-speech" && heard)) micMsg(f.message);
|
|
13110
13123
|
promptInput.focus();
|
|
13111
13124
|
};
|
|
13112
13125
|
try { rec.start(); } catch { liveBroken = true; return startRecording(); }
|
|
@@ -13132,6 +13145,9 @@
|
|
|
13132
13145
|
endRecordingUI();
|
|
13133
13146
|
try { rec.abort(); } catch { /* already over */ }
|
|
13134
13147
|
} else {
|
|
13148
|
+
// Asked to finish: an end with nothing heard is then the person's own
|
|
13149
|
+
// stop, not a recogniser that gave up (`recognitionEnd`).
|
|
13150
|
+
rec.shadokStopRequested = true;
|
|
13135
13151
|
try { rec.stop(); } catch { /* already over: onend clears the button */ }
|
|
13136
13152
|
}
|
|
13137
13153
|
}
|
package/public/live-dictation.js
CHANGED
|
@@ -62,8 +62,9 @@ export function spliceDictation(before, spoken, after) {
|
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* What a recognition error means for the person. `message` is shown (null: say
|
|
65
|
-
* nothing); `fallback` means the browser cannot do this at all here — the
|
|
66
|
-
*
|
|
65
|
+
* nothing); `fallback` means the browser cannot do this at all here — the page
|
|
66
|
+
* records for the server at once, and every later click does too, instead of
|
|
67
|
+
* failing the same way again.
|
|
67
68
|
*/
|
|
68
69
|
export function recognitionFailure(error) {
|
|
69
70
|
switch (error) {
|
|
@@ -74,6 +75,23 @@ export function recognitionFailure(error) {
|
|
|
74
75
|
default:
|
|
75
76
|
// network, service-not-allowed, language-not-supported, or a name this
|
|
76
77
|
// list does not know: the recogniser is not usable in this browser.
|
|
77
|
-
return { message:
|
|
78
|
+
return { message: FALLBACK_MESSAGE, fallback: true };
|
|
78
79
|
}
|
|
79
80
|
}
|
|
81
|
+
|
|
82
|
+
const FALLBACK_MESSAGE = "Browser dictation is unavailable here — recording for the server instead, speak again";
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* What a recogniser that ENDED means, once its error (if any) is known. Most
|
|
86
|
+
* failures name themselves through `error`; this adds the one that does not.
|
|
87
|
+
* A recogniser that stops by itself having produced nothing and reported no
|
|
88
|
+
* error is just as unusable as one saying `network` — nothing obliges a browser
|
|
89
|
+
* to name its failure — and, read as "nothing to report", it left the button
|
|
90
|
+
* blinking back to idle with not a word said: the shape a person reports as
|
|
91
|
+
* "it does not work".
|
|
92
|
+
*/
|
|
93
|
+
export function recognitionEnd({ requested, heard, error }) {
|
|
94
|
+
if (error) return recognitionFailure(error);
|
|
95
|
+
if (requested || heard) return { message: null, fallback: false };
|
|
96
|
+
return { message: FALLBACK_MESSAGE, fallback: true };
|
|
97
|
+
}
|