@hxnnxs/opencode-voice 0.1.9 → 0.2.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/CHANGELOG.md +25 -0
- package/PUBLISHING.md +3 -3
- package/README.md +75 -35
- package/bin/opencode-voice.js +26 -5
- package/docs/README.es.md +5 -2
- package/docs/README.ru.md +5 -2
- package/docs/README.zh.md +10 -7
- package/index.js +268 -150
- package/lib/engine.js +44 -17
- package/lib/engines.js +54 -35
- package/lib/handy-model-catalog.js +820 -0
- package/lib/models.js +183 -24
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -4,7 +4,10 @@ import { VoiceRuntime, ensureManagedRecorder, getRecorderStatus, listMicrophones
|
|
|
4
4
|
import { getEngineStatus, importManagedEngine, installManagedEngine, probeEngine, removeManagedEngine } from "./lib/engines.js";
|
|
5
5
|
|
|
6
6
|
const KV = {
|
|
7
|
+
// Legacy keys are read once by migrateSettings so existing installations keep
|
|
8
|
+
// their configured recording key after upgrading to the unified setting.
|
|
7
9
|
hotkey: "voice.hotkey",
|
|
10
|
+
recordingHotkey: "voice.recordingHotkey",
|
|
8
11
|
toggleHotkey: "voice.toggleHotkey",
|
|
9
12
|
submitHotkey: "voice.submitHotkey",
|
|
10
13
|
model: "voice.model",
|
|
@@ -21,8 +24,7 @@ function readSettings(kv) {
|
|
|
21
24
|
for (const [name, key] of Object.entries(KV)) settings[name] = kv.get(key, settings[name]);
|
|
22
25
|
|
|
23
26
|
if (!getModel(settings.model)?.implemented) settings.model = DEFAULT_SETTINGS.model;
|
|
24
|
-
settings.
|
|
25
|
-
settings.toggleHotkey = String(settings.toggleHotkey || "").trim();
|
|
27
|
+
settings.recordingHotkey = String(settings.recordingHotkey || settings.toggleHotkey || "ctrl+r").trim();
|
|
26
28
|
settings.submitHotkey = String(settings.submitHotkey || "").trim();
|
|
27
29
|
settings.language = String(settings.language || "auto").trim() || "auto";
|
|
28
30
|
settings.mic = String(settings.mic || "").trim();
|
|
@@ -38,11 +40,13 @@ function writeSetting(kv, name, value) {
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
function migrateSettings(kv) {
|
|
41
|
-
// Early builds
|
|
42
|
-
//
|
|
43
|
+
// Early builds stored separate hold and toggle keys. Preserve the user's
|
|
44
|
+
// explicit hold key first, otherwise retain the old toggle binding.
|
|
43
45
|
const holdHotkey = kv.get(KV.hotkey, undefined);
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
+
if (!kv.get(KV.recordingHotkey, undefined)) {
|
|
47
|
+
const configuredHotkey = String(kv.get(KV.hotkey, "")).trim();
|
|
48
|
+
kv.set(KV.recordingHotkey, configuredHotkey || kv.get(KV.toggleHotkey, DEFAULT_SETTINGS.recordingHotkey));
|
|
49
|
+
}
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
function toast(api, message, variant = "info") {
|
|
@@ -111,7 +115,7 @@ function renderDownloadStatus(ctx, model, progress = {}) {
|
|
|
111
115
|
);
|
|
112
116
|
}
|
|
113
117
|
|
|
114
|
-
function renderEngineInstallStatus(ctx, progress = {}) {
|
|
118
|
+
function renderEngineInstallStatus(ctx, engineId, progress = {}) {
|
|
115
119
|
const percent = Math.max(0, Math.min(100, progress.percent || 0));
|
|
116
120
|
const state = {
|
|
117
121
|
registry: "Loading engine registry",
|
|
@@ -119,7 +123,7 @@ function renderEngineInstallStatus(ctx, progress = {}) {
|
|
|
119
123
|
verifying: "Verifying engine archive",
|
|
120
124
|
decompressing: "Unpacking engine",
|
|
121
125
|
"verifying-binary": "Verifying engine binary",
|
|
122
|
-
probing: "Checking
|
|
126
|
+
probing: "Checking native binary",
|
|
123
127
|
done: "Native engine ready",
|
|
124
128
|
}[progress.state] || "Preparing native engine";
|
|
125
129
|
const attempt = progress.attempts > 1 ? `${progress.attempt} of ${progress.attempts}` : "single pass";
|
|
@@ -128,7 +132,7 @@ function renderEngineInstallStatus(ctx, progress = {}) {
|
|
|
128
132
|
ctx.api.ui.DialogAlert({
|
|
129
133
|
title: "Installing voice engine",
|
|
130
134
|
message: [
|
|
131
|
-
|
|
135
|
+
engineId,
|
|
132
136
|
"",
|
|
133
137
|
state,
|
|
134
138
|
progressLine(percent),
|
|
@@ -221,25 +225,26 @@ async function ensureDownloaded(ctx, model, settings) {
|
|
|
221
225
|
return true;
|
|
222
226
|
}
|
|
223
227
|
|
|
224
|
-
async function ensureEngineReady(ctx, settings) {
|
|
228
|
+
async function ensureEngineReady(ctx, settings, model = getModel(settings.model)) {
|
|
229
|
+
const engineId = model.engine;
|
|
225
230
|
const commandOptions = { ...ctx.options, downloadDir: settings.downloadDir };
|
|
226
|
-
const current = getEngineStatus(
|
|
231
|
+
const current = getEngineStatus(engineId, ctx.options, settings);
|
|
227
232
|
if (current.resolvedBinary) {
|
|
228
|
-
const probe = await probeEngine(
|
|
233
|
+
const probe = await probeEngine(engineId, current.resolvedBinary);
|
|
229
234
|
if (probe.ok) return true;
|
|
230
235
|
}
|
|
231
236
|
|
|
232
|
-
renderEngineInstallStatus(ctx, { state: "registry", downloaded: 0, total: 0, percent: 0, attempt: 1, attempts: 5 });
|
|
233
|
-
toast(ctx.api,
|
|
234
|
-
await installManagedEngine(
|
|
237
|
+
renderEngineInstallStatus(ctx, engineId, { state: "registry", downloaded: 0, total: 0, percent: 0, attempt: 1, attempts: 5 });
|
|
238
|
+
toast(ctx.api, `Installing ${engineId}...`);
|
|
239
|
+
await installManagedEngine(engineId, commandOptions, settings, {
|
|
235
240
|
retries: 5,
|
|
236
|
-
onProgress: (progress) => renderEngineInstallStatus(ctx, progress),
|
|
241
|
+
onProgress: (progress) => renderEngineInstallStatus(ctx, engineId, progress),
|
|
237
242
|
onRetry: ({ error, nextAttempt, attempts }) => {
|
|
238
|
-
renderEngineInstallStatus(ctx, { state: "downloading", downloaded: 0, total: 0, percent: 0, attempt: nextAttempt, attempts });
|
|
243
|
+
renderEngineInstallStatus(ctx, engineId, { state: "downloading", downloaded: 0, total: 0, percent: 0, attempt: nextAttempt, attempts });
|
|
239
244
|
toast(ctx.api, `Engine install retry ${nextAttempt}/${attempts}: ${error instanceof Error ? error.message : String(error)}`, "warning");
|
|
240
245
|
},
|
|
241
246
|
});
|
|
242
|
-
toast(ctx.api,
|
|
247
|
+
toast(ctx.api, `${engineId} installed`, "success");
|
|
243
248
|
return true;
|
|
244
249
|
}
|
|
245
250
|
|
|
@@ -305,7 +310,7 @@ function showModelPicker(ctx, firstRun = false) {
|
|
|
305
310
|
writeSetting(ctx.api.kv, "setupSkipped", false);
|
|
306
311
|
|
|
307
312
|
try {
|
|
308
|
-
await ensureEngineReady(ctx, nextSettings);
|
|
313
|
+
await ensureEngineReady(ctx, nextSettings, model);
|
|
309
314
|
await ensureDownloaded(ctx, model, nextSettings);
|
|
310
315
|
ctx.api.ui.dialog.clear();
|
|
311
316
|
} catch (error) {
|
|
@@ -336,16 +341,115 @@ function showPrompt(ctx, input) {
|
|
|
336
341
|
);
|
|
337
342
|
}
|
|
338
343
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
344
|
+
const WHISPER_LANGUAGES = [
|
|
345
|
+
["Afrikaans", "af"],
|
|
346
|
+
["Amharic", "am"],
|
|
347
|
+
["Arabic", "ar"],
|
|
348
|
+
["Assamese", "as"],
|
|
349
|
+
["Azerbaijani", "az"],
|
|
350
|
+
["Bashkir", "ba"],
|
|
351
|
+
["Belarusian", "be"],
|
|
352
|
+
["Bulgarian", "bg"],
|
|
353
|
+
["Bengali", "bn"],
|
|
354
|
+
["Tibetan", "bo"],
|
|
355
|
+
["Breton", "br"],
|
|
356
|
+
["Bosnian", "bs"],
|
|
357
|
+
["Catalan", "ca"],
|
|
358
|
+
["Czech", "cs"],
|
|
359
|
+
["Welsh", "cy"],
|
|
360
|
+
["Danish", "da"],
|
|
361
|
+
["German", "de"],
|
|
362
|
+
["Greek", "el"],
|
|
363
|
+
["English", "en"],
|
|
364
|
+
["Spanish", "es"],
|
|
365
|
+
["Estonian", "et"],
|
|
366
|
+
["Basque", "eu"],
|
|
367
|
+
["Persian", "fa"],
|
|
368
|
+
["Finnish", "fi"],
|
|
369
|
+
["Faroese", "fo"],
|
|
370
|
+
["French", "fr"],
|
|
371
|
+
["Galician", "gl"],
|
|
372
|
+
["Gujarati", "gu"],
|
|
373
|
+
["Hausa", "ha"],
|
|
374
|
+
["Hawaiian", "haw"],
|
|
375
|
+
["Hebrew", "he"],
|
|
376
|
+
["Hindi", "hi"],
|
|
377
|
+
["Croatian", "hr"],
|
|
378
|
+
["Haitian Creole", "ht"],
|
|
379
|
+
["Hungarian", "hu"],
|
|
380
|
+
["Armenian", "hy"],
|
|
381
|
+
["Indonesian", "id"],
|
|
382
|
+
["Icelandic", "is"],
|
|
383
|
+
["Italian", "it"],
|
|
384
|
+
["Japanese", "ja"],
|
|
385
|
+
["Javanese", "jw"],
|
|
386
|
+
["Georgian", "ka"],
|
|
387
|
+
["Kazakh", "kk"],
|
|
388
|
+
["Khmer", "km"],
|
|
389
|
+
["Kannada", "kn"],
|
|
390
|
+
["Korean", "ko"],
|
|
391
|
+
["Latin", "la"],
|
|
392
|
+
["Luxembourgish", "lb"],
|
|
393
|
+
["Lingala", "ln"],
|
|
394
|
+
["Lao", "lo"],
|
|
395
|
+
["Lithuanian", "lt"],
|
|
396
|
+
["Latvian", "lv"],
|
|
397
|
+
["Malagasy", "mg"],
|
|
398
|
+
["Maori", "mi"],
|
|
399
|
+
["Macedonian", "mk"],
|
|
400
|
+
["Malayalam", "ml"],
|
|
401
|
+
["Mongolian", "mn"],
|
|
402
|
+
["Marathi", "mr"],
|
|
403
|
+
["Malay", "ms"],
|
|
404
|
+
["Maltese", "mt"],
|
|
405
|
+
["Myanmar", "my"],
|
|
406
|
+
["Nepali", "ne"],
|
|
407
|
+
["Dutch", "nl"],
|
|
408
|
+
["Norwegian Nynorsk", "nn"],
|
|
409
|
+
["Norwegian", "no"],
|
|
410
|
+
["Occitan", "oc"],
|
|
411
|
+
["Punjabi", "pa"],
|
|
412
|
+
["Pashto", "ps"],
|
|
413
|
+
["Portuguese", "pt"],
|
|
414
|
+
["Romanian", "ro"],
|
|
415
|
+
["Russian", "ru"],
|
|
416
|
+
["Sanskrit", "sa"],
|
|
417
|
+
["Sindhi", "sd"],
|
|
418
|
+
["Sinhala", "si"],
|
|
419
|
+
["Slovak", "sk"],
|
|
420
|
+
["Slovenian", "sl"],
|
|
421
|
+
["Shona", "sn"],
|
|
422
|
+
["Somali", "so"],
|
|
423
|
+
["Albanian", "sq"],
|
|
424
|
+
["Serbian", "sr"],
|
|
425
|
+
["Sundanese", "su"],
|
|
426
|
+
["Swedish", "sv"],
|
|
427
|
+
["Swahili", "sw"],
|
|
428
|
+
["Tamil", "ta"],
|
|
429
|
+
["Telugu", "te"],
|
|
430
|
+
["Tajik", "tg"],
|
|
431
|
+
["Thai", "th"],
|
|
432
|
+
["Turkmen", "tk"],
|
|
433
|
+
["Tagalog", "tl"],
|
|
434
|
+
["Turkish", "tr"],
|
|
435
|
+
["Tatar", "tt"],
|
|
436
|
+
["Ukrainian", "uk"],
|
|
437
|
+
["Urdu", "ur"],
|
|
438
|
+
["Uzbek", "uz"],
|
|
439
|
+
["Vietnamese", "vi"],
|
|
440
|
+
["Yiddish", "yi"],
|
|
441
|
+
["Yoruba", "yo"],
|
|
442
|
+
["Chinese", "zh"],
|
|
443
|
+
["Cantonese", "yue"],
|
|
444
|
+
["Zulu", "zu"],
|
|
445
|
+
];
|
|
446
|
+
|
|
447
|
+
function showLanguagePicker(ctx) {
|
|
448
|
+
const settings = readSettings(ctx.api.kv);
|
|
449
|
+
const options = [
|
|
450
|
+
{ title: "Auto detect", value: "auto", description: "Let Whisper detect the language." },
|
|
451
|
+
...WHISPER_LANGUAGES.map(([name, code]) => ({ title: name, value: code })),
|
|
452
|
+
{ title: "Custom code", value: "__custom", description: "Enter a Whisper language code manually." },
|
|
349
453
|
];
|
|
350
454
|
|
|
351
455
|
setDialog(ctx, "medium", () =>
|
|
@@ -409,15 +513,53 @@ function showMicrophonePicker(ctx) {
|
|
|
409
513
|
);
|
|
410
514
|
}
|
|
411
515
|
|
|
516
|
+
function showRecordingHotkeyPicker(ctx) {
|
|
517
|
+
const settings = readSettings(ctx.api.kv);
|
|
518
|
+
const presets = [
|
|
519
|
+
{ title: "Ctrl + R", value: "ctrl+r", description: "Start and stop recording." },
|
|
520
|
+
{ title: "Ctrl + Space", value: "ctrl+space", description: "Start and stop recording." },
|
|
521
|
+
{ title: "Alt + R", value: "alt+r", description: "Start and stop recording." },
|
|
522
|
+
{ title: "Custom hotkey", value: "__custom", description: "Enter another OpenCode keybinding." },
|
|
523
|
+
];
|
|
524
|
+
|
|
525
|
+
setDialog(ctx, "medium", () =>
|
|
526
|
+
ctx.api.ui.DialogSelect({
|
|
527
|
+
title: "Record key",
|
|
528
|
+
current: presets.some((preset) => preset.value === settings.recordingHotkey) ? settings.recordingHotkey : "__custom",
|
|
529
|
+
options: presets,
|
|
530
|
+
onSelect: (option) => {
|
|
531
|
+
if (option.value === "__custom") {
|
|
532
|
+
showPrompt(ctx, {
|
|
533
|
+
title: "Custom recording key",
|
|
534
|
+
placeholder: "alt+shift+r",
|
|
535
|
+
value: settings.recordingHotkey,
|
|
536
|
+
onConfirm: (value) => {
|
|
537
|
+
writeSetting(ctx.api.kv, "recordingHotkey", value.trim());
|
|
538
|
+
ctx.registerCommands();
|
|
539
|
+
showRecordingSettings(ctx);
|
|
540
|
+
},
|
|
541
|
+
});
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
writeSetting(ctx.api.kv, "recordingHotkey", option.value);
|
|
546
|
+
ctx.registerCommands();
|
|
547
|
+
showRecordingSettings(ctx);
|
|
548
|
+
},
|
|
549
|
+
}),
|
|
550
|
+
);
|
|
551
|
+
}
|
|
552
|
+
|
|
412
553
|
function showDiagnostics(ctx) {
|
|
413
554
|
const settings = readSettings(ctx.api.kv);
|
|
414
555
|
const model = getModel(settings.model);
|
|
415
556
|
const commandOptions = { ...ctx.options, downloadDir: settings.downloadDir, skipFfmpegStaticInstall: true };
|
|
416
557
|
const whisperCli = resolveCommand("whisper-cli", commandOptions);
|
|
558
|
+
const transcribeCpp = resolveCommand("opencode-voice-transcribe", commandOptions);
|
|
417
559
|
const ffmpeg = resolveCommand("ffmpeg", commandOptions);
|
|
418
560
|
const arecord = resolveCommand("arecord", commandOptions);
|
|
419
561
|
const sox = resolveCommand("sox", commandOptions);
|
|
420
|
-
const engine = getEngineStatus(
|
|
562
|
+
const engine = getEngineStatus(model.engine, ctx.options, settings);
|
|
421
563
|
const recorder = getRecorderStatus(commandOptions, settings);
|
|
422
564
|
const lines = [
|
|
423
565
|
`Platform: ${process.platform}-${process.arch}`,
|
|
@@ -429,6 +571,7 @@ function showDiagnostics(ctx) {
|
|
|
429
571
|
`Engine: ${engine.id}`,
|
|
430
572
|
`Engine source: ${engine.source}`,
|
|
431
573
|
`whisper-cli: ${whisperCli || "missing"}`,
|
|
574
|
+
`opencode-voice-transcribe: ${transcribeCpp || "missing"}`,
|
|
432
575
|
`Managed engine dir: ${engine.managedDir}`,
|
|
433
576
|
`Managed installed: ${engine.managedInstalled ? "yes" : "no"}`,
|
|
434
577
|
`Managed version: ${engine.manifest?.version || "missing"}`,
|
|
@@ -447,19 +590,19 @@ function showDiagnostics(ctx) {
|
|
|
447
590
|
);
|
|
448
591
|
}
|
|
449
592
|
|
|
450
|
-
function showEngineManager(ctx) {
|
|
593
|
+
function showEngineManager(ctx, engineId = getModel(readSettings(ctx.api.kv).model).engine) {
|
|
451
594
|
const settings = readSettings(ctx.api.kv);
|
|
452
|
-
const status = getEngineStatus(
|
|
595
|
+
const status = getEngineStatus(engineId, ctx.options, settings);
|
|
453
596
|
const canImport = Boolean(status.resolvedBinary && status.source !== "managed");
|
|
454
597
|
const options = [
|
|
455
598
|
{
|
|
456
|
-
title:
|
|
599
|
+
title: `Use detected ${status.command} as managed engine`,
|
|
457
600
|
value: "import",
|
|
458
|
-
description: canImport ? status.resolvedBinary :
|
|
601
|
+
description: canImport ? status.resolvedBinary : `No external ${status.command} detected`,
|
|
459
602
|
disabled: !canImport,
|
|
460
603
|
},
|
|
461
604
|
{
|
|
462
|
-
title:
|
|
605
|
+
title: `Install managed ${engineId}`,
|
|
463
606
|
value: "install",
|
|
464
607
|
description: "Download the matching native engine from GitHub Releases.",
|
|
465
608
|
},
|
|
@@ -487,26 +630,26 @@ function showEngineManager(ctx) {
|
|
|
487
630
|
if (option.value === "diagnostics") showDiagnostics(ctx);
|
|
488
631
|
if (option.value === "import") {
|
|
489
632
|
try {
|
|
490
|
-
const result = await importManagedEngine(
|
|
633
|
+
const result = await importManagedEngine(engineId, status.resolvedBinary, ctx.options, settings);
|
|
491
634
|
toast(ctx.api, `Managed engine imported: ${result.managedBinary}`, "success");
|
|
492
|
-
showEngineManager(ctx);
|
|
635
|
+
showEngineManager(ctx, engineId);
|
|
493
636
|
} catch (error) {
|
|
494
637
|
showError(ctx, "Engine import failed", error);
|
|
495
638
|
}
|
|
496
639
|
}
|
|
497
640
|
if (option.value === "install") {
|
|
498
641
|
try {
|
|
499
|
-
await ensureEngineReady(ctx, settings);
|
|
500
|
-
showEngineManager(ctx);
|
|
642
|
+
await ensureEngineReady(ctx, settings, { engine: engineId });
|
|
643
|
+
showEngineManager(ctx, engineId);
|
|
501
644
|
} catch (error) {
|
|
502
645
|
showError(ctx, "Engine install failed", error);
|
|
503
646
|
}
|
|
504
647
|
}
|
|
505
648
|
if (option.value === "remove") {
|
|
506
649
|
try {
|
|
507
|
-
await removeManagedEngine(
|
|
650
|
+
await removeManagedEngine(engineId, ctx.options, settings);
|
|
508
651
|
toast(ctx.api, "Managed engine removed");
|
|
509
|
-
showEngineManager(ctx);
|
|
652
|
+
showEngineManager(ctx, engineId);
|
|
510
653
|
} catch (error) {
|
|
511
654
|
showError(ctx, "Engine remove failed", error);
|
|
512
655
|
}
|
|
@@ -530,7 +673,7 @@ async function downloadActiveModel(ctx) {
|
|
|
530
673
|
const settings = readSettings(ctx.api.kv);
|
|
531
674
|
const model = getModel(settings.model);
|
|
532
675
|
try {
|
|
533
|
-
await ensureEngineReady(ctx, settings);
|
|
676
|
+
await ensureEngineReady(ctx, settings, model);
|
|
534
677
|
await ensureDownloaded(ctx, model, settings);
|
|
535
678
|
showSettings(ctx);
|
|
536
679
|
} catch (error) {
|
|
@@ -538,121 +681,80 @@ async function downloadActiveModel(ctx) {
|
|
|
538
681
|
}
|
|
539
682
|
}
|
|
540
683
|
|
|
541
|
-
function
|
|
684
|
+
function showRecordingSettings(ctx) {
|
|
685
|
+
const settings = readSettings(ctx.api.kv);
|
|
686
|
+
|
|
687
|
+
setDialog(ctx, "medium", () =>
|
|
688
|
+
ctx.api.ui.DialogSelect({
|
|
689
|
+
title: "Recording",
|
|
690
|
+
options: [
|
|
691
|
+
{ title: "Record key", value: "key", description: settings.recordingHotkey || "not set" },
|
|
692
|
+
{ title: "Toggle recording", value: "toggle", description: "Press once to start and again to transcribe.", disabled: true },
|
|
693
|
+
{ title: "Hold to talk", value: "hold", description: "Unavailable until OpenCode provides key-release events.", disabled: true },
|
|
694
|
+
],
|
|
695
|
+
onSelect: (option) => {
|
|
696
|
+
if (option.value === "key") showRecordingHotkeyPicker(ctx);
|
|
697
|
+
},
|
|
698
|
+
}),
|
|
699
|
+
);
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
function showTranscriptionSettings(ctx) {
|
|
542
703
|
const settings = readSettings(ctx.api.kv);
|
|
543
704
|
const model = getModel(settings.model);
|
|
544
705
|
const downloaded = isModelDownloaded(model, ctx.options, settings);
|
|
545
706
|
|
|
546
|
-
setDialog(ctx, "
|
|
707
|
+
setDialog(ctx, "medium", () =>
|
|
547
708
|
ctx.api.ui.DialogSelect({
|
|
548
|
-
title: "
|
|
709
|
+
title: "Transcription",
|
|
549
710
|
options: [
|
|
550
|
-
{
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
},
|
|
555
|
-
{
|
|
556
|
-
title: downloaded ? "Re-download active model" : "Download active model",
|
|
557
|
-
value: "download",
|
|
558
|
-
description: `${model.name} · ${formatSize(model)}`,
|
|
559
|
-
},
|
|
560
|
-
{
|
|
561
|
-
title: "Hold hotkey",
|
|
562
|
-
value: "hotkey",
|
|
563
|
-
description: settings.hotkey ? `hold ${settings.hotkey}` : "disabled",
|
|
564
|
-
},
|
|
565
|
-
{
|
|
566
|
-
title: "Toggle hotkey",
|
|
567
|
-
value: "toggleHotkey",
|
|
568
|
-
description: settings.toggleHotkey || "disabled",
|
|
569
|
-
},
|
|
570
|
-
{
|
|
571
|
-
title: "Submit hotkey",
|
|
572
|
-
value: "submitHotkey",
|
|
573
|
-
description: settings.submitHotkey || "disabled",
|
|
574
|
-
},
|
|
575
|
-
{
|
|
576
|
-
title: "Microphone",
|
|
577
|
-
value: "mic",
|
|
578
|
-
description: settings.mic || "system default",
|
|
579
|
-
},
|
|
580
|
-
{
|
|
581
|
-
title: "Language",
|
|
582
|
-
value: "language",
|
|
583
|
-
description: settings.language,
|
|
584
|
-
},
|
|
585
|
-
{
|
|
586
|
-
title: "Auto-submit after /voice",
|
|
587
|
-
value: "autoSubmit",
|
|
588
|
-
description: settings.autoSubmit ? "enabled" : "disabled",
|
|
589
|
-
},
|
|
590
|
-
{
|
|
591
|
-
title: "Download directory",
|
|
592
|
-
value: "downloadDir",
|
|
593
|
-
description: settings.downloadDir || getCacheDir(ctx.options, settings),
|
|
594
|
-
},
|
|
595
|
-
{
|
|
596
|
-
title: "Native engine",
|
|
597
|
-
value: "engine",
|
|
598
|
-
description: `${getEngineStatus("whisper.cpp", ctx.options, settings).source} · whisper.cpp`,
|
|
599
|
-
},
|
|
600
|
-
{
|
|
601
|
-
title: "Diagnostics",
|
|
602
|
-
value: "diagnostics",
|
|
603
|
-
description: "Check recorder, whisper-cli, and model paths.",
|
|
604
|
-
},
|
|
605
|
-
{
|
|
606
|
-
title: "Show first-run setup again",
|
|
607
|
-
value: "firstRun",
|
|
608
|
-
description: "Open the initial model picker.",
|
|
609
|
-
},
|
|
711
|
+
{ title: "Model", value: "model", description: `${model.name} · ${downloaded ? "ready" : "not downloaded"}` },
|
|
712
|
+
{ title: downloaded ? "Re-download model" : "Download model", value: "download", description: `${model.name} · ${formatSize(model)}` },
|
|
713
|
+
{ title: "Language", value: "language", description: settings.language === "auto" ? "auto detect" : settings.language },
|
|
714
|
+
{ title: "Auto-submit", value: "autoSubmit", description: settings.autoSubmit ? "enabled" : "disabled" },
|
|
715
|
+
{ title: "Submit key", value: "submitHotkey", description: settings.submitHotkey || "disabled" },
|
|
610
716
|
],
|
|
611
717
|
onSelect: (option) => {
|
|
612
718
|
if (option.value === "model") showModelPicker(ctx, false);
|
|
613
719
|
if (option.value === "download") downloadActiveModel(ctx);
|
|
614
|
-
if (option.value === "
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
value: settings.hotkey,
|
|
619
|
-
onConfirm: (value) => {
|
|
620
|
-
writeSetting(ctx.api.kv, "hotkey", value.trim());
|
|
621
|
-
ctx.registerCommands();
|
|
622
|
-
showSettings(ctx);
|
|
623
|
-
},
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
if (option.value === "toggleHotkey") {
|
|
627
|
-
showPrompt(ctx, {
|
|
628
|
-
title: "Toggle hotkey",
|
|
629
|
-
placeholder: "ctrl+r",
|
|
630
|
-
value: settings.toggleHotkey,
|
|
631
|
-
onConfirm: (value) => {
|
|
632
|
-
writeSetting(ctx.api.kv, "toggleHotkey", value.trim());
|
|
633
|
-
ctx.registerCommands();
|
|
634
|
-
showSettings(ctx);
|
|
635
|
-
},
|
|
636
|
-
});
|
|
720
|
+
if (option.value === "language") showLanguagePicker(ctx);
|
|
721
|
+
if (option.value === "autoSubmit") {
|
|
722
|
+
writeSetting(ctx.api.kv, "autoSubmit", !settings.autoSubmit);
|
|
723
|
+
showTranscriptionSettings(ctx);
|
|
637
724
|
}
|
|
638
725
|
if (option.value === "submitHotkey") {
|
|
639
726
|
showPrompt(ctx, {
|
|
640
|
-
title: "Submit
|
|
727
|
+
title: "Submit recording key",
|
|
641
728
|
placeholder: "leader r or empty to disable",
|
|
642
729
|
value: settings.submitHotkey,
|
|
643
730
|
onConfirm: (value) => {
|
|
644
731
|
writeSetting(ctx.api.kv, "submitHotkey", value.trim());
|
|
645
732
|
ctx.registerCommands();
|
|
646
|
-
|
|
733
|
+
showTranscriptionSettings(ctx);
|
|
647
734
|
},
|
|
648
735
|
});
|
|
649
736
|
}
|
|
737
|
+
},
|
|
738
|
+
}),
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
function showSystemSettings(ctx) {
|
|
743
|
+
const settings = readSettings(ctx.api.kv);
|
|
744
|
+
const model = getModel(settings.model);
|
|
745
|
+
|
|
746
|
+
setDialog(ctx, "medium", () =>
|
|
747
|
+
ctx.api.ui.DialogSelect({
|
|
748
|
+
title: "Audio and system",
|
|
749
|
+
options: [
|
|
750
|
+
{ title: "Microphone", value: "mic", description: settings.mic || "system default" },
|
|
751
|
+
{ title: "Download directory", value: "downloadDir", description: settings.downloadDir || getCacheDir(ctx.options, settings) },
|
|
752
|
+
{ title: "Native engine", value: "engine", description: `${getEngineStatus(model.engine, ctx.options, settings).source} · ${model.engine}` },
|
|
753
|
+
{ title: "Diagnostics", value: "diagnostics", description: "Check recorder, runtimes, and model paths." },
|
|
754
|
+
{ title: "Run setup again", value: "firstRun", description: "Open the first-run model picker." },
|
|
755
|
+
],
|
|
756
|
+
onSelect: (option) => {
|
|
650
757
|
if (option.value === "mic") showMicrophonePicker(ctx);
|
|
651
|
-
if (option.value === "language") showLanguagePicker(ctx);
|
|
652
|
-
if (option.value === "autoSubmit") {
|
|
653
|
-
writeSetting(ctx.api.kv, "autoSubmit", !settings.autoSubmit);
|
|
654
|
-
showSettings(ctx);
|
|
655
|
-
}
|
|
656
758
|
if (option.value === "downloadDir") {
|
|
657
759
|
showPrompt(ctx, {
|
|
658
760
|
title: "Download directory",
|
|
@@ -660,7 +762,7 @@ function showSettings(ctx) {
|
|
|
660
762
|
value: settings.downloadDir,
|
|
661
763
|
onConfirm: (value) => {
|
|
662
764
|
writeSetting(ctx.api.kv, "downloadDir", value.trim());
|
|
663
|
-
|
|
765
|
+
showSystemSettings(ctx);
|
|
664
766
|
},
|
|
665
767
|
});
|
|
666
768
|
}
|
|
@@ -672,6 +774,27 @@ function showSettings(ctx) {
|
|
|
672
774
|
);
|
|
673
775
|
}
|
|
674
776
|
|
|
777
|
+
function showSettings(ctx) {
|
|
778
|
+
const settings = readSettings(ctx.api.kv);
|
|
779
|
+
const model = getModel(settings.model);
|
|
780
|
+
|
|
781
|
+
setDialog(ctx, "large", () =>
|
|
782
|
+
ctx.api.ui.DialogSelect({
|
|
783
|
+
title: "Voice settings",
|
|
784
|
+
options: [
|
|
785
|
+
{ title: "Recording", value: "recording", description: `${settings.recordingHotkey} · toggle` },
|
|
786
|
+
{ title: "Transcription", value: "transcription", description: `${model.name} · ${settings.language === "auto" ? "auto language" : settings.language}` },
|
|
787
|
+
{ title: "Audio and system", value: "system", description: `${settings.mic || "default microphone"} · ${model.engine}` },
|
|
788
|
+
],
|
|
789
|
+
onSelect: (option) => {
|
|
790
|
+
if (option.value === "recording") showRecordingSettings(ctx);
|
|
791
|
+
if (option.value === "transcription") showTranscriptionSettings(ctx);
|
|
792
|
+
if (option.value === "system") showSystemSettings(ctx);
|
|
793
|
+
},
|
|
794
|
+
}),
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
|
|
675
798
|
async function appendTranscription(ctx, text, submit) {
|
|
676
799
|
const next = text.endsWith(" ") ? text : `${text} `;
|
|
677
800
|
await ctx.api.client.tui.appendPrompt({ text: next });
|
|
@@ -711,7 +834,7 @@ async function startVoice(ctx, submit = false, hold = false) {
|
|
|
711
834
|
const model = getModel(settings.model);
|
|
712
835
|
if (!isModelDownloaded(model, ctx.options, settings)) {
|
|
713
836
|
try {
|
|
714
|
-
await ensureEngineReady(ctx, settings);
|
|
837
|
+
await ensureEngineReady(ctx, settings, model);
|
|
715
838
|
await ensureDownloaded(ctx, model, settings);
|
|
716
839
|
ctx.api.ui.dialog.clear();
|
|
717
840
|
} catch (error) {
|
|
@@ -721,7 +844,7 @@ async function startVoice(ctx, submit = false, hold = false) {
|
|
|
721
844
|
}
|
|
722
845
|
|
|
723
846
|
try {
|
|
724
|
-
await ensureEngineReady(ctx, settings);
|
|
847
|
+
await ensureEngineReady(ctx, settings, model);
|
|
725
848
|
await ensureRecorderReady(ctx, settings);
|
|
726
849
|
} catch (error) {
|
|
727
850
|
showError(ctx, "Voice runtime setup failed", error);
|
|
@@ -731,7 +854,7 @@ async function startVoice(ctx, submit = false, hold = false) {
|
|
|
731
854
|
try {
|
|
732
855
|
ctx.runtime.pendingSubmit = submit || settings.autoSubmit;
|
|
733
856
|
await ctx.runtime.start(settings);
|
|
734
|
-
toast(ctx.api, hold ? `Recording. Release ${settings.
|
|
857
|
+
toast(ctx.api, hold ? `Recording. Release ${settings.recordingHotkey || "the recording key"} to stop.` : submit ? "Recording for submit. Run /voice-submit again to stop." : "Recording. Run /voice again to stop.");
|
|
735
858
|
} catch (error) {
|
|
736
859
|
toast(ctx.api, error instanceof Error ? error.message : String(error), "error");
|
|
737
860
|
}
|
|
@@ -764,18 +887,9 @@ function stopVoice(ctx) {
|
|
|
764
887
|
|
|
765
888
|
function buildBindings(settings) {
|
|
766
889
|
const bindings = [];
|
|
767
|
-
const holdHotkey = settings.hotkey.toLowerCase();
|
|
768
|
-
const toggleHotkey = settings.toggleHotkey.toLowerCase();
|
|
769
|
-
|
|
770
|
-
if (settings.hotkey) {
|
|
771
|
-
bindings.push(
|
|
772
|
-
{ key: settings.hotkey, event: "press", preventDefault: true, cmd: "voice.hold.start", desc: "Hold to record voice" },
|
|
773
|
-
{ key: settings.hotkey, event: "release", preventDefault: true, cmd: "voice.hold.finish", desc: "Release to transcribe voice" },
|
|
774
|
-
);
|
|
775
|
-
}
|
|
776
890
|
|
|
777
|
-
if (settings.
|
|
778
|
-
bindings.push({ key: settings.
|
|
891
|
+
if (settings.recordingHotkey) {
|
|
892
|
+
bindings.push({ key: settings.recordingHotkey, event: "press", preventDefault: true, cmd: "voice.record", desc: "Toggle voice recording" });
|
|
779
893
|
}
|
|
780
894
|
|
|
781
895
|
if (settings.submitHotkey) {
|
|
@@ -847,6 +961,9 @@ function buildCommands(ctx) {
|
|
|
847
961
|
|
|
848
962
|
const plugin = {
|
|
849
963
|
id: PLUGIN_ID,
|
|
964
|
+
// OpenCode 1.18 validates every plugin module through its server contract,
|
|
965
|
+
// even when the plugin only contributes TUI commands.
|
|
966
|
+
server: async () => ({}),
|
|
850
967
|
tui: async (api, options = {}) => {
|
|
851
968
|
const runtime = new VoiceRuntime(options || {});
|
|
852
969
|
const ctx = {
|
|
@@ -879,3 +996,4 @@ const plugin = {
|
|
|
879
996
|
};
|
|
880
997
|
|
|
881
998
|
export default plugin;
|
|
999
|
+
|