@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/lib/engine.js
CHANGED
|
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
5
6
|
import { spawn, spawnSync } from "node:child_process";
|
|
6
7
|
import { fileURLToPath } from "node:url";
|
|
7
8
|
import { createGunzip } from "node:zlib";
|
|
@@ -9,6 +10,7 @@ import { Readable, Transform } from "node:stream";
|
|
|
9
10
|
import { pipeline } from "node:stream/promises";
|
|
10
11
|
import { ensureDir, replaceFile, sha256 } from "./download.js";
|
|
11
12
|
import { getAudioDir, getCacheDir, getEnginesDir, getModelPath } from "./models.js";
|
|
13
|
+
import { repairUnfinalizedWavHeader } from "./wav.js";
|
|
12
14
|
|
|
13
15
|
const require = createRequire(import.meta.url);
|
|
14
16
|
const FFMPEG_STATIC_PACKAGE = "ffmpeg-static@^5.2.0";
|
|
@@ -579,7 +581,6 @@ function childEnv(options = {}) {
|
|
|
579
581
|
|
|
580
582
|
function normalizeWindowsAudioInput(device = "") {
|
|
581
583
|
const value = String(device).trim();
|
|
582
|
-
if (!value || value === "default") return "audio=default";
|
|
583
584
|
if (value.startsWith("audio=") || value.startsWith("video=")) return value;
|
|
584
585
|
return `audio=${value}`;
|
|
585
586
|
}
|
|
@@ -587,7 +588,7 @@ function normalizeWindowsAudioInput(device = "") {
|
|
|
587
588
|
function formatCommand(command, args) {
|
|
588
589
|
const quote = (value) => {
|
|
589
590
|
const text = String(value);
|
|
590
|
-
if (/^[
|
|
591
|
+
if (/^[a-zA-Z0-9_./=:+-]+$/.test(text)) return text;
|
|
591
592
|
return `"${text.replace(/(\\*)"/g, "$1$1\\\"").replace(/(\\*)$/g, "$1$1")}"`;
|
|
592
593
|
};
|
|
593
594
|
return [command, ...args].map(quote).join(" ");
|
|
@@ -604,10 +605,11 @@ function parseWindowsMicrophones(stderr) {
|
|
|
604
605
|
}
|
|
605
606
|
|
|
606
607
|
export function listMicrophones(options = {}) {
|
|
608
|
+
const platform = options.platform || process.platform;
|
|
607
609
|
const arecordCommand = resolveCommand("arecord", options);
|
|
608
610
|
const ffmpegCommand = resolveCommand("ffmpeg", options);
|
|
609
611
|
|
|
610
|
-
if (
|
|
612
|
+
if (platform === "linux" && arecordCommand) {
|
|
611
613
|
const result = spawnSync(arecordCommand, ["-L"], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
|
|
612
614
|
const devices = result.stdout
|
|
613
615
|
.split(/\r?\n/)
|
|
@@ -616,7 +618,7 @@ export function listMicrophones(options = {}) {
|
|
|
616
618
|
return ["default", ...devices.filter((item) => item !== "default")];
|
|
617
619
|
}
|
|
618
620
|
|
|
619
|
-
if (
|
|
621
|
+
if (platform === "darwin" && ffmpegCommand) {
|
|
620
622
|
const result = spawnSync(ffmpegCommand, ["-hide_banner", "-f", "avfoundation", "-list_devices", "true", "-i", ""], {
|
|
621
623
|
encoding: "utf8",
|
|
622
624
|
stdio: ["ignore", "ignore", "pipe"],
|
|
@@ -628,10 +630,11 @@ export function listMicrophones(options = {}) {
|
|
|
628
630
|
.map((id) => `:${id}`);
|
|
629
631
|
}
|
|
630
632
|
|
|
631
|
-
if (
|
|
633
|
+
if (platform === "win32" && ffmpegCommand) {
|
|
632
634
|
const result = spawnSync(ffmpegCommand, ["-hide_banner", "-f", "dshow", "-list_devices", "true", "-i", "dummy"], {
|
|
633
635
|
encoding: "utf8",
|
|
634
636
|
stdio: ["ignore", "ignore", "pipe"],
|
|
637
|
+
timeout: 5000,
|
|
635
638
|
});
|
|
636
639
|
const devices = parseWindowsMicrophones(result.stderr || "");
|
|
637
640
|
return ["default", ...devices.filter((device) => device !== "default")];
|
|
@@ -641,13 +644,14 @@ export function listMicrophones(options = {}) {
|
|
|
641
644
|
}
|
|
642
645
|
|
|
643
646
|
function buildRecorders(file, settings = {}) {
|
|
644
|
-
const mic = settings.mic || "";
|
|
647
|
+
const mic = (settings.mic || "").trim();
|
|
645
648
|
const recorders = [];
|
|
649
|
+
const platform = settings.platform || process.platform;
|
|
646
650
|
const arecordCommand = resolveCommand("arecord", settings);
|
|
647
651
|
const ffmpegCommand = resolveCommand("ffmpeg", settings);
|
|
648
652
|
const soxCommand = resolveCommand("sox", settings);
|
|
649
653
|
|
|
650
|
-
if (
|
|
654
|
+
if (platform === "linux" && arecordCommand) {
|
|
651
655
|
recorders.push({
|
|
652
656
|
label: mic ? `arecord (${mic})` : "arecord (default)",
|
|
653
657
|
command: arecordCommand,
|
|
@@ -655,7 +659,7 @@ function buildRecorders(file, settings = {}) {
|
|
|
655
659
|
});
|
|
656
660
|
}
|
|
657
661
|
|
|
658
|
-
if (
|
|
662
|
+
if (platform === "linux" && ffmpegCommand) {
|
|
659
663
|
if (!mic) {
|
|
660
664
|
recorders.push({
|
|
661
665
|
label: "ffmpeg pulse (default)",
|
|
@@ -671,7 +675,7 @@ function buildRecorders(file, settings = {}) {
|
|
|
671
675
|
});
|
|
672
676
|
}
|
|
673
677
|
|
|
674
|
-
if (
|
|
678
|
+
if (platform === "darwin" && ffmpegCommand) {
|
|
675
679
|
recorders.push({
|
|
676
680
|
label: `ffmpeg avfoundation (${mic || ":0"})`,
|
|
677
681
|
command: ffmpegCommand,
|
|
@@ -679,27 +683,21 @@ function buildRecorders(file, settings = {}) {
|
|
|
679
683
|
});
|
|
680
684
|
}
|
|
681
685
|
|
|
682
|
-
if (
|
|
683
|
-
const
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
recorders.push({
|
|
694
|
-
label: `ffmpeg dshow (${input.replace(/^audio=/, "")})`,
|
|
695
|
-
command: ffmpegCmd,
|
|
696
|
-
args: ["-hide_banner", "-loglevel", "error", "-y", "-f", "dshow", "-i", input, "-ac", "1", "-ar", "16000", file],
|
|
697
|
-
});
|
|
698
|
-
}
|
|
686
|
+
if (platform === "win32" && ffmpegCommand) {
|
|
687
|
+
const inputs = mic && mic !== "default" && mic !== "audio=default"
|
|
688
|
+
? [normalizeWindowsAudioInput(mic)]
|
|
689
|
+
: listMicrophones(settings).filter((device) => device !== "default").map(normalizeWindowsAudioInput);
|
|
690
|
+
for (const input of new Set(inputs)) {
|
|
691
|
+
recorders.push({
|
|
692
|
+
label: `ffmpeg dshow (${input.replace(/^audio=/, "")})`,
|
|
693
|
+
command: ffmpegCommand,
|
|
694
|
+
args: ["-hide_banner", "-loglevel", "error", "-y", "-f", "dshow", "-i", input, "-ac", "1", "-ar", "16000", "-flush_packets", "1", file],
|
|
695
|
+
gracefulStop: true,
|
|
696
|
+
});
|
|
699
697
|
}
|
|
700
698
|
}
|
|
701
699
|
|
|
702
|
-
if (soxCommand) {
|
|
700
|
+
if (soxCommand && platform !== "win32") {
|
|
703
701
|
recorders.push({
|
|
704
702
|
label: "sox default",
|
|
705
703
|
command: soxCommand,
|
|
@@ -707,33 +705,41 @@ function buildRecorders(file, settings = {}) {
|
|
|
707
705
|
});
|
|
708
706
|
}
|
|
709
707
|
|
|
710
|
-
if (!recorders.length)
|
|
708
|
+
if (!recorders.length) {
|
|
709
|
+
if (platform === "win32" && ffmpegCommand) throw new Error("No DirectShow audio devices found. Select a microphone in /voice-settings.");
|
|
710
|
+
throw new Error("No recorder found. Install ffmpeg, arecord, or sox.");
|
|
711
|
+
}
|
|
711
712
|
return recorders;
|
|
712
713
|
}
|
|
713
714
|
|
|
714
715
|
function waitForExit(proc, timeoutMs = 3000) {
|
|
715
716
|
return new Promise((resolve) => {
|
|
716
717
|
let settled = false;
|
|
718
|
+
let timer;
|
|
717
719
|
const finish = () => {
|
|
718
720
|
if (settled) return;
|
|
719
721
|
settled = true;
|
|
722
|
+
clearTimeout(timer);
|
|
720
723
|
resolve();
|
|
721
724
|
};
|
|
722
|
-
|
|
725
|
+
|
|
726
|
+
proc.once("exit", finish);
|
|
727
|
+
proc.once("error", finish);
|
|
728
|
+
if (proc.exitCode !== null || proc.signalCode !== null) {
|
|
729
|
+
finish();
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
timer = setTimeout(() => {
|
|
723
734
|
try {
|
|
724
735
|
proc.kill("SIGKILL");
|
|
725
|
-
} catch {
|
|
726
|
-
|
|
736
|
+
} catch {
|
|
737
|
+
finish();
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
// Wait for the OS to close recorder file handles before reading the WAV.
|
|
741
|
+
timer = setTimeout(finish, 1000);
|
|
727
742
|
}, timeoutMs);
|
|
728
|
-
|
|
729
|
-
proc.once("exit", () => {
|
|
730
|
-
clearTimeout(timer);
|
|
731
|
-
finish();
|
|
732
|
-
});
|
|
733
|
-
proc.once("error", () => {
|
|
734
|
-
clearTimeout(timer);
|
|
735
|
-
finish();
|
|
736
|
-
});
|
|
737
743
|
});
|
|
738
744
|
}
|
|
739
745
|
|
|
@@ -749,49 +755,85 @@ function lastLine(value) {
|
|
|
749
755
|
return value.trim().split("\n").filter(Boolean).pop() || "";
|
|
750
756
|
}
|
|
751
757
|
|
|
752
|
-
function startRecorder(recorder, file) {
|
|
758
|
+
function startRecorder(recorder, file, log, signal) {
|
|
753
759
|
return new Promise((resolve, reject) => {
|
|
754
760
|
let stderr = "";
|
|
755
|
-
let
|
|
756
|
-
let
|
|
761
|
+
let timer;
|
|
762
|
+
let settled = false;
|
|
763
|
+
let stopReason;
|
|
764
|
+
const started = Date.now();
|
|
757
765
|
const commandLine = formatCommand(recorder.command, recorder.args);
|
|
758
|
-
|
|
766
|
+
log(`Starting ${recorder.label}\nCommand: ${commandLine}\nArguments: ${JSON.stringify(recorder.args)}`);
|
|
767
|
+
const finish = (error, active) => {
|
|
768
|
+
if (settled) return;
|
|
769
|
+
settled = true;
|
|
770
|
+
clearTimeout(timer);
|
|
771
|
+
signal.removeEventListener("abort", abort);
|
|
772
|
+
if (error) {
|
|
773
|
+
log(error.message);
|
|
774
|
+
reject(error);
|
|
775
|
+
} else {
|
|
776
|
+
resolve(active);
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
const failure = (detail) => new Error(`${recorder.label}: ${detail}\nCommand: ${commandLine}${stderr.trim() ? `\nstderr:\n${stderr.trim()}` : ""}`);
|
|
759
780
|
|
|
760
781
|
let proc;
|
|
782
|
+
const abort = async () => {
|
|
783
|
+
clearTimeout(timer);
|
|
784
|
+
stopReason = "recording cancelled";
|
|
785
|
+
try { proc.kill("SIGKILL"); } catch {}
|
|
786
|
+
await waitForExit(proc);
|
|
787
|
+
finish(failure(stopReason));
|
|
788
|
+
};
|
|
761
789
|
try {
|
|
762
|
-
proc = spawn(recorder.command, recorder.args, { stdio: ["ignore", "ignore", "pipe"] });
|
|
790
|
+
proc = spawn(recorder.command, recorder.args, { stdio: [recorder.gracefulStop ? "pipe" : "ignore", "ignore", "pipe"] });
|
|
763
791
|
} catch (error) {
|
|
764
|
-
|
|
792
|
+
finish(failure(error instanceof Error ? error.message : String(error)));
|
|
765
793
|
return;
|
|
766
794
|
}
|
|
795
|
+
proc.stdin?.on("error", () => {});
|
|
767
796
|
proc.stderr.on("data", (chunk) => {
|
|
768
797
|
stderr += chunk.toString();
|
|
798
|
+
log(`stderr: ${chunk.toString().trimEnd()}`);
|
|
769
799
|
});
|
|
770
800
|
proc.once("error", (error) => {
|
|
771
|
-
|
|
772
|
-
reject(failure(error.message));
|
|
801
|
+
finish(failure(error.message));
|
|
773
802
|
});
|
|
774
|
-
proc.once("
|
|
775
|
-
|
|
776
|
-
|
|
803
|
+
proc.once("close", (code, exitSignal) => {
|
|
804
|
+
log(`Exited: code=${code}, signal=${exitSignal}, elapsed=${Date.now() - started}ms`);
|
|
805
|
+
finish(failure(stopReason || lastLine(stderr) || `exited with code ${code}`));
|
|
777
806
|
});
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
807
|
+
const check = async () => {
|
|
808
|
+
if (signal.aborted) return;
|
|
809
|
+
let stat;
|
|
810
|
+
try {
|
|
811
|
+
stat = fs.statSync(file, { throwIfNoEntry: false });
|
|
812
|
+
} catch (error) {
|
|
813
|
+
stopReason = error.message;
|
|
814
|
+
try { proc.kill("SIGKILL"); } catch {}
|
|
815
|
+
await waitForExit(proc);
|
|
816
|
+
finish(failure(stopReason));
|
|
782
817
|
return;
|
|
783
818
|
}
|
|
784
|
-
|
|
785
|
-
if (!
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
} catch {}
|
|
789
|
-
reject(failure("did not create an audio file"));
|
|
819
|
+
const size = stat?.size || 0;
|
|
820
|
+
if (proc.exitCode === null && proc.signalCode === null && stat && (!recorder.gracefulStop || size > RECORDING_MIN_BYTES)) {
|
|
821
|
+
log(`Recording ready after ${Date.now() - started}ms (${size} bytes)`);
|
|
822
|
+
finish(null, { proc, file, recorder, stderr: () => stderr, log });
|
|
790
823
|
return;
|
|
791
824
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
825
|
+
if (Date.now() - started >= 5000) {
|
|
826
|
+
stopReason = stat ? "did not write audio data within 5 seconds" : "did not create an audio file within 5 seconds";
|
|
827
|
+
try { proc.kill("SIGKILL"); } catch {}
|
|
828
|
+
await waitForExit(proc);
|
|
829
|
+
finish(failure(stopReason));
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
timer = setTimeout(check, 100);
|
|
833
|
+
};
|
|
834
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
835
|
+
if (signal.aborted) void abort();
|
|
836
|
+
else timer = setTimeout(check, 100);
|
|
795
837
|
});
|
|
796
838
|
}
|
|
797
839
|
|
|
@@ -799,7 +841,8 @@ export class VoiceRuntime {
|
|
|
799
841
|
constructor(options = {}) {
|
|
800
842
|
this.options = options;
|
|
801
843
|
this.recording = null;
|
|
802
|
-
this.
|
|
844
|
+
this.starting = null;
|
|
845
|
+
this.recorderLog = "";
|
|
803
846
|
this.transcription = null;
|
|
804
847
|
this.pendingSubmit = false;
|
|
805
848
|
}
|
|
@@ -814,7 +857,18 @@ export class VoiceRuntime {
|
|
|
814
857
|
|
|
815
858
|
async start(settings = {}) {
|
|
816
859
|
if (this.recording) return this.recording.file;
|
|
860
|
+
if (this.starting) return this.starting.promise;
|
|
861
|
+
const controller = new AbortController();
|
|
862
|
+
const promise = this.startRecording(settings, controller.signal);
|
|
863
|
+
this.starting = { controller, promise };
|
|
864
|
+
try {
|
|
865
|
+
return await promise;
|
|
866
|
+
} finally {
|
|
867
|
+
this.starting = null;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
817
870
|
|
|
871
|
+
async startRecording(settings, signal) {
|
|
818
872
|
const dir = getAudioDir(this.options, settings);
|
|
819
873
|
await ensureDir(dir);
|
|
820
874
|
const recorderSettings = { ...this.options, ...settings, downloadDir: settings.downloadDir || this.options.downloadDir };
|
|
@@ -824,26 +878,43 @@ export class VoiceRuntime {
|
|
|
824
878
|
});
|
|
825
879
|
if (recorderReady?.resolvedBinary) recorderSettings.ffmpeg = recorderReady.resolvedBinary;
|
|
826
880
|
|
|
827
|
-
const
|
|
828
|
-
const
|
|
881
|
+
const stem = path.join(dir, `voice-${Date.now()}-${randomUUID()}`);
|
|
882
|
+
const file = `${stem}.wav`;
|
|
883
|
+
this.recorderLog = `${stem}.log`;
|
|
884
|
+
const logFile = this.recorderLog;
|
|
885
|
+
const log = (message) => {
|
|
886
|
+
try {
|
|
887
|
+
fs.appendFileSync(logFile, `[${new Date().toISOString()}] ${message}\n`);
|
|
888
|
+
} catch {}
|
|
889
|
+
};
|
|
890
|
+
log(`Platform: ${recorderSettings.platform || process.platform}; microphone: ${settings.mic || "default"}`);
|
|
891
|
+
let recorders;
|
|
892
|
+
try {
|
|
893
|
+
recorders = buildRecorders(file, recorderSettings);
|
|
894
|
+
} catch (error) {
|
|
895
|
+
log(error.message);
|
|
896
|
+
throw new Error(`${error.message}\nRecorder log: ${logFile}`);
|
|
897
|
+
}
|
|
829
898
|
const errors = [];
|
|
830
|
-
this.recordingError = "";
|
|
831
899
|
|
|
832
|
-
for (const recorder of recorders) {
|
|
833
|
-
|
|
900
|
+
for (const [index, recorder] of recorders.entries()) {
|
|
901
|
+
signal.throwIfAborted();
|
|
902
|
+
const attemptFile = index === 0 ? file : `${stem}-${index}.wav`;
|
|
903
|
+
recorder.args[recorder.args.length - 1] = attemptFile;
|
|
834
904
|
try {
|
|
835
|
-
const active = await startRecorder(recorder,
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
905
|
+
const active = await startRecorder(recorder, attemptFile, log, signal);
|
|
906
|
+
if (signal.aborted) {
|
|
907
|
+
try { active.proc.kill("SIGKILL"); } catch {}
|
|
908
|
+
signal.throwIfAborted();
|
|
909
|
+
}
|
|
839
910
|
this.recording = active;
|
|
840
|
-
return
|
|
911
|
+
return attemptFile;
|
|
841
912
|
} catch (error) {
|
|
842
913
|
errors.push(error instanceof Error ? error.message : String(error));
|
|
843
914
|
}
|
|
844
915
|
}
|
|
845
916
|
|
|
846
|
-
throw new Error(`Could not start recorder. Tried: ${errors.join("; ")}`);
|
|
917
|
+
throw new Error(`Could not start recorder. Tried: ${errors.join("; ")}\nRecorder log: ${logFile}`);
|
|
847
918
|
}
|
|
848
919
|
|
|
849
920
|
async stop() {
|
|
@@ -851,30 +922,36 @@ export class VoiceRuntime {
|
|
|
851
922
|
if (!active) return null;
|
|
852
923
|
|
|
853
924
|
try {
|
|
854
|
-
active.proc.
|
|
925
|
+
if (active.recorder.gracefulStop && active.proc.stdin?.writable) active.proc.stdin.end("q\n");
|
|
926
|
+
else active.proc.kill("SIGINT");
|
|
855
927
|
} catch {}
|
|
856
928
|
|
|
857
929
|
await waitForExit(active.proc);
|
|
858
930
|
this.recording = null;
|
|
859
931
|
|
|
860
932
|
if (!fs.existsSync(active.file)) {
|
|
861
|
-
const lastError = lastLine(active.stderr?.() ||
|
|
862
|
-
throw new Error(lastError || `${active.recorder?.label || "Recorder"} did not create an audio file`);
|
|
933
|
+
const lastError = lastLine(active.stderr?.() || "");
|
|
934
|
+
throw new Error(`${lastError || `${active.recorder?.label || "Recorder"} did not create an audio file`}\nRecorder log: ${this.recorderLog}`);
|
|
863
935
|
}
|
|
864
936
|
|
|
865
|
-
|
|
866
|
-
|
|
937
|
+
const size = fs.statSync(active.file).size;
|
|
938
|
+
active.log(`Recording stopped (${size} bytes)`);
|
|
939
|
+
if (size <= RECORDING_MIN_BYTES) {
|
|
940
|
+
throw new Error(`Recording is empty. Check your microphone input.\nRecorder log: ${this.recorderLog}`);
|
|
867
941
|
}
|
|
868
942
|
|
|
869
943
|
return active.file;
|
|
870
944
|
}
|
|
871
945
|
|
|
872
946
|
async cancel() {
|
|
947
|
+
this.starting?.controller.abort();
|
|
873
948
|
if (this.recording) {
|
|
949
|
+
const active = this.recording;
|
|
874
950
|
try {
|
|
875
|
-
|
|
951
|
+
active.proc.kill("SIGKILL");
|
|
876
952
|
} catch {}
|
|
877
953
|
this.recording = null;
|
|
954
|
+
await waitForExit(active.proc);
|
|
878
955
|
}
|
|
879
956
|
|
|
880
957
|
if (this.transcription) {
|
|
@@ -896,6 +973,8 @@ export class VoiceRuntime {
|
|
|
896
973
|
throw new Error(`Model is not downloaded: ${model.name}`);
|
|
897
974
|
}
|
|
898
975
|
|
|
976
|
+
repairUnfinalizedWavHeader(audioFile);
|
|
977
|
+
|
|
899
978
|
const args = model.engine === "transcribe-cpp" ? ["--model", modelFile, "--file", audioFile] : ["-m", modelFile, "-f", audioFile, "-np", "-nt"];
|
|
900
979
|
if (settings.language && settings.language !== "auto") args.push(model.engine === "transcribe-cpp" ? "--language" : "-l", settings.language);
|
|
901
980
|
|
package/lib/engines.js
CHANGED
|
@@ -10,6 +10,7 @@ import { getCacheDir } from "./models.js";
|
|
|
10
10
|
import { getBundledEngineDir, resolveCommand } from "./engine.js";
|
|
11
11
|
|
|
12
12
|
export const DEFAULT_ENGINE_REGISTRY_URL = "https://github.com/ihxnnxs/opencode-voice/releases/download/v0.2.0/registry.json";
|
|
13
|
+
const TRANSCRIBE_ENGINE_REGISTRY_URL = "https://github.com/ihxnnxs/opencode-voice/releases/download/engines-2026-12/registry.json";
|
|
13
14
|
|
|
14
15
|
export const ENGINES = {
|
|
15
16
|
"whisper.cpp": {
|
|
@@ -171,9 +172,13 @@ export async function probeEngine(engineId = "whisper.cpp", binaryPath, options
|
|
|
171
172
|
finish({ ok: false, message: engineProbeMessage(error.message) });
|
|
172
173
|
});
|
|
173
174
|
proc.on("exit", (code, signal) => {
|
|
174
|
-
const
|
|
175
|
+
const requiresUpdate = engineId === "transcribe-cpp" && options.requireUpdatedEngine !== false;
|
|
176
|
+
const ok = engine.probeContains.every((item) => output.includes(item)) &&
|
|
177
|
+
(!requiresUpdate || output.includes("Supports GigaAM-v4"));
|
|
175
178
|
const detail = summarizeProbeOutput(output) || `exit ${code ?? signal ?? "unknown"}`;
|
|
176
|
-
finish({ ok, message: ok ? "ok" : engineProbeMessage(
|
|
179
|
+
finish({ ok, message: ok ? "ok" : engineProbeMessage(requiresUpdate && !output.includes("Supports GigaAM-v4")
|
|
180
|
+
? `${engine.command} needs the updated GigaAM-v4-capable runtime`
|
|
181
|
+
: `unexpected ${engine.command} help output: ${detail}`) });
|
|
177
182
|
});
|
|
178
183
|
});
|
|
179
184
|
}
|
|
@@ -208,12 +213,13 @@ async function readJsonUrl(url, options = {}) {
|
|
|
208
213
|
return response.json();
|
|
209
214
|
}
|
|
210
215
|
|
|
211
|
-
export function getEngineRegistryUrl(options = {}) {
|
|
212
|
-
return options.engineRegistry || process.env.OPENCODE_VOICE_ENGINE_REGISTRY ||
|
|
216
|
+
export function getEngineRegistryUrl(options = {}, engineId) {
|
|
217
|
+
return options.engineRegistry || process.env.OPENCODE_VOICE_ENGINE_REGISTRY ||
|
|
218
|
+
(engineId === "transcribe-cpp" ? TRANSCRIBE_ENGINE_REGISTRY_URL : DEFAULT_ENGINE_REGISTRY_URL);
|
|
213
219
|
}
|
|
214
220
|
|
|
215
|
-
export async function loadEngineRegistry(options = {}) {
|
|
216
|
-
const url = getEngineRegistryUrl(options);
|
|
221
|
+
export async function loadEngineRegistry(options = {}, engineId) {
|
|
222
|
+
const url = getEngineRegistryUrl(options, engineId);
|
|
217
223
|
const registry = await readJsonUrl(url, options);
|
|
218
224
|
if (registry?.schema !== "opencode-voice.engines.v1") throw new Error("Unsupported engine registry schema");
|
|
219
225
|
return { url, registry };
|
|
@@ -320,7 +326,7 @@ export async function installManagedEngine(engineId = "whisper.cpp", options = {
|
|
|
320
326
|
}
|
|
321
327
|
|
|
322
328
|
hooks.onProgress?.({ state: "registry", downloaded: 0, total: 0, percent: 0, attempt: 1, attempts: 1 });
|
|
323
|
-
const { url: registryUrl, registry } = await loadEngineRegistry(commandOptions);
|
|
329
|
+
const { url: registryUrl, registry } = await loadEngineRegistry(commandOptions, engineId);
|
|
324
330
|
const platform = getEnginePlatformKey(commandOptions);
|
|
325
331
|
const { engine, asset } = selectEngineAsset(registry, engineId, platform);
|
|
326
332
|
|
|
@@ -394,7 +400,7 @@ export async function importManagedEngine(engineId = "whisper.cpp", sourcePath,
|
|
|
394
400
|
await fs.promises.copyFile(source, tmp);
|
|
395
401
|
await fs.promises.chmod(tmp, 0o755);
|
|
396
402
|
|
|
397
|
-
const probe = await probeEngine(engineId, tmp);
|
|
403
|
+
const probe = await probeEngine(engineId, tmp, { requireUpdatedEngine: false });
|
|
398
404
|
if (!probe.ok) {
|
|
399
405
|
await fs.promises.unlink(tmp).catch(() => {});
|
|
400
406
|
throw new Error(`Imported binary failed probe: ${probe.message}`);
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
// Generated by scripts/update-handy-model-catalog.mjs. Do not edit manually.
|
|
2
|
-
export const HANDY_MODEL_CATALOG_SHA256 = "
|
|
2
|
+
export const HANDY_MODEL_CATALOG_SHA256 = "8c886882ed49ff5f39cc0ff42176a41119ea49242068518e3eb671b09be88ddc";
|
|
3
3
|
export const HANDY_MODELS = [
|
|
4
|
+
{
|
|
5
|
+
"id": "gigaam-v4-e2e-rnnt-gguf",
|
|
6
|
+
"name": "gigaam-v4-e2e-rnnt-gguf",
|
|
7
|
+
"engine": "transcribe-cpp",
|
|
8
|
+
"implemented": true,
|
|
9
|
+
"filename": "gigaam-v4-e2e-rnnt-Q8_0.gguf",
|
|
10
|
+
"url": "https://huggingface.co/70sh1/gigaam-v4-e2e-rnnt-gguf/resolve/2a312d783963ca3433768281faea00cdcf2569c5/gigaam-v4-e2e-rnnt-Q8_0.gguf",
|
|
11
|
+
"sha256": "debd6179b9948beba5c60c0944285e577f732610dd50dee1233884e4b46e3e29",
|
|
12
|
+
"sizeMB": 244,
|
|
13
|
+
"languages": "ru, en",
|
|
14
|
+
"requiresUpdatedEngine": true,
|
|
15
|
+
"description": "gigaam model from the GigaAM-v4 Zapformer port. Pinned to 2a312d783963."
|
|
16
|
+
},
|
|
4
17
|
{
|
|
5
18
|
"id": "handy-breeze-asr-25-gguf",
|
|
6
19
|
"name": "Breeze-ASR-25-gguf",
|
|
@@ -217,6 +230,32 @@ export const HANDY_MODELS = [
|
|
|
217
230
|
"languages": "en, fr, de, es, pt",
|
|
218
231
|
"description": "granite_speech model from Handy's transcribe.cpp catalog. Pinned to f73a59df77fe."
|
|
219
232
|
},
|
|
233
|
+
{
|
|
234
|
+
"id": "handy-granite-speech-5-0-470m-turboctc-gguf",
|
|
235
|
+
"name": "granite-speech-5.0-470m-turboctc-gguf",
|
|
236
|
+
"engine": "transcribe-cpp",
|
|
237
|
+
"implemented": true,
|
|
238
|
+
"filename": "granite-speech-5.0-470m-turboctc-Q4_K_M.gguf",
|
|
239
|
+
"url": "https://huggingface.co/handy-computer/granite-speech-5.0-470m-turboctc-gguf/resolve/0cf5be9f4bcd479989e6a24d142094d34d552daa/granite-speech-5.0-470m-turboctc-Q4_K_M.gguf",
|
|
240
|
+
"sha256": "3f30525381d72246b7f99e49b6cb66b249cf1b990c6c3d0e031a7765735f513e",
|
|
241
|
+
"sizeMB": 267,
|
|
242
|
+
"languages": "en",
|
|
243
|
+
"requiresUpdatedEngine": true,
|
|
244
|
+
"description": "granite_speech5_ctc model from Handy's transcribe.cpp catalog. Pinned to 0cf5be9f4bcd."
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
"id": "handy-granite-speech-5-0-470m-turboctc-nc-gguf",
|
|
248
|
+
"name": "granite-speech-5.0-470m-turboctc-nc-gguf",
|
|
249
|
+
"engine": "transcribe-cpp",
|
|
250
|
+
"implemented": true,
|
|
251
|
+
"filename": "granite-speech-5.0-470m-turboctc-nc-Q4_K_M.gguf",
|
|
252
|
+
"url": "https://huggingface.co/handy-computer/granite-speech-5.0-470m-turboctc-nc-gguf/resolve/73e511af2e488994672379a3e5f9307b51d173c9/granite-speech-5.0-470m-turboctc-nc-Q4_K_M.gguf",
|
|
253
|
+
"sha256": "b79b5b39c36f3d0596774ff352d132483b659a43927015864ad5e149ac85470a",
|
|
254
|
+
"sizeMB": 267,
|
|
255
|
+
"languages": "en",
|
|
256
|
+
"requiresUpdatedEngine": true,
|
|
257
|
+
"description": "granite_speech5_ctc model from Handy's transcribe.cpp catalog. Pinned to 73e511af2e48."
|
|
258
|
+
},
|
|
220
259
|
{
|
|
221
260
|
"id": "handy-medasr-gguf",
|
|
222
261
|
"name": "medasr-gguf",
|
|
@@ -481,6 +520,19 @@ export const HANDY_MODELS = [
|
|
|
481
520
|
"languages": "en",
|
|
482
521
|
"description": "parakeet model from Handy's transcribe.cpp catalog. Pinned to 7d9b71920678."
|
|
483
522
|
},
|
|
523
|
+
{
|
|
524
|
+
"id": "handy-orukeet-gguf",
|
|
525
|
+
"name": "orukeet-gguf",
|
|
526
|
+
"engine": "transcribe-cpp",
|
|
527
|
+
"implemented": true,
|
|
528
|
+
"filename": "orukeet-Q4_K_M.gguf",
|
|
529
|
+
"url": "https://huggingface.co/handy-computer/orukeet-gguf/resolve/c5511a3850fce1cbbfa5d94ef815966e1d99275f/orukeet-Q4_K_M.gguf",
|
|
530
|
+
"sha256": "ead20f27cef24a39c2c8ad262bff88c3b5e0d4b514ff761cf7a08c5e172ccd9e",
|
|
531
|
+
"sizeMB": 463,
|
|
532
|
+
"languages": "bg, hr, cs, da, nl, en, et, fi, fr, de, el, hu, it, lv, lt, mt, pl, pt, ro, ru, sk, sl, es, sv, uk",
|
|
533
|
+
"requiresUpdatedEngine": true,
|
|
534
|
+
"description": "parakeet model from Handy's transcribe.cpp catalog. Pinned to c5511a3850fc."
|
|
535
|
+
},
|
|
484
536
|
{
|
|
485
537
|
"id": "handy-parakeet-ctc-0-6b-gguf",
|
|
486
538
|
"name": "parakeet-ctc-0.6b-gguf",
|
|
@@ -505,6 +557,19 @@ export const HANDY_MODELS = [
|
|
|
505
557
|
"languages": "en",
|
|
506
558
|
"description": "parakeet model from Handy's transcribe.cpp catalog. Pinned to a9607fbeb480."
|
|
507
559
|
},
|
|
560
|
+
{
|
|
561
|
+
"id": "handy-parakeet-primeline-gguf",
|
|
562
|
+
"name": "parakeet-primeline-gguf",
|
|
563
|
+
"engine": "transcribe-cpp",
|
|
564
|
+
"implemented": true,
|
|
565
|
+
"filename": "parakeet-primeline-Q4_K_M.gguf",
|
|
566
|
+
"url": "https://huggingface.co/handy-computer/parakeet-primeline-gguf/resolve/cf04224dee82c8ad7184e99562680f2926c82bf7/parakeet-primeline-Q4_K_M.gguf",
|
|
567
|
+
"sha256": "8b01f1893fa1db166d8b08375f8300c140fc7f110af7e9b68480a27b145dad7d",
|
|
568
|
+
"sizeMB": 463,
|
|
569
|
+
"languages": "bg, hr, cs, da, nl, en, et, fi, fr, de, el, hu, it, lv, lt, mt, pl, pt, ro, ru, sk, sl, es, sv, uk",
|
|
570
|
+
"requiresUpdatedEngine": true,
|
|
571
|
+
"description": "parakeet model from Handy's transcribe.cpp catalog. Pinned to cf04224dee82."
|
|
572
|
+
},
|
|
508
573
|
{
|
|
509
574
|
"id": "handy-parakeet-rnnt-0-6b-gguf",
|
|
510
575
|
"name": "parakeet-rnnt-0.6b-gguf",
|
|
@@ -589,6 +654,19 @@ export const HANDY_MODELS = [
|
|
|
589
654
|
"languages": "en",
|
|
590
655
|
"description": "parakeet model from Handy's transcribe.cpp catalog. Pinned to 8c2181061569."
|
|
591
656
|
},
|
|
657
|
+
{
|
|
658
|
+
"id": "handy-parakeet-ultra-gguf",
|
|
659
|
+
"name": "parakeet-ultra-gguf",
|
|
660
|
+
"engine": "transcribe-cpp",
|
|
661
|
+
"implemented": true,
|
|
662
|
+
"filename": "parakeet-ultra-Q4_K_M.gguf",
|
|
663
|
+
"url": "https://huggingface.co/handy-computer/parakeet-ultra-gguf/resolve/a1539be1b849ea7463b88343e5277b373d0c4ea9/parakeet-ultra-Q4_K_M.gguf",
|
|
664
|
+
"sha256": "c69b7a5f9071a7afd8a1818ef7ae542c386c4b01ed0cac380c19a99947646bf9",
|
|
665
|
+
"sizeMB": 464,
|
|
666
|
+
"languages": "en, de, fr, es, it, pt, ru, uk, hr, sl, lv, lt, et, fi, sv, da, nl, pl, cs, sk, hu, ro, bg, el, mt",
|
|
667
|
+
"requiresUpdatedEngine": true,
|
|
668
|
+
"description": "parakeet model from Handy's transcribe.cpp catalog. Pinned to a1539be1b849."
|
|
669
|
+
},
|
|
592
670
|
{
|
|
593
671
|
"id": "handy-parakeet-unified-en-0-6b-gguf",
|
|
594
672
|
"name": "parakeet-unified-en-0.6b-gguf",
|