@hxnnxs/opencode-voice 0.2.2 → 0.2.4
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 +13 -0
- package/PUBLISHING.md +2 -2
- package/README.md +17 -9
- package/bin/opencode-voice.js +17 -4
- package/docs/README.es.md +3 -3
- package/docs/README.ru.md +10 -6
- package/docs/README.zh.md +3 -3
- package/index.js +231 -174
- package/lib/engine.js +161 -82
- package/lib/engines.js +14 -8
- package/lib/handy-model-catalog.js +79 -1
- package/lib/wav.js +91 -0
- package/package.json +10 -4
- package/tui.js +108 -0
package/index.js
CHANGED
|
@@ -36,16 +36,15 @@ function readSettings(kv) {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
function writeSetting(kv, name, value) {
|
|
39
|
-
kv.set(KV[name], value);
|
|
39
|
+
return kv.set(KV[name], value);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
function migrateSettings(kv) {
|
|
42
|
+
async function migrateSettings(kv) {
|
|
43
43
|
// Early builds stored separate hold and toggle keys. Preserve the user's
|
|
44
44
|
// explicit hold key first, otherwise retain the old toggle binding.
|
|
45
|
-
const holdHotkey = kv.get(KV.hotkey, undefined);
|
|
46
45
|
if (!kv.get(KV.recordingHotkey, undefined)) {
|
|
47
46
|
const configuredHotkey = String(kv.get(KV.hotkey, "")).trim();
|
|
48
|
-
kv.set(KV.recordingHotkey, configuredHotkey || kv.get(KV.toggleHotkey, DEFAULT_SETTINGS.recordingHotkey));
|
|
47
|
+
await kv.set(KV.recordingHotkey, configuredHotkey || kv.get(KV.toggleHotkey, DEFAULT_SETTINGS.recordingHotkey));
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
|
|
@@ -230,8 +229,13 @@ async function ensureEngineReady(ctx, settings, model = getModel(settings.model)
|
|
|
230
229
|
const commandOptions = { ...ctx.options, downloadDir: settings.downloadDir };
|
|
231
230
|
const current = getEngineStatus(engineId, ctx.options, settings);
|
|
232
231
|
if (current.resolvedBinary) {
|
|
233
|
-
const probe = await probeEngine(engineId, current.resolvedBinary
|
|
232
|
+
const probe = await probeEngine(engineId, current.resolvedBinary, {
|
|
233
|
+
requireUpdatedEngine: model.id ? Boolean(model.requiresUpdatedEngine) : true,
|
|
234
|
+
});
|
|
234
235
|
if (probe.ok) return true;
|
|
236
|
+
if (model.requiresUpdatedEngine && ["option", "env"].includes(current.source)) {
|
|
237
|
+
throw new Error(`${probe.message}. Update the configured binary: ${current.resolvedBinary}`);
|
|
238
|
+
}
|
|
235
239
|
}
|
|
236
240
|
|
|
237
241
|
renderEngineInstallStatus(ctx, engineId, { state: "registry", downloaded: 0, total: 0, percent: 0, attempt: 1, attempts: 5 });
|
|
@@ -294,8 +298,8 @@ function showModelPicker(ctx, firstRun = false) {
|
|
|
294
298
|
],
|
|
295
299
|
onSelect: async (option) => {
|
|
296
300
|
if (option.value === "__skip") {
|
|
297
|
-
writeSetting(ctx.api.kv, "onboardingDone", true);
|
|
298
|
-
writeSetting(ctx.api.kv, "setupSkipped", true);
|
|
301
|
+
await writeSetting(ctx.api.kv, "onboardingDone", true);
|
|
302
|
+
await writeSetting(ctx.api.kv, "setupSkipped", true);
|
|
299
303
|
ctx.api.ui.dialog.clear();
|
|
300
304
|
toast(ctx.api, "Voice setup skipped. Use /voice-settings when ready.");
|
|
301
305
|
return;
|
|
@@ -305,9 +309,9 @@ function showModelPicker(ctx, firstRun = false) {
|
|
|
305
309
|
if (!model?.implemented) return;
|
|
306
310
|
|
|
307
311
|
const nextSettings = { ...readSettings(ctx.api.kv), model: model.id };
|
|
308
|
-
writeSetting(ctx.api.kv, "model", model.id);
|
|
309
|
-
writeSetting(ctx.api.kv, "onboardingDone", true);
|
|
310
|
-
writeSetting(ctx.api.kv, "setupSkipped", false);
|
|
312
|
+
await writeSetting(ctx.api.kv, "model", model.id);
|
|
313
|
+
await writeSetting(ctx.api.kv, "onboardingDone", true);
|
|
314
|
+
await writeSetting(ctx.api.kv, "setupSkipped", false);
|
|
311
315
|
|
|
312
316
|
try {
|
|
313
317
|
await ensureEngineReady(ctx, nextSettings, model);
|
|
@@ -333,123 +337,123 @@ function showPrompt(ctx, input) {
|
|
|
333
337
|
title: input.title,
|
|
334
338
|
placeholder: input.placeholder,
|
|
335
339
|
value: input.value,
|
|
336
|
-
onConfirm: (value) => {
|
|
337
|
-
input.onConfirm(value);
|
|
340
|
+
onConfirm: async (value) => {
|
|
341
|
+
return input.onConfirm(value);
|
|
338
342
|
},
|
|
339
343
|
onCancel: () => showSettings(ctx),
|
|
340
344
|
}),
|
|
341
345
|
);
|
|
342
346
|
}
|
|
343
347
|
|
|
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"],
|
|
348
|
+
const WHISPER_LANGUAGES = [
|
|
349
|
+
["Afrikaans", "af"],
|
|
350
|
+
["Amharic", "am"],
|
|
351
|
+
["Arabic", "ar"],
|
|
352
|
+
["Assamese", "as"],
|
|
353
|
+
["Azerbaijani", "az"],
|
|
354
|
+
["Bashkir", "ba"],
|
|
355
|
+
["Belarusian", "be"],
|
|
356
|
+
["Bulgarian", "bg"],
|
|
357
|
+
["Bengali", "bn"],
|
|
358
|
+
["Tibetan", "bo"],
|
|
359
|
+
["Breton", "br"],
|
|
360
|
+
["Bosnian", "bs"],
|
|
361
|
+
["Catalan", "ca"],
|
|
362
|
+
["Czech", "cs"],
|
|
363
|
+
["Welsh", "cy"],
|
|
364
|
+
["Danish", "da"],
|
|
365
|
+
["German", "de"],
|
|
366
|
+
["Greek", "el"],
|
|
367
|
+
["English", "en"],
|
|
368
|
+
["Spanish", "es"],
|
|
369
|
+
["Estonian", "et"],
|
|
370
|
+
["Basque", "eu"],
|
|
371
|
+
["Persian", "fa"],
|
|
372
|
+
["Finnish", "fi"],
|
|
373
|
+
["Faroese", "fo"],
|
|
374
|
+
["French", "fr"],
|
|
375
|
+
["Galician", "gl"],
|
|
376
|
+
["Gujarati", "gu"],
|
|
377
|
+
["Hausa", "ha"],
|
|
378
|
+
["Hawaiian", "haw"],
|
|
379
|
+
["Hebrew", "he"],
|
|
380
|
+
["Hindi", "hi"],
|
|
381
|
+
["Croatian", "hr"],
|
|
382
|
+
["Haitian Creole", "ht"],
|
|
383
|
+
["Hungarian", "hu"],
|
|
384
|
+
["Armenian", "hy"],
|
|
385
|
+
["Indonesian", "id"],
|
|
386
|
+
["Icelandic", "is"],
|
|
387
|
+
["Italian", "it"],
|
|
388
|
+
["Japanese", "ja"],
|
|
389
|
+
["Javanese", "jw"],
|
|
390
|
+
["Georgian", "ka"],
|
|
391
|
+
["Kazakh", "kk"],
|
|
392
|
+
["Khmer", "km"],
|
|
393
|
+
["Kannada", "kn"],
|
|
394
|
+
["Korean", "ko"],
|
|
395
|
+
["Latin", "la"],
|
|
396
|
+
["Luxembourgish", "lb"],
|
|
397
|
+
["Lingala", "ln"],
|
|
398
|
+
["Lao", "lo"],
|
|
399
|
+
["Lithuanian", "lt"],
|
|
400
|
+
["Latvian", "lv"],
|
|
401
|
+
["Malagasy", "mg"],
|
|
402
|
+
["Maori", "mi"],
|
|
403
|
+
["Macedonian", "mk"],
|
|
404
|
+
["Malayalam", "ml"],
|
|
405
|
+
["Mongolian", "mn"],
|
|
406
|
+
["Marathi", "mr"],
|
|
407
|
+
["Malay", "ms"],
|
|
408
|
+
["Maltese", "mt"],
|
|
409
|
+
["Myanmar", "my"],
|
|
410
|
+
["Nepali", "ne"],
|
|
411
|
+
["Dutch", "nl"],
|
|
412
|
+
["Norwegian Nynorsk", "nn"],
|
|
413
|
+
["Norwegian", "no"],
|
|
414
|
+
["Occitan", "oc"],
|
|
415
|
+
["Punjabi", "pa"],
|
|
416
|
+
["Pashto", "ps"],
|
|
417
|
+
["Portuguese", "pt"],
|
|
418
|
+
["Romanian", "ro"],
|
|
419
|
+
["Russian", "ru"],
|
|
420
|
+
["Sanskrit", "sa"],
|
|
421
|
+
["Sindhi", "sd"],
|
|
422
|
+
["Sinhala", "si"],
|
|
423
|
+
["Slovak", "sk"],
|
|
424
|
+
["Slovenian", "sl"],
|
|
425
|
+
["Shona", "sn"],
|
|
426
|
+
["Somali", "so"],
|
|
427
|
+
["Albanian", "sq"],
|
|
428
|
+
["Serbian", "sr"],
|
|
429
|
+
["Sundanese", "su"],
|
|
430
|
+
["Swedish", "sv"],
|
|
431
|
+
["Swahili", "sw"],
|
|
432
|
+
["Tamil", "ta"],
|
|
433
|
+
["Telugu", "te"],
|
|
434
|
+
["Tajik", "tg"],
|
|
435
|
+
["Thai", "th"],
|
|
436
|
+
["Turkmen", "tk"],
|
|
437
|
+
["Tagalog", "tl"],
|
|
438
|
+
["Turkish", "tr"],
|
|
439
|
+
["Tatar", "tt"],
|
|
440
|
+
["Ukrainian", "uk"],
|
|
441
|
+
["Urdu", "ur"],
|
|
442
|
+
["Uzbek", "uz"],
|
|
443
|
+
["Vietnamese", "vi"],
|
|
440
444
|
["Yiddish", "yi"],
|
|
441
445
|
["Yoruba", "yo"],
|
|
442
446
|
["Chinese", "zh"],
|
|
443
447
|
["Cantonese", "yue"],
|
|
444
448
|
["Zulu", "zu"],
|
|
445
449
|
];
|
|
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." },
|
|
450
|
+
|
|
451
|
+
function showLanguagePicker(ctx) {
|
|
452
|
+
const settings = readSettings(ctx.api.kv);
|
|
453
|
+
const options = [
|
|
454
|
+
{ title: "Auto detect", value: "auto", description: "Let Whisper detect the language." },
|
|
455
|
+
...WHISPER_LANGUAGES.map(([name, code]) => ({ title: name, value: code })),
|
|
456
|
+
{ title: "Custom code", value: "__custom", description: "Enter a Whisper language code manually." },
|
|
453
457
|
];
|
|
454
458
|
|
|
455
459
|
setDialog(ctx, "medium", () =>
|
|
@@ -457,21 +461,21 @@ function showLanguagePicker(ctx) {
|
|
|
457
461
|
title: "Voice language",
|
|
458
462
|
current: settings.language,
|
|
459
463
|
options,
|
|
460
|
-
onSelect: (option) => {
|
|
464
|
+
onSelect: async (option) => {
|
|
461
465
|
if (option.value === "__custom") {
|
|
462
466
|
showPrompt(ctx, {
|
|
463
467
|
title: "Custom language code",
|
|
464
468
|
placeholder: "ru, en, de, ...",
|
|
465
469
|
value: settings.language === "auto" ? "" : settings.language,
|
|
466
|
-
onConfirm: (value) => {
|
|
467
|
-
writeSetting(ctx.api.kv, "language", value.trim() || "auto");
|
|
470
|
+
onConfirm: async (value) => {
|
|
471
|
+
await writeSetting(ctx.api.kv, "language", value.trim() || "auto");
|
|
468
472
|
showSettings(ctx);
|
|
469
473
|
},
|
|
470
474
|
});
|
|
471
475
|
return;
|
|
472
476
|
}
|
|
473
477
|
|
|
474
|
-
writeSetting(ctx.api.kv, "language", option.value);
|
|
478
|
+
await writeSetting(ctx.api.kv, "language", option.value);
|
|
475
479
|
showSettings(ctx);
|
|
476
480
|
},
|
|
477
481
|
}),
|
|
@@ -481,32 +485,32 @@ function showLanguagePicker(ctx) {
|
|
|
481
485
|
function showMicrophonePicker(ctx) {
|
|
482
486
|
const settings = readSettings(ctx.api.kv);
|
|
483
487
|
const commandOptions = { ...ctx.options, downloadDir: settings.downloadDir, skipFfmpegStaticInstall: true };
|
|
484
|
-
const placeholder = process.platform === "win32" ? "default,
|
|
488
|
+
const placeholder = process.platform === "win32" ? "default, Microphone (Name)" : "default, hw:0,0, pulse, :0, ...";
|
|
485
489
|
const devices = listMicrophones(commandOptions);
|
|
486
490
|
setDialog(ctx, "large", () =>
|
|
487
491
|
ctx.api.ui.DialogSelect({
|
|
488
492
|
title: "Voice microphone",
|
|
489
493
|
current: settings.mic || "",
|
|
490
494
|
options: [
|
|
491
|
-
{ title: "System default", value: "", description: "Use the default input device." },
|
|
492
|
-
...devices.map((device) => ({ title: device, value: device })),
|
|
495
|
+
{ title: "System default", value: "", description: process.platform === "win32" ? "Try enumerated DirectShow audio devices in order." : "Use the default input device." },
|
|
496
|
+
...devices.filter((device) => device !== "default").map((device) => ({ title: device, value: device })),
|
|
493
497
|
{ title: "Custom device", value: "__custom", description: "Enter ffmpeg/arecord device manually." },
|
|
494
498
|
],
|
|
495
|
-
onSelect: (option) => {
|
|
499
|
+
onSelect: async (option) => {
|
|
496
500
|
if (option.value === "__custom") {
|
|
497
501
|
showPrompt(ctx, {
|
|
498
502
|
title: "Custom microphone device",
|
|
499
503
|
placeholder,
|
|
500
504
|
value: settings.mic,
|
|
501
|
-
onConfirm: (value) => {
|
|
502
|
-
writeSetting(ctx.api.kv, "mic", value.trim());
|
|
505
|
+
onConfirm: async (value) => {
|
|
506
|
+
await writeSetting(ctx.api.kv, "mic", value.trim());
|
|
503
507
|
showSettings(ctx);
|
|
504
508
|
},
|
|
505
509
|
});
|
|
506
510
|
return;
|
|
507
511
|
}
|
|
508
512
|
|
|
509
|
-
writeSetting(ctx.api.kv, "mic", option.value);
|
|
513
|
+
await writeSetting(ctx.api.kv, "mic", option.value);
|
|
510
514
|
showSettings(ctx);
|
|
511
515
|
},
|
|
512
516
|
}),
|
|
@@ -527,14 +531,14 @@ function showRecordingHotkeyPicker(ctx) {
|
|
|
527
531
|
title: "Record key",
|
|
528
532
|
current: presets.some((preset) => preset.value === settings.recordingHotkey) ? settings.recordingHotkey : "__custom",
|
|
529
533
|
options: presets,
|
|
530
|
-
onSelect: (option) => {
|
|
534
|
+
onSelect: async (option) => {
|
|
531
535
|
if (option.value === "__custom") {
|
|
532
536
|
showPrompt(ctx, {
|
|
533
537
|
title: "Custom recording key",
|
|
534
538
|
placeholder: "alt+shift+r",
|
|
535
539
|
value: settings.recordingHotkey,
|
|
536
|
-
onConfirm: (value) => {
|
|
537
|
-
writeSetting(ctx.api.kv, "recordingHotkey", value.trim());
|
|
540
|
+
onConfirm: async (value) => {
|
|
541
|
+
await writeSetting(ctx.api.kv, "recordingHotkey", value.trim());
|
|
538
542
|
ctx.registerCommands();
|
|
539
543
|
showRecordingSettings(ctx);
|
|
540
544
|
},
|
|
@@ -542,7 +546,7 @@ function showRecordingHotkeyPicker(ctx) {
|
|
|
542
546
|
return;
|
|
543
547
|
}
|
|
544
548
|
|
|
545
|
-
writeSetting(ctx.api.kv, "recordingHotkey", option.value);
|
|
549
|
+
await writeSetting(ctx.api.kv, "recordingHotkey", option.value);
|
|
546
550
|
ctx.registerCommands();
|
|
547
551
|
showRecordingSettings(ctx);
|
|
548
552
|
},
|
|
@@ -565,6 +569,7 @@ function showDiagnostics(ctx) {
|
|
|
565
569
|
`Platform: ${process.platform}-${process.arch}`,
|
|
566
570
|
`Recorder: ffmpeg=${ffmpeg ? "yes" : "no"}${ffmpeg ? ` (${ffmpeg})` : ""}, arecord=${arecord ? "yes" : "no"}, sox=${sox ? "yes" : "no"}`,
|
|
567
571
|
`Recorder source: ${recorder.source}`,
|
|
572
|
+
`Last recorder log: ${ctx.runtime.recorderLog || "No recording attempted yet"}`,
|
|
568
573
|
`Managed recorder dir: ${recorder.managedDir}`,
|
|
569
574
|
`Managed recorder installed: ${recorder.managedInstalled ? "yes" : "no"}`,
|
|
570
575
|
`Managed recorder version: ${recorder.manifest?.version || "missing"}`,
|
|
@@ -692,7 +697,7 @@ function showRecordingSettings(ctx) {
|
|
|
692
697
|
{ title: "Toggle recording", value: "toggle", description: "Press once to start and again to transcribe.", disabled: true },
|
|
693
698
|
{ title: "Hold to talk", value: "hold", description: "Unavailable until OpenCode provides key-release events.", disabled: true },
|
|
694
699
|
],
|
|
695
|
-
onSelect: (option) => {
|
|
700
|
+
onSelect: async (option) => {
|
|
696
701
|
if (option.value === "key") showRecordingHotkeyPicker(ctx);
|
|
697
702
|
},
|
|
698
703
|
}),
|
|
@@ -714,12 +719,12 @@ function showTranscriptionSettings(ctx) {
|
|
|
714
719
|
{ title: "Auto-submit", value: "autoSubmit", description: settings.autoSubmit ? "enabled" : "disabled" },
|
|
715
720
|
{ title: "Submit key", value: "submitHotkey", description: settings.submitHotkey || "disabled" },
|
|
716
721
|
],
|
|
717
|
-
onSelect: (option) => {
|
|
722
|
+
onSelect: async (option) => {
|
|
718
723
|
if (option.value === "model") showModelPicker(ctx, false);
|
|
719
724
|
if (option.value === "download") downloadActiveModel(ctx);
|
|
720
725
|
if (option.value === "language") showLanguagePicker(ctx);
|
|
721
726
|
if (option.value === "autoSubmit") {
|
|
722
|
-
writeSetting(ctx.api.kv, "autoSubmit", !settings.autoSubmit);
|
|
727
|
+
await writeSetting(ctx.api.kv, "autoSubmit", !settings.autoSubmit);
|
|
723
728
|
showTranscriptionSettings(ctx);
|
|
724
729
|
}
|
|
725
730
|
if (option.value === "submitHotkey") {
|
|
@@ -727,8 +732,8 @@ function showTranscriptionSettings(ctx) {
|
|
|
727
732
|
title: "Submit recording key",
|
|
728
733
|
placeholder: "leader r or empty to disable",
|
|
729
734
|
value: settings.submitHotkey,
|
|
730
|
-
onConfirm: (value) => {
|
|
731
|
-
writeSetting(ctx.api.kv, "submitHotkey", value.trim());
|
|
735
|
+
onConfirm: async (value) => {
|
|
736
|
+
await writeSetting(ctx.api.kv, "submitHotkey", value.trim());
|
|
732
737
|
ctx.registerCommands();
|
|
733
738
|
showTranscriptionSettings(ctx);
|
|
734
739
|
},
|
|
@@ -753,15 +758,15 @@ function showSystemSettings(ctx) {
|
|
|
753
758
|
{ title: "Diagnostics", value: "diagnostics", description: "Check recorder, runtimes, and model paths." },
|
|
754
759
|
{ title: "Run setup again", value: "firstRun", description: "Open the first-run model picker." },
|
|
755
760
|
],
|
|
756
|
-
onSelect: (option) => {
|
|
761
|
+
onSelect: async (option) => {
|
|
757
762
|
if (option.value === "mic") showMicrophonePicker(ctx);
|
|
758
763
|
if (option.value === "downloadDir") {
|
|
759
764
|
showPrompt(ctx, {
|
|
760
765
|
title: "Download directory",
|
|
761
766
|
placeholder: "~/.cache/opencode-voice",
|
|
762
767
|
value: settings.downloadDir,
|
|
763
|
-
onConfirm: (value) => {
|
|
764
|
-
writeSetting(ctx.api.kv, "downloadDir", value.trim());
|
|
768
|
+
onConfirm: async (value) => {
|
|
769
|
+
await writeSetting(ctx.api.kv, "downloadDir", value.trim());
|
|
765
770
|
showSystemSettings(ctx);
|
|
766
771
|
},
|
|
767
772
|
});
|
|
@@ -786,7 +791,7 @@ function showSettings(ctx) {
|
|
|
786
791
|
{ title: "Transcription", value: "transcription", description: `${model.name} · ${settings.language === "auto" ? "auto language" : settings.language}` },
|
|
787
792
|
{ title: "Audio and system", value: "system", description: `${settings.mic || "default microphone"} · ${model.engine}` },
|
|
788
793
|
],
|
|
789
|
-
onSelect: (option) => {
|
|
794
|
+
onSelect: async (option) => {
|
|
790
795
|
if (option.value === "recording") showRecordingSettings(ctx);
|
|
791
796
|
if (option.value === "transcription") showTranscriptionSettings(ctx);
|
|
792
797
|
if (option.value === "system") showSystemSettings(ctx);
|
|
@@ -818,11 +823,12 @@ async function stopAndTranscribe(ctx, submit) {
|
|
|
818
823
|
await appendTranscription(ctx, text, submit || settings.autoSubmit);
|
|
819
824
|
toast(ctx.api, submit || settings.autoSubmit ? "Transcribed and submitted" : "Transcribed", "success");
|
|
820
825
|
} catch (error) {
|
|
821
|
-
|
|
826
|
+
showError(ctx, "Voice transcription failed", error);
|
|
822
827
|
}
|
|
823
828
|
}
|
|
824
829
|
|
|
825
830
|
async function startVoice(ctx, submit = false, hold = false) {
|
|
831
|
+
if (ctx.starting) return;
|
|
826
832
|
if (ctx.runtime.isTranscribing()) {
|
|
827
833
|
toast(ctx.api, "Transcription is already running", "warning");
|
|
828
834
|
return;
|
|
@@ -830,15 +836,26 @@ async function startVoice(ctx, submit = false, hold = false) {
|
|
|
830
836
|
|
|
831
837
|
if (ctx.runtime.isRecording()) return;
|
|
832
838
|
|
|
839
|
+
const controller = new AbortController();
|
|
840
|
+
ctx.starting = controller;
|
|
841
|
+
try {
|
|
842
|
+
await prepareAndStartVoice(ctx, submit, hold, controller.signal);
|
|
843
|
+
} finally {
|
|
844
|
+
if (ctx.starting === controller) ctx.starting = null;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
async function prepareAndStartVoice(ctx, submit, hold, signal) {
|
|
833
849
|
const settings = readSettings(ctx.api.kv);
|
|
834
850
|
const model = getModel(settings.model);
|
|
835
851
|
if (!isModelDownloaded(model, ctx.options, settings)) {
|
|
836
852
|
try {
|
|
837
853
|
await ensureEngineReady(ctx, settings, model);
|
|
838
854
|
await ensureDownloaded(ctx, model, settings);
|
|
855
|
+
if (signal.aborted) return;
|
|
839
856
|
ctx.api.ui.dialog.clear();
|
|
840
857
|
} catch (error) {
|
|
841
|
-
showError(ctx, "Voice setup failed", error);
|
|
858
|
+
if (!signal.aborted) showError(ctx, "Voice setup failed", error);
|
|
842
859
|
return;
|
|
843
860
|
}
|
|
844
861
|
}
|
|
@@ -847,16 +864,18 @@ async function startVoice(ctx, submit = false, hold = false) {
|
|
|
847
864
|
await ensureEngineReady(ctx, settings, model);
|
|
848
865
|
await ensureRecorderReady(ctx, settings);
|
|
849
866
|
} catch (error) {
|
|
850
|
-
showError(ctx, "Voice runtime setup failed", error);
|
|
867
|
+
if (!signal.aborted) showError(ctx, "Voice runtime setup failed", error);
|
|
851
868
|
return;
|
|
852
869
|
}
|
|
853
870
|
|
|
871
|
+
if (signal.aborted) return;
|
|
854
872
|
try {
|
|
855
873
|
ctx.runtime.pendingSubmit = submit || settings.autoSubmit;
|
|
856
874
|
await ctx.runtime.start(settings);
|
|
875
|
+
if (signal.aborted) return;
|
|
857
876
|
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.");
|
|
858
877
|
} catch (error) {
|
|
859
|
-
|
|
878
|
+
if (!signal.aborted) showError(ctx, "Recorder start failed", error);
|
|
860
879
|
}
|
|
861
880
|
}
|
|
862
881
|
|
|
@@ -881,6 +900,7 @@ async function toggleVoice(ctx, submit = false) {
|
|
|
881
900
|
}
|
|
882
901
|
|
|
883
902
|
function stopVoice(ctx) {
|
|
903
|
+
ctx.starting?.abort();
|
|
884
904
|
ctx.runtime.cancel();
|
|
885
905
|
toast(ctx.api, "Voice recording cancelled");
|
|
886
906
|
}
|
|
@@ -959,38 +979,75 @@ function buildCommands(ctx) {
|
|
|
959
979
|
];
|
|
960
980
|
}
|
|
961
981
|
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
const settings = readSettings(api.kv);
|
|
974
|
-
ctx.disposeCommands = api.keymap.registerLayer({
|
|
975
|
-
priority: 100,
|
|
976
|
-
commands: buildCommands(ctx),
|
|
977
|
-
bindings: buildBindings(settings),
|
|
978
|
-
});
|
|
979
|
-
},
|
|
980
|
-
};
|
|
981
|
-
|
|
982
|
-
migrateSettings(api.kv);
|
|
983
|
-
ctx.registerCommands();
|
|
984
|
-
api.lifecycle.onDispose(() => {
|
|
982
|
+
export async function setupVoice(api, options = {}, context) {
|
|
983
|
+
const runtime = new VoiceRuntime(options);
|
|
984
|
+
let disposed = false;
|
|
985
|
+
const ctx = {
|
|
986
|
+
api,
|
|
987
|
+
options,
|
|
988
|
+
runtime,
|
|
989
|
+
starting: null,
|
|
990
|
+
disposeCommands: undefined,
|
|
991
|
+
registerCommands() {
|
|
992
|
+
if (context) return; // V2 reads settings reactively in its keymap layer.
|
|
985
993
|
if (ctx.disposeCommands) ctx.disposeCommands();
|
|
986
|
-
|
|
987
|
-
|
|
994
|
+
ctx.disposeCommands = api.keymap.registerLayer({
|
|
995
|
+
priority: 100,
|
|
996
|
+
commands: buildCommands(ctx),
|
|
997
|
+
bindings: buildBindings(readSettings(api.kv)),
|
|
998
|
+
});
|
|
999
|
+
},
|
|
1000
|
+
};
|
|
1001
|
+
|
|
1002
|
+
await migrateSettings(api.kv);
|
|
1003
|
+
if (context) {
|
|
1004
|
+
context.keymap.layer(() => ({
|
|
1005
|
+
mode: "global",
|
|
1006
|
+
priority: 100,
|
|
1007
|
+
commands: buildCommands(ctx).filter((command) => !command.hidden).map((command) => ({
|
|
1008
|
+
id: command.name,
|
|
1009
|
+
title: command.title,
|
|
1010
|
+
description: command.desc,
|
|
1011
|
+
group: command.category,
|
|
1012
|
+
palette: true,
|
|
1013
|
+
slash: { name: command.slashName, aliases: command.slashAliases },
|
|
1014
|
+
bind: false,
|
|
1015
|
+
run: command.run,
|
|
1016
|
+
})),
|
|
1017
|
+
}));
|
|
1018
|
+
context.keymap.layer(() => ({
|
|
1019
|
+
priority: 100,
|
|
1020
|
+
commands: buildBindings(readSettings(api.kv)).map((binding) => ({
|
|
1021
|
+
bind: binding.key,
|
|
1022
|
+
title: binding.desc,
|
|
1023
|
+
group: "Voice",
|
|
1024
|
+
run: () => context.keymap.dispatch(binding.cmd),
|
|
1025
|
+
})),
|
|
1026
|
+
}));
|
|
1027
|
+
} else {
|
|
1028
|
+
ctx.registerCommands();
|
|
1029
|
+
}
|
|
988
1030
|
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
1031
|
+
const timer = setTimeout(() => {
|
|
1032
|
+
if (!disposed && shouldShowStartupModelPicker(ctx)) showModelPicker(ctx, true);
|
|
1033
|
+
}, 250);
|
|
1034
|
+
return () => {
|
|
1035
|
+
disposed = true;
|
|
1036
|
+
clearTimeout(timer);
|
|
1037
|
+
ctx.starting?.abort();
|
|
1038
|
+
ctx.disposeCommands?.();
|
|
1039
|
+
api.dispose?.();
|
|
1040
|
+
return runtime.cancel();
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// Keep the V1 package entrypoint and accept existing V2 server configurations.
|
|
1045
|
+
// The server has no voice functionality; the actual V2 setup lives in ./tui.
|
|
1046
|
+
export default {
|
|
1047
|
+
id: PLUGIN_ID,
|
|
1048
|
+
setup() {},
|
|
1049
|
+
async tui(api, options = {}) {
|
|
1050
|
+
const cleanup = await setupVoice(api, options || {});
|
|
1051
|
+
api.lifecycle.onDispose(cleanup);
|
|
992
1052
|
},
|
|
993
1053
|
};
|
|
994
|
-
|
|
995
|
-
export default plugin;
|
|
996
|
-
|