@bojackduy/opencode-voice 0.11.2 → 0.11.3
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 +6 -4
- package/index.js +1 -1
- package/lib/streaming-stt.js +20 -0
- package/lib/stt-log.js +39 -0
- package/lib/stt.js +221 -19
- package/lib/tts-player.js +356 -0
- package/lib/tts-status.js +266 -0
- package/lib/tts.js +661 -170
- package/lib/v2-compat.js +19 -0
- package/lib/v2-preview.js +141 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -96,7 +96,8 @@ capability detection already picks the right path per host.
|
|
|
96
96
|
in that dialog instead of being sent as a prompt.
|
|
97
97
|
- **STT (streaming dictation):** enable with `"sttMode": "streaming"` in plugin
|
|
98
98
|
options. Local whisper streaming displays a bounded live transcript above
|
|
99
|
-
the prompt footer on home and session screens
|
|
99
|
+
the prompt footer on home and session screens, with the live input waveform
|
|
100
|
+
beside it. Stable words are plain;
|
|
100
101
|
the tentative tail is bracketed and may change. Press the record key again
|
|
101
102
|
to finalize: the full text is inserted once at the focused cursor (and
|
|
102
103
|
submitted when `sttAutoSubmit` is set), or cancel to clear the preview
|
|
@@ -767,9 +768,10 @@ there is never a silent gap — `Loading speech model…` during cold start,
|
|
|
767
768
|
`● Streaming dictation — listening` with an elapsed timer while live
|
|
768
769
|
(plus a `(listening…)` note when inference runs slow), and `Finalizing…`
|
|
769
770
|
between the second keypress and finalization. On v2, a bounded transcript
|
|
770
|
-
above the prompt footer updates during recording
|
|
771
|
-
|
|
772
|
-
the focused cursor; cancel clears
|
|
771
|
+
above the prompt footer updates during recording, with the live input
|
|
772
|
+
waveform beside it: stable words are plain, tentative words are bracketed.
|
|
773
|
+
Finalization inserts the full text once at the focused cursor; cancel clears
|
|
774
|
+
the preview without sending.
|
|
773
775
|
The OpenCode renderer only
|
|
774
776
|
exposes `insertText`/`submit`, with no live range-replacement API, so
|
|
775
777
|
partials render as preview toasts (`🎙 ...`) alongside (not instead of)
|
package/index.js
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
// /stt-mic - select microphone
|
|
27
27
|
// /tts-speak - read last response aloud (default: <leader>] = ctrl+x, ])
|
|
28
28
|
// /tts-mode - toggle auto TTS on/off (palette-only)
|
|
29
|
-
// /tts-stop - stop playback
|
|
29
|
+
// /tts-stop - stop playback (palette-only; global <leader>. already stops TTS)
|
|
30
30
|
// /tts-voice - select TTS voice
|
|
31
31
|
// /voice-conversation - toggle hands-free voice conversation (default: <leader>v = ctrl+x, v)
|
|
32
32
|
// /voice-conversation-stop - exit voice conversation mode (palette-only)
|
package/lib/streaming-stt.js
CHANGED
|
@@ -436,6 +436,16 @@ export function createSoxRollingCapture({
|
|
|
436
436
|
});
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
+
// Cheap tail read for live level meters: copies only the requested bytes
|
|
440
|
+
// (no WAV wrap, no snapshot sequence bookkeeping). Returns empty when the
|
|
441
|
+
// capture has no audio yet.
|
|
442
|
+
function peekTail(nBytes = 2048) {
|
|
443
|
+
const want = Math.max(0, Math.min(Math.floor(Number(nBytes) || 0), capacityBytes));
|
|
444
|
+
if (want === 0) return null;
|
|
445
|
+
const pcm = ring.snapshotLast(want);
|
|
446
|
+
return pcm.length > 0 ? pcm : null;
|
|
447
|
+
}
|
|
448
|
+
|
|
439
449
|
function snapshot() {
|
|
440
450
|
const pcm = ring.snapshotLast(Math.ceil((windowMs / 1000) * STREAMING_DEFAULTS.bytesPerSecond));
|
|
441
451
|
if (pcm.length === 0) return null;
|
|
@@ -551,6 +561,7 @@ export function createSoxRollingCapture({
|
|
|
551
561
|
return {
|
|
552
562
|
start,
|
|
553
563
|
snapshot,
|
|
564
|
+
peekTail,
|
|
554
565
|
stopFinal,
|
|
555
566
|
cancel,
|
|
556
567
|
dispose,
|
|
@@ -1316,6 +1327,15 @@ export function createStreamingController({
|
|
|
1316
1327
|
getState,
|
|
1317
1328
|
getServerPort,
|
|
1318
1329
|
getTranscript: currentTranscript,
|
|
1330
|
+
// Live level meter source: newest PCM tail (16-bit mono). Null when the
|
|
1331
|
+
// capture is gone or has no audio yet; never throws.
|
|
1332
|
+
peekPcm: (nBytes) => {
|
|
1333
|
+
try {
|
|
1334
|
+
return capture?.peekTail?.(nBytes) || null;
|
|
1335
|
+
} catch {
|
|
1336
|
+
return null;
|
|
1337
|
+
}
|
|
1338
|
+
},
|
|
1319
1339
|
getFallbackAudio: () => fallbackAudio,
|
|
1320
1340
|
getFallbackCoverage: () => fallbackCoverage,
|
|
1321
1341
|
};
|
package/lib/stt-log.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Local file log for STT/streaming diagnosis (user-requested).
|
|
2
|
+
//
|
|
3
|
+
// Why this exists: v2 toasts are one-shot and the slot preview's fate is
|
|
4
|
+
// invisible from the UI. This log records which branch ran (batch vs
|
|
5
|
+
// streaming), what the preview did, and toast emissions, so the next
|
|
6
|
+
// recording answers "what happened" without guessing.
|
|
7
|
+
//
|
|
8
|
+
// Privacy: local /tmp only, never shipped. Free text (partials, messages)
|
|
9
|
+
// is truncated to 120 chars; options/endpoints/keys are never logged.
|
|
10
|
+
// Disable with OPENCODE_VOICE_DEBUG_LOG=0. Rotates at ~512KB.
|
|
11
|
+
import fs from "node:fs";
|
|
12
|
+
|
|
13
|
+
const LOG_PATH = "/tmp/opencode-voice-stt.log";
|
|
14
|
+
const MAX_BYTES = 512 * 1024;
|
|
15
|
+
const MAX_TEXT = 120;
|
|
16
|
+
|
|
17
|
+
function enabled() {
|
|
18
|
+
return process.env.OPENCODE_VOICE_DEBUG_LOG !== "0";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function trunc(value) {
|
|
22
|
+
const s = String(value ?? "");
|
|
23
|
+
return s.length > MAX_TEXT ? `${s.slice(0, MAX_TEXT)}…` : s;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function sttLog(event, details = "") {
|
|
27
|
+
if (!enabled()) return;
|
|
28
|
+
try {
|
|
29
|
+
let header = "";
|
|
30
|
+
try {
|
|
31
|
+
if (fs.statSync(LOG_PATH).size > MAX_BYTES) {
|
|
32
|
+
header = `--- rotated ${new Date().toISOString()} ---\n`;
|
|
33
|
+
fs.writeFileSync(LOG_PATH, header);
|
|
34
|
+
}
|
|
35
|
+
} catch {}
|
|
36
|
+
const line = `${new Date().toISOString()} pid=${process.pid} ${event}${details ? ` ${trunc(details)}` : ""}\n`;
|
|
37
|
+
fs.appendFileSync(LOG_PATH, header + line);
|
|
38
|
+
} catch {}
|
|
39
|
+
}
|
package/lib/stt.js
CHANGED
|
@@ -5,6 +5,7 @@ import path from "node:path";
|
|
|
5
5
|
import os from "node:os";
|
|
6
6
|
import { spawn, execSync } from "node:child_process";
|
|
7
7
|
import { getActiveSessionTitle, getRecentConversationContext } from "./session.js";
|
|
8
|
+
import { sttLog } from "./stt-log.js";
|
|
8
9
|
|
|
9
10
|
let sttApiEndpoint = null;
|
|
10
11
|
let sttApiModel = null;
|
|
@@ -337,10 +338,24 @@ export const STREAMING_MODE_DEFAULTS = {
|
|
|
337
338
|
cadenceMs: 1000,
|
|
338
339
|
};
|
|
339
340
|
|
|
340
|
-
export function resolveSttMode(opts) {
|
|
341
|
+
export function resolveSttMode(opts, kv = null) {
|
|
342
|
+
// kv wins when set: the v2 host has been observed delivering only a
|
|
343
|
+
// subset of file-plugin options, so a persisted choice must override.
|
|
344
|
+
try {
|
|
345
|
+
const saved = kv?.get("stt.mode");
|
|
346
|
+
if (saved === "streaming" || saved === "batch") return saved;
|
|
347
|
+
} catch {}
|
|
341
348
|
return opts?.sttMode === "streaming" ? "streaming" : "batch";
|
|
342
349
|
}
|
|
343
350
|
|
|
351
|
+
export function resolveSttAutoSubmit(opts, kv = null) {
|
|
352
|
+
try {
|
|
353
|
+
const saved = kv?.get("stt.autoSubmit");
|
|
354
|
+
if (saved === true || saved === false) return saved;
|
|
355
|
+
} catch {}
|
|
356
|
+
return opts?.sttAutoSubmit === true;
|
|
357
|
+
}
|
|
358
|
+
|
|
344
359
|
export function resolveStreamTimings(opts) {
|
|
345
360
|
const windowMs =
|
|
346
361
|
Number(opts?.sttStreamWindowMs) > 0
|
|
@@ -427,6 +442,14 @@ const WAVE_LEN = 16;
|
|
|
427
442
|
const WAVE_INTERVAL = 35;
|
|
428
443
|
const WAVE_DURATION = 70;
|
|
429
444
|
let useWave = true;
|
|
445
|
+
// v2's toast API has no update/replace: every call stacks as a new
|
|
446
|
+
// notification, so the v1 polling pattern becomes a toast storm. v2 shows
|
|
447
|
+
// live state in the slot preview instead and uses one-shot toasts.
|
|
448
|
+
let toastPolling = true;
|
|
449
|
+
|
|
450
|
+
export function __setToastPolling(v) {
|
|
451
|
+
toastPolling = !!v;
|
|
452
|
+
}
|
|
430
453
|
|
|
431
454
|
export function __setRecordingToastFn(fn) {
|
|
432
455
|
recordingToastFn = fn;
|
|
@@ -478,6 +501,7 @@ export function showProcessingToast(message) {
|
|
|
478
501
|
variant: "info",
|
|
479
502
|
duration: PROCESSING_TOAST_DURATION,
|
|
480
503
|
});
|
|
504
|
+
if (!toastPolling) return;
|
|
481
505
|
processingToastTimer = setInterval(() => {
|
|
482
506
|
if (processingToastFn) {
|
|
483
507
|
processingToastFn({
|
|
@@ -579,7 +603,9 @@ export function showStreamingToast(message, { slowAfterMs } = {}) {
|
|
|
579
603
|
streamingLastPartialMs = null;
|
|
580
604
|
if (Number(slowAfterMs) > 0) streamingSlowAfterMs = Math.floor(Number(slowAfterMs));
|
|
581
605
|
if (!streamingToastFn) return;
|
|
606
|
+
sttLog("toast.streaming", `base=${streamingToastBase} polling=${toastPolling}`);
|
|
582
607
|
emitStreamingToast();
|
|
608
|
+
if (!toastPolling) return;
|
|
583
609
|
streamingToastTimer = setInterval(() => {
|
|
584
610
|
emitStreamingToast();
|
|
585
611
|
}, STREAMING_TOAST_INTERVAL);
|
|
@@ -749,6 +775,63 @@ export function getWaveString() {
|
|
|
749
775
|
}
|
|
750
776
|
}
|
|
751
777
|
|
|
778
|
+
// ---- Streaming waveform (live transcript + wave) ----
|
|
779
|
+
// The batch meter samples a WAV file on disk; streaming keeps PCM in memory,
|
|
780
|
+
// so the controller exposes its newest tail instead. Same thresholds and
|
|
781
|
+
// noise-floor gating as the batch meter, with slightly slower decay because
|
|
782
|
+
// this samples at ~80 ms rather than ~35 ms.
|
|
783
|
+
|
|
784
|
+
const STREAM_WAVE_BYTES = 2560; // ~80 ms of 16 kHz mono 16-bit PCM
|
|
785
|
+
let streamWavePrev = [];
|
|
786
|
+
let streamNoiseFloor = null;
|
|
787
|
+
|
|
788
|
+
export function __resetStreamWave() {
|
|
789
|
+
streamWavePrev = [];
|
|
790
|
+
streamNoiseFloor = null;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
export function waveLevelsFromPcm(pcm) {
|
|
794
|
+
if (!pcm || pcm.length < 2) return Array(WAVE_LEN).fill(0);
|
|
795
|
+
const chunkBytes = Math.max(2, Math.floor(pcm.length / WAVE_LEN));
|
|
796
|
+
const raw = [];
|
|
797
|
+
for (let column = 0; column < WAVE_LEN; column++) {
|
|
798
|
+
const offset = column * chunkBytes;
|
|
799
|
+
if (offset >= pcm.length) {
|
|
800
|
+
raw.push(0);
|
|
801
|
+
continue;
|
|
802
|
+
}
|
|
803
|
+
const chunk = pcm.subarray(offset, Math.min(offset + chunkBytes, pcm.length));
|
|
804
|
+
const samples = Math.floor(chunk.length / 2);
|
|
805
|
+
if (samples === 0) {
|
|
806
|
+
raw.push(0);
|
|
807
|
+
continue;
|
|
808
|
+
}
|
|
809
|
+
let sum = 0;
|
|
810
|
+
for (let i = 0; i + 1 < chunk.length; i += 2) {
|
|
811
|
+
const sample = chunk.readInt16LE(i) / 32768;
|
|
812
|
+
sum += sample * sample;
|
|
813
|
+
}
|
|
814
|
+
raw.push(Math.sqrt(sum / samples));
|
|
815
|
+
}
|
|
816
|
+
const floor = Math.min(...raw);
|
|
817
|
+
if (streamNoiseFloor === null) streamNoiseFloor = floor;
|
|
818
|
+
else streamNoiseFloor = Math.min(streamNoiseFloor, floor) * 0.995 + floor * 0.005;
|
|
819
|
+
const levels = raw.map((rms) => {
|
|
820
|
+
const effective = Math.max(0, rms - streamNoiseFloor * 1.15);
|
|
821
|
+
if (effective < 0.005) return 0;
|
|
822
|
+
return rmsToLevel(effective * 1.6);
|
|
823
|
+
});
|
|
824
|
+
if (streamWavePrev.length !== WAVE_LEN) streamWavePrev = Array(WAVE_LEN).fill(0);
|
|
825
|
+
const smoothed = levels.map((level, index) => {
|
|
826
|
+
const prev = streamWavePrev[index] || 0;
|
|
827
|
+
if (level > prev) return level;
|
|
828
|
+
const decayed = Math.floor(prev * 0.35);
|
|
829
|
+
return level > decayed ? level : decayed;
|
|
830
|
+
});
|
|
831
|
+
streamWavePrev = smoothed;
|
|
832
|
+
return smoothed;
|
|
833
|
+
}
|
|
834
|
+
|
|
752
835
|
let currentRecordKeybind = "<leader>[";
|
|
753
836
|
export function __setRecordKeybind(kb) {
|
|
754
837
|
if (kb) currentRecordKeybind = kb.replace(/^<leader>/, "leader+");
|
|
@@ -767,10 +850,14 @@ export function __setStopHint(hint) {
|
|
|
767
850
|
savedRecordKeybind = null;
|
|
768
851
|
}
|
|
769
852
|
}
|
|
770
|
-
|
|
853
|
+
function recordingModeSuffix() {
|
|
771
854
|
// When the conversation loop overrides the stop hint, the toast says so
|
|
772
855
|
// explicitly - otherwise users wonder why it names a key they did not press.
|
|
773
|
-
|
|
856
|
+
return savedRecordKeybind !== null ? " (conversation)" : "";
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
export function buildRecordingMessage() {
|
|
860
|
+
const mode = recordingModeSuffix();
|
|
774
861
|
if (!useWave || recordingStartMs === null)
|
|
775
862
|
return `${RECORDING_TOAST_BASE}${mode} · ${currentRecordKeybind} to stop`;
|
|
776
863
|
const elapsed = formatElapsed(Date.now() - recordingStartMs);
|
|
@@ -781,10 +868,19 @@ export function buildRecordingMessage() {
|
|
|
781
868
|
export function showRecordingToast() {
|
|
782
869
|
clearRecordingToast();
|
|
783
870
|
if (!recordingToastFn) return;
|
|
871
|
+
sttLog("toast.recording", `polling=${toastPolling} wave=${useWave}`);
|
|
784
872
|
recordingStartMs = Date.now();
|
|
785
873
|
prevWaveLevels = Array(WAVE_LEN).fill(0);
|
|
786
874
|
noiseFloorRms = null;
|
|
787
875
|
calibrationEndMs = Date.now() + 120;
|
|
876
|
+
if (!toastPolling) {
|
|
877
|
+
recordingToastFn({
|
|
878
|
+
message: `${RECORDING_TOAST_BASE}${recordingModeSuffix()} · ${currentRecordKeybind} to stop`,
|
|
879
|
+
variant: "info",
|
|
880
|
+
duration: RECORDING_TOAST_DURATION,
|
|
881
|
+
});
|
|
882
|
+
return;
|
|
883
|
+
}
|
|
788
884
|
const interval = useWave ? WAVE_INTERVAL : RECORDING_TOAST_INTERVAL;
|
|
789
885
|
const duration = useWave ? WAVE_DURATION : RECORDING_TOAST_DURATION;
|
|
790
886
|
recordingToastFn({
|
|
@@ -1605,6 +1701,17 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1605
1701
|
const client = api.client;
|
|
1606
1702
|
const renderer = opts?.focusMode === "primary" ? null : api.renderer;
|
|
1607
1703
|
const preview = api.voicePreview;
|
|
1704
|
+
__setToastPolling(!preview);
|
|
1705
|
+
const bootMode = resolveSttMode(opts, kv);
|
|
1706
|
+
let modeSource = "default-batch";
|
|
1707
|
+
try {
|
|
1708
|
+
if (kv?.get("stt.mode") === bootMode) modeSource = "kv";
|
|
1709
|
+
else if (opts?.sttMode === bootMode) modeSource = "options";
|
|
1710
|
+
} catch {}
|
|
1711
|
+
sttLog(
|
|
1712
|
+
"register",
|
|
1713
|
+
`sttMode=${bootMode} source=${modeSource} preview=${preview ? "yes" : "no"} toastPolling=${!preview} optKeys=${Object.keys(opts || {}).join(",")}`,
|
|
1714
|
+
);
|
|
1608
1715
|
let streamGeneration = 0;
|
|
1609
1716
|
let streamDisposed = false;
|
|
1610
1717
|
let finalizingController = null;
|
|
@@ -1696,7 +1803,30 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1696
1803
|
}
|
|
1697
1804
|
|
|
1698
1805
|
// ---- Streaming dictation session (stage 2, local-only, no LLM) ----
|
|
1699
|
-
|
|
1806
|
+
// Mode/auto-submit resolve live from kv first: options seed kv on first
|
|
1807
|
+
// boot, then the /stt-mode and /stt-autosubmit commands own the runtime
|
|
1808
|
+
// value. This survives hosts that deliver partial plugin options.
|
|
1809
|
+
const seedKvFromOpts = () => {
|
|
1810
|
+
try {
|
|
1811
|
+
if (
|
|
1812
|
+
(opts?.sttMode === "streaming" || opts?.sttMode === "batch") &&
|
|
1813
|
+
kv.get("stt.mode") == null
|
|
1814
|
+
) {
|
|
1815
|
+
kv.set("stt.mode", opts.sttMode);
|
|
1816
|
+
}
|
|
1817
|
+
} catch {}
|
|
1818
|
+
try {
|
|
1819
|
+
if (opts?.sttAutoSubmit !== undefined && kv.get("stt.autoSubmit") == null) {
|
|
1820
|
+
kv.set("stt.autoSubmit", opts.sttAutoSubmit === true);
|
|
1821
|
+
}
|
|
1822
|
+
} catch {}
|
|
1823
|
+
};
|
|
1824
|
+
seedKvFromOpts();
|
|
1825
|
+
const currentSttMode = () => resolveSttMode(opts, kv);
|
|
1826
|
+
const sttAutoSubmitEnabled = () => resolveSttAutoSubmit(opts, kv);
|
|
1827
|
+
// Boot-time snapshot for the mode log line below; behavior branches call
|
|
1828
|
+
// currentSttMode() live so /stt-mode takes effect without a restart.
|
|
1829
|
+
const sttMode = currentSttMode();
|
|
1700
1830
|
const streamTimings = resolveStreamTimings(opts);
|
|
1701
1831
|
logger?.log(
|
|
1702
1832
|
"STT",
|
|
@@ -1797,6 +1927,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1797
1927
|
});
|
|
1798
1928
|
if (preview) await preview.begin();
|
|
1799
1929
|
else editor.begin(target);
|
|
1930
|
+
sttLog("stream.begin", `preview=${preview ? "yes" : "no"}`);
|
|
1800
1931
|
if (streamDisposed || myGen !== streamGeneration) {
|
|
1801
1932
|
preview?.clear();
|
|
1802
1933
|
return false;
|
|
@@ -1810,8 +1941,13 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1810
1941
|
try {
|
|
1811
1942
|
ed.applyPartial(p);
|
|
1812
1943
|
} catch {}
|
|
1944
|
+
sttLog(
|
|
1945
|
+
"stream.partial",
|
|
1946
|
+
`stable=${(p?.stableText || "").length} tentative=${(p?.tentativeText || "").length}`,
|
|
1947
|
+
);
|
|
1813
1948
|
},
|
|
1814
1949
|
onStateChange: (s) => {
|
|
1950
|
+
sttLog("stream.state", s);
|
|
1815
1951
|
try {
|
|
1816
1952
|
if (s === "streaming") {
|
|
1817
1953
|
updateStreamingToast("● Streaming dictation — listening");
|
|
@@ -1865,6 +2001,21 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1865
2001
|
return false;
|
|
1866
2002
|
}
|
|
1867
2003
|
__setStreamingActive(true);
|
|
2004
|
+
sttLog("stream.started", `reusedWarm=${reusedWarm}`);
|
|
2005
|
+
// Live waveform rides the v2 preview slot next to the live transcript.
|
|
2006
|
+
// v1 has no persistent preview surface; its batch wave is unchanged.
|
|
2007
|
+
if (preview) {
|
|
2008
|
+
__resetStreamWave();
|
|
2009
|
+
let pcmLogCount = 0;
|
|
2010
|
+
preview.startWave?.(() => {
|
|
2011
|
+
const pcm = controller.peekPcm?.(STREAM_WAVE_BYTES);
|
|
2012
|
+
if (pcmLogCount < 3 && pcm) {
|
|
2013
|
+
pcmLogCount += 1;
|
|
2014
|
+
sttLog("stream.pcm", `bytes=${pcm.length}`);
|
|
2015
|
+
}
|
|
2016
|
+
return pcm ? waveLevelsFromPcm(pcm) : null;
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
1868
2019
|
// Sticky, never silent: covers the cold model load ("Loading…") until
|
|
1869
2020
|
// the controller reports streaming, then live capture with elapsed
|
|
1870
2021
|
// time. Partial preview toasts continue alongside via the editor.
|
|
@@ -1875,6 +2026,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1875
2026
|
return true;
|
|
1876
2027
|
} catch (err) {
|
|
1877
2028
|
preview?.clear();
|
|
2029
|
+
sttLog("stream.start-failed", err?.message || String(err));
|
|
1878
2030
|
logger?.log("STT", `Streaming start failed: ${err?.message || err}`, "error");
|
|
1879
2031
|
try {
|
|
1880
2032
|
clearStreamingToast();
|
|
@@ -1911,6 +2063,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1911
2063
|
// is at fault, on model/language change, or on plugin unload.
|
|
1912
2064
|
async function finalizeStreamingDictation({ submit = false } = {}) {
|
|
1913
2065
|
if (!streamingDictationActive || !streamController) return null;
|
|
2066
|
+
sttLog("stream.finalize", `submit=${submit}`);
|
|
1914
2067
|
const controller = streamController;
|
|
1915
2068
|
const editor = streamEditor;
|
|
1916
2069
|
const target = streamTarget;
|
|
@@ -1988,18 +2141,9 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1988
2141
|
retainWarmStreamController(controller);
|
|
1989
2142
|
return { text: "" };
|
|
1990
2143
|
}
|
|
1991
|
-
if (preview) {
|
|
1992
|
-
// v2 has a visible preview but no composer append. Finalize submits
|
|
1993
|
-
// once through the same home/create/cancellation fence as batch STT.
|
|
1994
|
-
processing = true;
|
|
1995
|
-
const result = await submitTurnText(client, null, toast, text, logger);
|
|
1996
|
-
if (!streamDisposed && myGen === streamGeneration) retainWarmStreamController(controller);
|
|
1997
|
-
else await controller.dispose?.();
|
|
1998
|
-
return { ...result, submitted: !result.error };
|
|
1999
|
-
}
|
|
2000
2144
|
if (fin?.inserted) {
|
|
2001
2145
|
logger?.log("STT", `Streaming finalized via owned range chars=${text.length}`, "debug");
|
|
2002
|
-
if (submit ||
|
|
2146
|
+
if (submit || autoSubmitNow()) {
|
|
2003
2147
|
if (target && typeof target.submit === "function") {
|
|
2004
2148
|
try {
|
|
2005
2149
|
target.submit();
|
|
@@ -2013,6 +2157,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2013
2157
|
} else {
|
|
2014
2158
|
toast("Streaming transcription added", "success");
|
|
2015
2159
|
}
|
|
2160
|
+
if (preview) processing = false;
|
|
2016
2161
|
retainWarmStreamController(controller);
|
|
2017
2162
|
return { text, inserted: true };
|
|
2018
2163
|
}
|
|
@@ -2033,11 +2178,12 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2033
2178
|
if (!inserted) {
|
|
2034
2179
|
logger?.log("STT", "Streaming finalize: no editable field, transcript retained", "warn");
|
|
2035
2180
|
toast("No editable field - dictated text kept (not inserted elsewhere)", "warning");
|
|
2181
|
+
if (preview) processing = false;
|
|
2036
2182
|
retainWarmStreamController(controller);
|
|
2037
2183
|
return { text, inserted: false };
|
|
2038
2184
|
}
|
|
2039
2185
|
logger?.log("STT", `Streaming finalized chars=${text.length}`, "debug");
|
|
2040
|
-
if (submit ||
|
|
2186
|
+
if (submit || autoSubmitNow()) {
|
|
2041
2187
|
if (target && typeof target.submit === "function") {
|
|
2042
2188
|
try {
|
|
2043
2189
|
target.submit();
|
|
@@ -2051,6 +2197,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2051
2197
|
} else {
|
|
2052
2198
|
toast("Streaming transcription added", "success");
|
|
2053
2199
|
}
|
|
2200
|
+
if (preview) processing = false;
|
|
2054
2201
|
retainWarmStreamController(controller);
|
|
2055
2202
|
return { text, inserted: true };
|
|
2056
2203
|
}
|
|
@@ -2061,6 +2208,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2061
2208
|
// next dictation (user cancel is per-dictation, never a server fault).
|
|
2062
2209
|
async function cancelStreamingDictation() {
|
|
2063
2210
|
streamGeneration += 1;
|
|
2211
|
+
sttLog("stream.cancel");
|
|
2064
2212
|
preview?.clear();
|
|
2065
2213
|
if (preview && processing) cancelRecording(logger);
|
|
2066
2214
|
if (finalizingController) {
|
|
@@ -2153,7 +2301,9 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2153
2301
|
|
|
2154
2302
|
// One-shot auto-submit: speak, press again, and the text submits itself
|
|
2155
2303
|
// without landing in the box first. Off by default (append-then-edit).
|
|
2156
|
-
|
|
2304
|
+
// Live reader: /stt-autosubmit flips the kv value mid-session.
|
|
2305
|
+
const autoSubmit = sttAutoSubmitEnabled();
|
|
2306
|
+
const autoSubmitNow = () => sttAutoSubmitEnabled();
|
|
2157
2307
|
|
|
2158
2308
|
const commands = [
|
|
2159
2309
|
{
|
|
@@ -2173,7 +2323,8 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2173
2323
|
onSelect() {
|
|
2174
2324
|
// Streaming mode: toggle streaming record/finalize. Batch default
|
|
2175
2325
|
// below is behavior-identical to before.
|
|
2176
|
-
|
|
2326
|
+
sttLog("toggle", `sttMode=${currentSttMode()} streamingActive=${streamingDictationActive}`);
|
|
2327
|
+
if (currentSttMode() === "streaming") {
|
|
2177
2328
|
if (streamingDictationActive) {
|
|
2178
2329
|
void finalizeStreamingDictation({ submit: false });
|
|
2179
2330
|
return;
|
|
@@ -2240,7 +2391,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2240
2391
|
onSelect() {
|
|
2241
2392
|
// Streaming mode: finalize then submit ONLY via the captured
|
|
2242
2393
|
// target's own submit(). Never falls through to primary-chat submit.
|
|
2243
|
-
if (
|
|
2394
|
+
if (currentSttMode() === "streaming") {
|
|
2244
2395
|
if (!streamingDictationActive) {
|
|
2245
2396
|
toast("No streaming dictation in progress", "warning");
|
|
2246
2397
|
return;
|
|
@@ -2292,7 +2443,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2292
2443
|
onSelect() {
|
|
2293
2444
|
// Streaming mode: cancel and remove ONLY plugin-owned dictation
|
|
2294
2445
|
// text, never user-typed text.
|
|
2295
|
-
if (
|
|
2446
|
+
if (currentSttMode() === "streaming" || streamingDictationActive) {
|
|
2296
2447
|
if (streamingDictationActive) {
|
|
2297
2448
|
void cancelStreamingDictation();
|
|
2298
2449
|
return;
|
|
@@ -2322,6 +2473,57 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2322
2473
|
}
|
|
2323
2474
|
},
|
|
2324
2475
|
},
|
|
2476
|
+
{
|
|
2477
|
+
title: "STT: select dictation mode",
|
|
2478
|
+
value: "stt.mode",
|
|
2479
|
+
category: "opencode-voice",
|
|
2480
|
+
description: "Choose one-shot batch or live streaming dictation (saved, survives restarts)",
|
|
2481
|
+
slash: { name: "stt-mode" },
|
|
2482
|
+
onSelect() {
|
|
2483
|
+
const current = currentSttMode();
|
|
2484
|
+
api.ui.dialog.replace(() =>
|
|
2485
|
+
api.ui.DialogSelect({
|
|
2486
|
+
title: "Select dictation mode",
|
|
2487
|
+
current,
|
|
2488
|
+
options: [
|
|
2489
|
+
{
|
|
2490
|
+
title: "Streaming (live transcript + wave, local whisper, no LLM)",
|
|
2491
|
+
value: "streaming",
|
|
2492
|
+
onSelect() {
|
|
2493
|
+
kv.set("stt.mode", "streaming");
|
|
2494
|
+
sttLog("mode.set", "streaming via /stt-mode");
|
|
2495
|
+
toast("Dictation mode: streaming");
|
|
2496
|
+
api.ui.dialog.clear();
|
|
2497
|
+
},
|
|
2498
|
+
},
|
|
2499
|
+
{
|
|
2500
|
+
title: "Batch (record, then transcribe)",
|
|
2501
|
+
value: "batch",
|
|
2502
|
+
onSelect() {
|
|
2503
|
+
kv.set("stt.mode", "batch");
|
|
2504
|
+
sttLog("mode.set", "batch via /stt-mode");
|
|
2505
|
+
toast("Dictation mode: batch");
|
|
2506
|
+
api.ui.dialog.clear();
|
|
2507
|
+
},
|
|
2508
|
+
},
|
|
2509
|
+
],
|
|
2510
|
+
}),
|
|
2511
|
+
);
|
|
2512
|
+
},
|
|
2513
|
+
},
|
|
2514
|
+
{
|
|
2515
|
+
title: "STT: toggle auto-submit",
|
|
2516
|
+
value: "stt.autosubmit",
|
|
2517
|
+
category: "opencode-voice",
|
|
2518
|
+
description: "Toggle submitting the transcript automatically after dictation (saved)",
|
|
2519
|
+
slash: { name: "stt-autosubmit" },
|
|
2520
|
+
onSelect() {
|
|
2521
|
+
const next = !sttAutoSubmitEnabled();
|
|
2522
|
+
kv.set("stt.autoSubmit", next);
|
|
2523
|
+
sttLog("mode.set", `autoSubmit=${next} via /stt-autosubmit`);
|
|
2524
|
+
toast(`STT auto-submit: ${next ? "on" : "off"}`);
|
|
2525
|
+
},
|
|
2526
|
+
},
|
|
2325
2527
|
{
|
|
2326
2528
|
title: sttApiEndpoint ? "STT: select model (API)" : "STT: select model",
|
|
2327
2529
|
value: "stt.model",
|