@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/README.md
CHANGED
|
@@ -18,13 +18,13 @@ One package runs on both OpenCode 1.x and 2.x. The plugin detects the host
|
|
|
18
18
|
by capability (never by version string) and adapts; the v1 path is unchanged.
|
|
19
19
|
|
|
20
20
|
> [!IMPORTANT]
|
|
21
|
-
> **
|
|
22
|
-
>
|
|
23
|
-
>
|
|
24
|
-
>
|
|
25
|
-
>
|
|
26
|
-
>
|
|
27
|
-
>
|
|
21
|
+
> **Dictation inserts; it does not send.** On both v1 and v2 the transcript
|
|
22
|
+
> is typed at the cursor of whichever editable field currently has focus —
|
|
23
|
+
> the session composer, a dialog/search input, or another plugin's text
|
|
24
|
+
> field — leaving the text editable. Nothing is submitted unless you asked
|
|
25
|
+
> for it (`/stt-submit`, `sttAutoSubmit`, or conversation mode). If no
|
|
26
|
+
> editable field is focused, v2 keeps the transcript in a recovery dialog
|
|
27
|
+
> instead of sending it as a prompt.
|
|
28
28
|
|
|
29
29
|
### v1 (OpenCode 1.x)
|
|
30
30
|
|
|
@@ -84,21 +84,26 @@ capability detection already picks the right path per host.
|
|
|
84
84
|
every one reliably; the `Ctrl+P` palette shows them for matching queries
|
|
85
85
|
but its search occasionally reports no results for queries that should
|
|
86
86
|
match — when in doubt, use `/slash`.
|
|
87
|
-
- **STT (batch):**
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
- **STT (batch):** the transcript is typed at the cursor of the focused
|
|
88
|
+
editable field and nothing is sent unless submission is requested.
|
|
89
|
+
On home the composer is focused, so dictation works before a session
|
|
90
|
+
exists; an explicit submit creates the session, carries the selected
|
|
91
|
+
model into it, and sends once. Existing sessions retain their
|
|
92
|
+
agent/model. On home, v2's public plugin API exposes the selected model
|
|
93
|
+
but no selected-agent getter, so session creation uses the host's
|
|
94
|
+
default agent. Create/submit failures show the full transcript in a
|
|
95
|
+
recovery dialog. With no editable field focused, the transcript is kept
|
|
96
|
+
in that dialog instead of being sent as a prompt.
|
|
94
97
|
- **STT (streaming dictation):** enable with `"sttMode": "streaming"` in plugin
|
|
95
98
|
options. Local whisper streaming displays a bounded live transcript above
|
|
96
|
-
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;
|
|
97
101
|
the tentative tail is bracketed and may change. Press the record key again
|
|
98
|
-
to finalize
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
to finalize: the full text is inserted once at the focused cursor (and
|
|
103
|
+
submitted when `sttAutoSubmit` is set), or cancel to clear the preview
|
|
104
|
+
without sending. Batch remains the default and produces text after
|
|
105
|
+
recording stops; the hosted `sttEndpoint` option is for batch
|
|
106
|
+
transcription, not this local streaming preview.
|
|
102
107
|
- **TTS / conversation / live notes / cancel:** same semantics as v1 (auto
|
|
103
108
|
TTS on idle/permission/question gates, conversation barge-in, live-notes
|
|
104
109
|
background saves, one-key cancel).
|
|
@@ -747,7 +752,7 @@ Idle invocations toast `Nothing to cancel`. Keybind override:
|
|
|
747
752
|
|
|
748
753
|
Live local dictation for short prompts: the mic stays on, partial
|
|
749
754
|
transcriptions stream in as you speak, and one press of `/stt-record`
|
|
750
|
-
finalizes the text
|
|
755
|
+
finalizes the text at the focused cursor on both hosts.
|
|
751
756
|
Set `"sttMode": "streaming"` in the
|
|
752
757
|
plugin options (default `"batch"` keeps the record-then-transcribe flow
|
|
753
758
|
exactly as before).
|
|
@@ -763,19 +768,20 @@ there is never a silent gap — `Loading speech model…` during cold start,
|
|
|
763
768
|
`● Streaming dictation — listening` with an elapsed timer while live
|
|
764
769
|
(plus a `(listening…)` note when inference runs slow), and `Finalizing…`
|
|
765
770
|
between the second keypress and finalization. On v2, a bounded transcript
|
|
766
|
-
above the prompt footer updates during recording
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
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.
|
|
775
|
+
The OpenCode renderer only
|
|
770
776
|
exposes `insertText`/`submit`, with no live range-replacement API, so
|
|
771
777
|
partials render as preview toasts (`🎙 ...`) alongside (not instead of)
|
|
772
778
|
the sticky status, and the full text is inserted EXACTLY ONCE at
|
|
773
|
-
finalize. If no editable field is focused, the transcript is kept
|
|
774
|
-
toast instead of being redirected into the chat.
|
|
775
|
-
only through the dictated field's own `submit()` — a
|
|
776
|
-
submit keeps its text un-submitted rather than falling
|
|
777
|
-
primary chat. `/stt-stop` cancels and removes only
|
|
778
|
-
text, never your typed prefix/suffix.
|
|
779
|
+
finalize. If no editable field is focused, the transcript is kept visibly
|
|
780
|
+
(v2 recovery dialog, v1 toast) instead of being redirected into the chat.
|
|
781
|
+
`/stt-submit` submits only through the dictated field's own `submit()` — a
|
|
782
|
+
field that cannot submit keeps its text un-submitted rather than falling
|
|
783
|
+
through to the primary chat. `/stt-stop` cancels and removes only
|
|
784
|
+
plugin-dictated text, never your typed prefix/suffix.
|
|
779
785
|
|
|
780
786
|
Warm server: the whisper model stays loaded across dictations (finalize
|
|
781
787
|
and cancel keep the lease); it reloads only on model/language change,
|
|
@@ -796,9 +802,8 @@ Options:
|
|
|
796
802
|
- `sttMode` _(optional, default `"batch"`)_ - `"streaming"` selects this mode
|
|
797
803
|
- `sttStreamWindowMs` _(optional, default `10000`)_ - rolling audio window
|
|
798
804
|
- `sttStreamStepMs` _(optional, default `1000`)_ - live transcription cadence
|
|
799
|
-
- `sttAutoSubmit` applies after streaming finalize on
|
|
800
|
-
dictated field only, as above).
|
|
801
|
-
is no composer append/edit API.
|
|
805
|
+
- `sttAutoSubmit` applies after streaming finalize on both hosts (submit via
|
|
806
|
+
the dictated field only, as above).
|
|
802
807
|
|
|
803
808
|
Measured latencies (Apple M3 Pro, 36 GB, whisper.cpp 1.9.4 with Metal,
|
|
804
809
|
`ggml-large-v3-turbo-q5_0.bin`, scripted speech through the real
|
|
@@ -839,10 +844,11 @@ real streaming controller in `test/v2-preview.test.js`.
|
|
|
839
844
|
3. LLM normalizes the transcription: fixes punctuation, removes filler words,
|
|
840
845
|
corrects software engineering homophones ("Jason" to "JSON", "bullion" to
|
|
841
846
|
"boolean", etc.)
|
|
842
|
-
4. Cleaned text is
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
847
|
+
4. Cleaned text is inserted at the cursor of the focused editable field
|
|
848
|
+
(composer, search, or plugin input), or submitted immediately when
|
|
849
|
+
`/stt-submit` (or `sttAutoSubmit`) is used. If normalization fails (e.g.
|
|
850
|
+
LLM endpoint unreachable), the raw transcription is used as a fallback
|
|
851
|
+
so you never lose your input
|
|
846
852
|
|
|
847
853
|
### TTS pipeline
|
|
848
854
|
|
package/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// opencode-voice: Speech-to-text and text-to-speech for OpenCode.
|
|
2
2
|
//
|
|
3
3
|
// STT: Record voice via sox, transcribe with whisper-cpp, normalize with
|
|
4
|
-
// an OpenAI-compatible LLM,
|
|
5
|
-
//
|
|
6
|
-
//
|
|
4
|
+
// an OpenAI-compatible LLM, and insert the text at the cursor of the
|
|
5
|
+
// focused input (composer, dialog search, or plugin field) on both
|
|
6
|
+
// hosts. Explicit submits only: /stt-submit, sttAutoSubmit, conversation.
|
|
7
7
|
//
|
|
8
8
|
// TTS: Auto-speak assistant responses (or read on demand) via Piper,
|
|
9
9
|
// with LLM normalization for natural speech.
|
|
@@ -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)
|
|
@@ -46,7 +46,8 @@ import { adaptV2Context } from "./lib/v2-compat.js";
|
|
|
46
46
|
// Dual-compat export: v1's loader reads `tui`, v2's reads `setup`
|
|
47
47
|
// (`Plugin.define` is an identity wrapper, so a plain object carries both).
|
|
48
48
|
// Each host ignores the other's key. The core (`bootVoice`) is shared; v2
|
|
49
|
-
// runs it over the v2-compat adapted api
|
|
49
|
+
// runs it over the v2-compat adapted api, which forwards the live renderer
|
|
50
|
+
// so dictation lands in whatever input currently has focus.
|
|
50
51
|
export default {
|
|
51
52
|
id: "opencode-voice",
|
|
52
53
|
tui: async (api, options) => {
|
|
@@ -55,16 +56,16 @@ export default {
|
|
|
55
56
|
setup: async (ctx) => {
|
|
56
57
|
const adapted = adaptV2Context(ctx);
|
|
57
58
|
await bootVoice(adapted.api, ctx.options, {
|
|
58
|
-
|
|
59
|
+
v2: true,
|
|
59
60
|
onReady: async ({ logger }) => {
|
|
60
|
-
// First-run
|
|
61
|
-
//
|
|
61
|
+
// First-run v2 notice (required UX disclosure): text is typed into
|
|
62
|
+
// the focused field and is never sent automatically.
|
|
62
63
|
const notice =
|
|
63
|
-
"Voice on OpenCode v2: transcripts
|
|
64
|
-
"(
|
|
65
|
-
"
|
|
64
|
+
"Voice on OpenCode v2: transcripts are inserted at the cursor of the focused text field " +
|
|
65
|
+
"(prompt, search, or dialog input) and are not sent automatically. " +
|
|
66
|
+
"Set sttAutoSubmit to submit after recording.";
|
|
66
67
|
adapted.api.ui.toast({ message: notice, variant: "warning", duration: 8000 });
|
|
67
|
-
logger?.log?.("plugin", `v2
|
|
68
|
+
logger?.log?.("plugin", `v2 focused-input mode: ${notice}`, "warn");
|
|
68
69
|
// v2 has no client.app.log, so the logger above is a no-op: compat
|
|
69
70
|
// warnings must surface as a toast or they are lost entirely.
|
|
70
71
|
if (adapted.warnMessages.length > 0) {
|
package/lib/boot.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
// an `api` object (raw v1 `TuiPluginApi` vs the v2-compat adapted `Context`).
|
|
5
5
|
// Everything below runs identically on both, so there is exactly one core to
|
|
6
6
|
// maintain. The v1 `tui` path calls `bootVoice(api, options)` with no extras
|
|
7
|
-
// and behaves exactly as before; the v2 `setup` path passes
|
|
8
|
-
//
|
|
9
|
-
//
|
|
7
|
+
// and behaves exactly as before; the v2 `setup` path passes `{ v2: true }`
|
|
8
|
+
// for the first-run notice. No STT/TTS/routing/keybind behavior branches
|
|
9
|
+
// live here.
|
|
10
10
|
|
|
11
11
|
import fs from "node:fs";
|
|
12
12
|
import os from "node:os";
|
|
@@ -98,7 +98,7 @@ export async function bootVoice(api, options, extras = {}) {
|
|
|
98
98
|
...cancel.commands,
|
|
99
99
|
]);
|
|
100
100
|
|
|
101
|
-
if (extras?.
|
|
101
|
+
if (extras?.v2 && typeof extras?.onReady === "function") {
|
|
102
102
|
await extras.onReady({ logger, stt, tts, conversation, liveNotes, voiceModel, cancel });
|
|
103
103
|
}
|
|
104
104
|
|
package/lib/conversation.js
CHANGED
|
@@ -373,7 +373,7 @@ export function registerConversation(api, opts, logger, { stt, tts, isLiveNotesA
|
|
|
373
373
|
// v2 prompt dispatch may emit the entire reply before its promise returns.
|
|
374
374
|
// Home creation navigates before prompting, so resolve the ID at event time.
|
|
375
375
|
let earlyWait = null;
|
|
376
|
-
if (api.client?.tui?.
|
|
376
|
+
if (api.client?.tui?.v2) {
|
|
377
377
|
phase = "waiting";
|
|
378
378
|
startReplyStream(currentSessionID, turnStart);
|
|
379
379
|
earlyWait = waitForReply(currentSessionID);
|
package/lib/llm-client.js
CHANGED
|
@@ -102,7 +102,9 @@ export function resolveProviderConfig(provider, model) {
|
|
|
102
102
|
const exported = envVars.find((name) => name && process.env[name]);
|
|
103
103
|
return {
|
|
104
104
|
endpoint,
|
|
105
|
-
model
|
|
105
|
+
// v2 keeps the upstream provider's model id in `modelID` (`id` is the
|
|
106
|
+
// selection id and can differ for configured aliases), so prefer it.
|
|
107
|
+
model: model.modelID ?? model.id,
|
|
106
108
|
apiKeyEnv: exported || envVars[0] || null,
|
|
107
109
|
};
|
|
108
110
|
}
|
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
|
+
}
|