@bojackduy/opencode-voice 0.11.1 → 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 +43 -37
- package/index.js +13 -12
- package/lib/boot.js +4 -4
- package/lib/conversation.js +1 -1
- package/lib/llm-client.js +3 -1
- package/lib/streaming-stt.js +20 -0
- package/lib/stt-log.js +39 -0
- package/lib/stt.js +241 -30
- 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 +96 -23
- package/lib/v2-preview.js +141 -21
- package/package.json +1 -1
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({
|
|
@@ -1376,9 +1472,11 @@ async function appendTranscription(client, renderer, text, submit, isCurrent) {
|
|
|
1376
1472
|
return true;
|
|
1377
1473
|
}
|
|
1378
1474
|
|
|
1379
|
-
// Only the
|
|
1380
|
-
//
|
|
1381
|
-
|
|
1475
|
+
// Only the v2 adapter consumes this fence; v1 request bodies remain
|
|
1476
|
+
// unchanged. Re-check after an asynchronous home session create. The
|
|
1477
|
+
// `submit` flag lets the adapter distinguish an explicit submit from a
|
|
1478
|
+
// plain append with no editable field focused (append must not send).
|
|
1479
|
+
const fence = client.tui?.v2 ? { isCurrent, submit } : {};
|
|
1382
1480
|
let appendResult = await client.tui.appendPrompt({ body: { text }, ...fence });
|
|
1383
1481
|
|
|
1384
1482
|
if (appendResult?.error?.data?.message === "Expected object, got undefined") {
|
|
@@ -1391,7 +1489,9 @@ async function appendTranscription(client, renderer, text, submit, isCurrent) {
|
|
|
1391
1489
|
);
|
|
1392
1490
|
}
|
|
1393
1491
|
|
|
1394
|
-
if (
|
|
1492
|
+
if (appendResult?.retained) return appendResult;
|
|
1493
|
+
|
|
1494
|
+
if (submit && !appendResult?.submitted) {
|
|
1395
1495
|
await client.tui.submitPrompt();
|
|
1396
1496
|
}
|
|
1397
1497
|
return appendResult;
|
|
@@ -1515,15 +1615,15 @@ async function appendTurnText(client, renderer, toast, text, logger) {
|
|
|
1515
1615
|
);
|
|
1516
1616
|
clearProcessingToast();
|
|
1517
1617
|
logger?.log("STT", `Turn appended chars=${text.length}`, "debug");
|
|
1518
|
-
//
|
|
1519
|
-
//
|
|
1520
|
-
// the text was "added to prompt" for editing there. v1 results carry no
|
|
1618
|
+
// The v2 adapter retains the transcript when no editable field has
|
|
1619
|
+
// focus — it never sends an unrequested prompt. v1 results carry no
|
|
1521
1620
|
// marker and keep the original toast.
|
|
1621
|
+
const retained = appendResult?.retained === true;
|
|
1522
1622
|
toast(
|
|
1523
|
-
|
|
1524
|
-
? "
|
|
1623
|
+
retained
|
|
1624
|
+
? "No text field focused - transcription kept (not sent)"
|
|
1525
1625
|
: "Transcription added to prompt",
|
|
1526
|
-
"success",
|
|
1626
|
+
retained ? "warning" : "success",
|
|
1527
1627
|
);
|
|
1528
1628
|
return { text };
|
|
1529
1629
|
} catch (err) {
|
|
@@ -1601,6 +1701,17 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1601
1701
|
const client = api.client;
|
|
1602
1702
|
const renderer = opts?.focusMode === "primary" ? null : api.renderer;
|
|
1603
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
|
+
);
|
|
1604
1715
|
let streamGeneration = 0;
|
|
1605
1716
|
let streamDisposed = false;
|
|
1606
1717
|
let finalizingController = null;
|
|
@@ -1692,7 +1803,30 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1692
1803
|
}
|
|
1693
1804
|
|
|
1694
1805
|
// ---- Streaming dictation session (stage 2, local-only, no LLM) ----
|
|
1695
|
-
|
|
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();
|
|
1696
1830
|
const streamTimings = resolveStreamTimings(opts);
|
|
1697
1831
|
logger?.log(
|
|
1698
1832
|
"STT",
|
|
@@ -1793,6 +1927,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1793
1927
|
});
|
|
1794
1928
|
if (preview) await preview.begin();
|
|
1795
1929
|
else editor.begin(target);
|
|
1930
|
+
sttLog("stream.begin", `preview=${preview ? "yes" : "no"}`);
|
|
1796
1931
|
if (streamDisposed || myGen !== streamGeneration) {
|
|
1797
1932
|
preview?.clear();
|
|
1798
1933
|
return false;
|
|
@@ -1806,8 +1941,13 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1806
1941
|
try {
|
|
1807
1942
|
ed.applyPartial(p);
|
|
1808
1943
|
} catch {}
|
|
1944
|
+
sttLog(
|
|
1945
|
+
"stream.partial",
|
|
1946
|
+
`stable=${(p?.stableText || "").length} tentative=${(p?.tentativeText || "").length}`,
|
|
1947
|
+
);
|
|
1809
1948
|
},
|
|
1810
1949
|
onStateChange: (s) => {
|
|
1950
|
+
sttLog("stream.state", s);
|
|
1811
1951
|
try {
|
|
1812
1952
|
if (s === "streaming") {
|
|
1813
1953
|
updateStreamingToast("● Streaming dictation — listening");
|
|
@@ -1861,6 +2001,21 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1861
2001
|
return false;
|
|
1862
2002
|
}
|
|
1863
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
|
+
}
|
|
1864
2019
|
// Sticky, never silent: covers the cold model load ("Loading…") until
|
|
1865
2020
|
// the controller reports streaming, then live capture with elapsed
|
|
1866
2021
|
// time. Partial preview toasts continue alongside via the editor.
|
|
@@ -1871,6 +2026,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1871
2026
|
return true;
|
|
1872
2027
|
} catch (err) {
|
|
1873
2028
|
preview?.clear();
|
|
2029
|
+
sttLog("stream.start-failed", err?.message || String(err));
|
|
1874
2030
|
logger?.log("STT", `Streaming start failed: ${err?.message || err}`, "error");
|
|
1875
2031
|
try {
|
|
1876
2032
|
clearStreamingToast();
|
|
@@ -1907,6 +2063,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1907
2063
|
// is at fault, on model/language change, or on plugin unload.
|
|
1908
2064
|
async function finalizeStreamingDictation({ submit = false } = {}) {
|
|
1909
2065
|
if (!streamingDictationActive || !streamController) return null;
|
|
2066
|
+
sttLog("stream.finalize", `submit=${submit}`);
|
|
1910
2067
|
const controller = streamController;
|
|
1911
2068
|
const editor = streamEditor;
|
|
1912
2069
|
const target = streamTarget;
|
|
@@ -1984,18 +2141,9 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
1984
2141
|
retainWarmStreamController(controller);
|
|
1985
2142
|
return { text: "" };
|
|
1986
2143
|
}
|
|
1987
|
-
if (preview) {
|
|
1988
|
-
// v2 has a visible preview but no composer append. Finalize submits
|
|
1989
|
-
// once through the same home/create/cancellation fence as batch STT.
|
|
1990
|
-
processing = true;
|
|
1991
|
-
const result = await submitTurnText(client, null, toast, text, logger);
|
|
1992
|
-
if (!streamDisposed && myGen === streamGeneration) retainWarmStreamController(controller);
|
|
1993
|
-
else await controller.dispose?.();
|
|
1994
|
-
return { ...result, submitted: !result.error };
|
|
1995
|
-
}
|
|
1996
2144
|
if (fin?.inserted) {
|
|
1997
2145
|
logger?.log("STT", `Streaming finalized via owned range chars=${text.length}`, "debug");
|
|
1998
|
-
if (submit ||
|
|
2146
|
+
if (submit || autoSubmitNow()) {
|
|
1999
2147
|
if (target && typeof target.submit === "function") {
|
|
2000
2148
|
try {
|
|
2001
2149
|
target.submit();
|
|
@@ -2009,6 +2157,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2009
2157
|
} else {
|
|
2010
2158
|
toast("Streaming transcription added", "success");
|
|
2011
2159
|
}
|
|
2160
|
+
if (preview) processing = false;
|
|
2012
2161
|
retainWarmStreamController(controller);
|
|
2013
2162
|
return { text, inserted: true };
|
|
2014
2163
|
}
|
|
@@ -2029,11 +2178,12 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2029
2178
|
if (!inserted) {
|
|
2030
2179
|
logger?.log("STT", "Streaming finalize: no editable field, transcript retained", "warn");
|
|
2031
2180
|
toast("No editable field - dictated text kept (not inserted elsewhere)", "warning");
|
|
2181
|
+
if (preview) processing = false;
|
|
2032
2182
|
retainWarmStreamController(controller);
|
|
2033
2183
|
return { text, inserted: false };
|
|
2034
2184
|
}
|
|
2035
2185
|
logger?.log("STT", `Streaming finalized chars=${text.length}`, "debug");
|
|
2036
|
-
if (submit ||
|
|
2186
|
+
if (submit || autoSubmitNow()) {
|
|
2037
2187
|
if (target && typeof target.submit === "function") {
|
|
2038
2188
|
try {
|
|
2039
2189
|
target.submit();
|
|
@@ -2047,6 +2197,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2047
2197
|
} else {
|
|
2048
2198
|
toast("Streaming transcription added", "success");
|
|
2049
2199
|
}
|
|
2200
|
+
if (preview) processing = false;
|
|
2050
2201
|
retainWarmStreamController(controller);
|
|
2051
2202
|
return { text, inserted: true };
|
|
2052
2203
|
}
|
|
@@ -2057,6 +2208,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2057
2208
|
// next dictation (user cancel is per-dictation, never a server fault).
|
|
2058
2209
|
async function cancelStreamingDictation() {
|
|
2059
2210
|
streamGeneration += 1;
|
|
2211
|
+
sttLog("stream.cancel");
|
|
2060
2212
|
preview?.clear();
|
|
2061
2213
|
if (preview && processing) cancelRecording(logger);
|
|
2062
2214
|
if (finalizingController) {
|
|
@@ -2136,7 +2288,12 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2136
2288
|
cancel: () => cancelRecording(logger),
|
|
2137
2289
|
discard: () => discardTurn(),
|
|
2138
2290
|
transcribeTurn: () => transcribeTurn(kv, complete, client, api, toast, systemPrompt, logger),
|
|
2139
|
-
|
|
2291
|
+
// Conversation turns are hands-free submissions, not dictation: on v2
|
|
2292
|
+
// they must not press Enter in whatever field happens to have focus (a
|
|
2293
|
+
// permission dialog could own it), so they always go through the
|
|
2294
|
+
// session.prompt submit path. v1 keeps its focused-insert + submit.
|
|
2295
|
+
submitTurnText: (text) =>
|
|
2296
|
+
submitTurnText(client, client.tui?.v2 ? null : renderer, toast, text, logger),
|
|
2140
2297
|
startStreaming: startStreamingDictation,
|
|
2141
2298
|
finalizeStreaming: finalizeStreamingDictation,
|
|
2142
2299
|
cancelStreaming: cancelStreamingDictation,
|
|
@@ -2144,7 +2301,9 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2144
2301
|
|
|
2145
2302
|
// One-shot auto-submit: speak, press again, and the text submits itself
|
|
2146
2303
|
// without landing in the box first. Off by default (append-then-edit).
|
|
2147
|
-
|
|
2304
|
+
// Live reader: /stt-autosubmit flips the kv value mid-session.
|
|
2305
|
+
const autoSubmit = sttAutoSubmitEnabled();
|
|
2306
|
+
const autoSubmitNow = () => sttAutoSubmitEnabled();
|
|
2148
2307
|
|
|
2149
2308
|
const commands = [
|
|
2150
2309
|
{
|
|
@@ -2164,7 +2323,8 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2164
2323
|
onSelect() {
|
|
2165
2324
|
// Streaming mode: toggle streaming record/finalize. Batch default
|
|
2166
2325
|
// below is behavior-identical to before.
|
|
2167
|
-
|
|
2326
|
+
sttLog("toggle", `sttMode=${currentSttMode()} streamingActive=${streamingDictationActive}`);
|
|
2327
|
+
if (currentSttMode() === "streaming") {
|
|
2168
2328
|
if (streamingDictationActive) {
|
|
2169
2329
|
void finalizeStreamingDictation({ submit: false });
|
|
2170
2330
|
return;
|
|
@@ -2231,7 +2391,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2231
2391
|
onSelect() {
|
|
2232
2392
|
// Streaming mode: finalize then submit ONLY via the captured
|
|
2233
2393
|
// target's own submit(). Never falls through to primary-chat submit.
|
|
2234
|
-
if (
|
|
2394
|
+
if (currentSttMode() === "streaming") {
|
|
2235
2395
|
if (!streamingDictationActive) {
|
|
2236
2396
|
toast("No streaming dictation in progress", "warning");
|
|
2237
2397
|
return;
|
|
@@ -2283,7 +2443,7 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2283
2443
|
onSelect() {
|
|
2284
2444
|
// Streaming mode: cancel and remove ONLY plugin-owned dictation
|
|
2285
2445
|
// text, never user-typed text.
|
|
2286
|
-
if (
|
|
2446
|
+
if (currentSttMode() === "streaming" || streamingDictationActive) {
|
|
2287
2447
|
if (streamingDictationActive) {
|
|
2288
2448
|
void cancelStreamingDictation();
|
|
2289
2449
|
return;
|
|
@@ -2313,6 +2473,57 @@ export function registerSTT(api, kv, complete, prompts, opts, logger, deps = {})
|
|
|
2313
2473
|
}
|
|
2314
2474
|
},
|
|
2315
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
|
+
},
|
|
2316
2527
|
{
|
|
2317
2528
|
title: sttApiEndpoint ? "STT: select model (API)" : "STT: select model",
|
|
2318
2529
|
value: "stt.model",
|