@senad-d/micme 0.2.0 → 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 +1 -0
- package/README.md +25 -5
- package/SECURITY.md +2 -2
- package/micme.example.json +1 -0
- package/micme.schema.json +22 -2
- package/package.json +2 -2
- package/scripts/doctor.mjs +92 -0
- package/src/backends.ts +249 -0
- package/src/config.ts +11 -1
- package/src/constants.ts +2 -0
- package/src/extension.ts +8 -12
- package/src/models.ts +100 -9
- package/src/settings.ts +115 -44
- package/src/transcription.ts +32 -48
- package/src/types.ts +27 -0
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,7 @@ All notable changes to Micme will be documented in this file.
|
|
|
9
9
|
- Document the scoped npm package name, `@senad-d/micme`, in install, diagnostics, update, and uninstall commands.
|
|
10
10
|
- Add an interactive npm publishing script that prompts for a version, validates the package, creates the release commit/tag, and publishes with public scoped-package access.
|
|
11
11
|
- Keep publication on hold until package name, metadata, security review, validation, and smoke tests are complete.
|
|
12
|
+
- Add explicit transcription backend selection with backend-specific `/micme conf` model rows, doctor diagnostics, schema, and docs.
|
|
12
13
|
|
|
13
14
|
## 0.1.0 - 2026-06-18
|
|
14
15
|
|
package/README.md
CHANGED
|
@@ -17,6 +17,17 @@
|
|
|
17
17
|
|
|
18
18
|
Micme is a pi extension for short coding prompts. It records your microphone with `ffmpeg`, transcribes locally with `whisper.cpp` or another local backend, and inserts the transcript into pi.
|
|
19
19
|
|
|
20
|
+
<table align="center">
|
|
21
|
+
<tr>
|
|
22
|
+
<th>Micme demo</th>
|
|
23
|
+
</tr>
|
|
24
|
+
<tr>
|
|
25
|
+
<td align="center">
|
|
26
|
+
<img src="img/demo.gif" alt="Micme demo: record voice and paste the transcript into pi" title="Micme demo" width="760">
|
|
27
|
+
</td>
|
|
28
|
+
</tr>
|
|
29
|
+
</table>
|
|
30
|
+
|
|
20
31
|
- **Local-first:** no telemetry and no cloud STT service by default.
|
|
21
32
|
- **Review-first:** transcripts paste into the editor unless you enable auto-submit.
|
|
22
33
|
- **Pi-native:** install globally, project-locally, from git, or from a source checkout.
|
|
@@ -150,6 +161,7 @@ You can also edit the JSON manually. Minimal `~/.pi/agent/micme.json`:
|
|
|
150
161
|
{
|
|
151
162
|
"$schema": "https://raw.githubusercontent.com/senad-d/micme/main/micme.schema.json",
|
|
152
163
|
"MICME_LANGUAGE": "en",
|
|
164
|
+
"MICME_TRANSCRIBE_BACKEND": "auto",
|
|
153
165
|
"MICME_AUTO_DOWNLOAD_MODEL": "1",
|
|
154
166
|
"MICME_DEFAULT_WHISPER_CPP_MODEL": "small.en",
|
|
155
167
|
"MICME_AUTO_SUBMIT": "0",
|
|
@@ -163,8 +175,9 @@ Common settings:
|
|
|
163
175
|
|
|
164
176
|
| Variable | Meaning |
|
|
165
177
|
| --- | --- |
|
|
178
|
+
| `MICME_TRANSCRIBE_BACKEND=auto` | Backend selector. `auto` preserves priority: custom command, whisper.cpp, then Python Whisper. |
|
|
166
179
|
| `MICME_TRANSCRIPTION_MODE=clip` | Stable default: transcribe after recording stops. |
|
|
167
|
-
| `MICME_TRANSCRIPTION_MODE=stream` | Experimental append-only live dictation with `whisper-stream
|
|
180
|
+
| `MICME_TRANSCRIPTION_MODE=stream` | Experimental append-only live dictation with `whisper-stream`; requires whisper.cpp. |
|
|
168
181
|
| `MICME_STREAM_KEEP_CONTEXT=0` | Stream default: avoid Whisper prompt carry-over so live chunks are less likely to rewrite each other. |
|
|
169
182
|
| `MICME_STREAM_FLUSH_MS=650` | Stream profile quiet interval before tentative words are committed append-only. |
|
|
170
183
|
| `MICME_STREAM_FINALIZE_WITH_CLIP=0` | Keep the append-only live transcript on stop. Set `1` to opt in to final clip replacement. |
|
|
@@ -196,9 +209,16 @@ Streaming mode treats `whisper-stream` output as repeated, overlapping hypothese
|
|
|
196
209
|
|
|
197
210
|
## Models and Backends
|
|
198
211
|
|
|
199
|
-
|
|
212
|
+
Micme supports these backend values in JSON/env config:
|
|
213
|
+
|
|
214
|
+
- `auto` (default): custom command when configured, otherwise whisper.cpp, otherwise Python Whisper.
|
|
215
|
+
- `whisper.cpp`: uses `whisper-cli`/`whisper-cpp` and a ggml/gguf model path.
|
|
216
|
+
- `python`: uses the OpenAI Whisper `whisper` CLI and a Python model name.
|
|
217
|
+
- `custom`: runs `MICME_TRANSCRIBE_COMMAND`; Micme treats the model as unknown.
|
|
218
|
+
|
|
219
|
+
`/micme conf` keeps the interactive backend picker focused on `whisper.cpp` and `Python Whisper`, then shows only the model/binary fields for the selected backend. For whisper.cpp, `MICME_WHISPER_CPP_MODEL` is the selected ggml/gguf model path; if it is unset, Micme falls back to `${MICME_MODEL_DIR}/ggml-${MICME_DEFAULT_WHISPER_CPP_MODEL}.bin`. For Python Whisper, `MICME_WHISPER_MODEL` is passed as the CLI model name.
|
|
200
220
|
|
|
201
|
-
With `MICME_AUTO_DOWNLOAD_MODEL=1`, Micme downloads missing standard models into `MICME_MODEL_DIR`. Disable downloads with:
|
|
221
|
+
With `MICME_AUTO_DOWNLOAD_MODEL=1`, Micme downloads missing standard whisper.cpp models into `MICME_MODEL_DIR`. Disable downloads with:
|
|
202
222
|
|
|
203
223
|
```env
|
|
204
224
|
MICME_AUTO_DOWNLOAD_MODEL=0
|
|
@@ -221,7 +241,7 @@ MICME_TRANSCRIBE_COMMAND=whisper-cli -m /path/to/model.bin -f {audio} -otxt -of
|
|
|
221
241
|
|
|
222
242
|
| Problem | Try |
|
|
223
243
|
| --- | --- |
|
|
224
|
-
| No backend found |
|
|
244
|
+
| No backend found | Use `/micme conf` to choose `whisper.cpp` or Python Whisper, install the selected backend, or configure a trusted custom command manually. |
|
|
225
245
|
| Wrong microphone | Run `/micme devices`, then set the OS-specific device variable. |
|
|
226
246
|
| Unrelated transcript | You probably recorded silence. Set `MICME_KEEP_AUDIO=1` and check `/micme audio`. |
|
|
227
247
|
| Slow transcription | Use `whisper.cpp`, a smaller model, and shorter recordings. |
|
|
@@ -242,7 +262,7 @@ From a source checkout:
|
|
|
242
262
|
npm run doctor
|
|
243
263
|
```
|
|
244
264
|
|
|
245
|
-
The doctor checks Node, pi, `ffmpeg`, whisper.cpp, optional `whisper-stream`, model paths, and macOS devices when available. Custom command values are redacted.
|
|
265
|
+
The doctor checks Node, pi, `ffmpeg`, requested/effective backend, effective model, whisper.cpp, optional `whisper-stream`, model paths, and macOS devices when available. Custom command values are redacted.
|
|
246
266
|
|
|
247
267
|
For stream state investigation, start pi with `MICME_STREAM_DIAGNOSTICS=1`. Diagnostics are opt-in and include sanitized frames, extraction mode, committed words, and tentative candidate words.
|
|
248
268
|
|
package/SECURITY.md
CHANGED
|
@@ -39,7 +39,7 @@ The default process output is capped before it is shown to users or errors. Diag
|
|
|
39
39
|
|
|
40
40
|
## Custom command risks
|
|
41
41
|
|
|
42
|
-
`MICME_RECORD_COMMAND` and `MICME_TRANSCRIBE_COMMAND` are advanced escape hatches. They run through the local shell (`sh -lc` on Unix-like systems and `cmd.exe` on Windows). Only use commands you wrote or fully trust.
|
|
42
|
+
`MICME_RECORD_COMMAND` and `MICME_TRANSCRIBE_COMMAND` are advanced escape hatches. They run through the local shell (`sh -lc` on Unix-like systems and `cmd.exe` on Windows). Only use commands you wrote or fully trust. When `MICME_TRANSCRIBE_BACKEND=custom`, Micme does not try to inspect, parse, or rewrite the command to infer which model it uses.
|
|
43
43
|
|
|
44
44
|
Micme replaces these placeholders in custom commands:
|
|
45
45
|
|
|
@@ -59,7 +59,7 @@ Disable model downloads with:
|
|
|
59
59
|
MICME_AUTO_DOWNLOAD_MODEL=0
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
You can also download models manually and set `MICME_WHISPER_CPP_MODEL=/path/to/model.bin`.
|
|
62
|
+
You can also download models manually and set `MICME_WHISPER_CPP_MODEL=/path/to/model.bin`. Micme only auto-downloads standard, inferable whisper.cpp model files and does not treat arbitrary custom-command model references as downloadable assets.
|
|
63
63
|
|
|
64
64
|
## Micme config handling
|
|
65
65
|
|
package/micme.example.json
CHANGED
package/micme.schema.json
CHANGED
|
@@ -21,6 +21,12 @@
|
|
|
21
21
|
"enum": ["clip", "stream"],
|
|
22
22
|
"default": "clip"
|
|
23
23
|
},
|
|
24
|
+
"MICME_TRANSCRIBE_BACKEND": {
|
|
25
|
+
"type": "string",
|
|
26
|
+
"enum": ["auto", "whisper.cpp", "python", "custom"],
|
|
27
|
+
"default": "auto",
|
|
28
|
+
"description": "Select transcription backend. auto preserves priority: custom command, whisper.cpp, then Python Whisper."
|
|
29
|
+
},
|
|
24
30
|
"MICME_AUTO_SUBMIT": {
|
|
25
31
|
"$ref": "#/$defs/stringFlag"
|
|
26
32
|
},
|
|
@@ -33,7 +39,21 @@
|
|
|
33
39
|
},
|
|
34
40
|
"MICME_DEFAULT_WHISPER_CPP_MODEL": {
|
|
35
41
|
"type": "string",
|
|
36
|
-
"default": "small.en"
|
|
42
|
+
"default": "small.en",
|
|
43
|
+
"description": "whisper.cpp model name mapped to MICME_MODEL_DIR/ggml-<name>.bin unless MICME_WHISPER_CPP_MODEL is set."
|
|
44
|
+
},
|
|
45
|
+
"MICME_WHISPER_CPP_MODEL": {
|
|
46
|
+
"type": "string",
|
|
47
|
+
"description": "Advanced whisper.cpp exact ggml/gguf model path override. When set, it wins over MICME_DEFAULT_WHISPER_CPP_MODEL."
|
|
48
|
+
},
|
|
49
|
+
"MICME_WHISPER_CPP_BIN": {
|
|
50
|
+
"type": "string",
|
|
51
|
+
"description": "Command or path for whisper.cpp clip transcription. Leave unset to find whisper-cli/whisper-cpp on PATH."
|
|
52
|
+
},
|
|
53
|
+
"MICME_WHISPER_MODEL": {
|
|
54
|
+
"type": "string",
|
|
55
|
+
"default": "base.en",
|
|
56
|
+
"description": "Model name passed to the OpenAI Whisper Python CLI when the Python backend is used."
|
|
37
57
|
},
|
|
38
58
|
"MICME_MODEL_DIR": {
|
|
39
59
|
"type": "string",
|
|
@@ -65,7 +85,7 @@
|
|
|
65
85
|
},
|
|
66
86
|
"MICME_TRANSCRIBE_COMMAND": {
|
|
67
87
|
"type": "string",
|
|
68
|
-
"description": "Advanced shell command
|
|
88
|
+
"description": "Advanced custom transcription shell command. Use only trusted commands; Micme cannot inspect which model it uses."
|
|
69
89
|
}
|
|
70
90
|
},
|
|
71
91
|
"patternProperties": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@senad-d/micme",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Local voice-to-text for pi, optimized for fast Whisper-style backends.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"scripts": {
|
|
46
46
|
"doctor": "node scripts/doctor.mjs",
|
|
47
47
|
"check": "node --check scripts/doctor.mjs && node --check scripts/check-package-contents.mjs && node --check scripts/publish-npm.mjs",
|
|
48
|
-
"test": "node --test test
|
|
48
|
+
"test": "node --test test/*.test.mjs",
|
|
49
49
|
"typecheck": "tsc --noEmit",
|
|
50
50
|
"pack:dry-run": "npm pack --dry-run --json",
|
|
51
51
|
"check:pack": "node scripts/check-package-contents.mjs",
|
package/scripts/doctor.mjs
CHANGED
|
@@ -7,6 +7,8 @@ import { execFileSync, spawnSync } from "node:child_process";
|
|
|
7
7
|
|
|
8
8
|
const isWin = process.platform === "win32";
|
|
9
9
|
const micmeConfig = loadMicmeConfig();
|
|
10
|
+
const DEFAULT_TRANSCRIBE_BACKEND = "auto";
|
|
11
|
+
const TRANSCRIBE_BACKENDS = new Set(["auto", "whisper.cpp", "python", "custom"]);
|
|
10
12
|
|
|
11
13
|
function getMicmeConfigPath() {
|
|
12
14
|
const agentDir = process.env.PI_CODING_AGENT_DIR ? resolve(process.env.PI_CODING_AGENT_DIR) : join(homedir(), ".pi", "agent");
|
|
@@ -91,6 +93,94 @@ function summarizeConfiguredCommand(value) {
|
|
|
91
93
|
return `configured (${trimmed.length} chars${placeholderText}; full value redacted)`;
|
|
92
94
|
}
|
|
93
95
|
|
|
96
|
+
function getTranscribeBackend() {
|
|
97
|
+
const raw = env("MICME_TRANSCRIBE_BACKEND")?.trim();
|
|
98
|
+
return TRANSCRIBE_BACKENDS.has(raw) ? raw : DEFAULT_TRANSCRIBE_BACKEND;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getTranscriptionMode() {
|
|
102
|
+
return env("MICME_TRANSCRIPTION_MODE") === "stream" ? "stream" : "clip";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function resolveWhisperCppModelSummary() {
|
|
106
|
+
const explicit = envPath("MICME_WHISPER_CPP_MODEL");
|
|
107
|
+
if (explicit) {
|
|
108
|
+
return {
|
|
109
|
+
path: explicit,
|
|
110
|
+
source: "MICME_WHISPER_CPP_MODEL explicit path",
|
|
111
|
+
exists: existsSync(explicit),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const defaultModel = env("MICME_DEFAULT_WHISPER_CPP_MODEL") || "small.en";
|
|
115
|
+
const modelDir = expandConfigValue(env("MICME_MODEL_DIR") || join(homedir(), ".cache", "whisper.cpp"));
|
|
116
|
+
const path = join(modelDir, `ggml-${defaultModel}.bin`);
|
|
117
|
+
return {
|
|
118
|
+
path,
|
|
119
|
+
modelName: defaultModel,
|
|
120
|
+
source: env("MICME_DEFAULT_WHISPER_CPP_MODEL") ? "MICME_DEFAULT_WHISPER_CPP_MODEL" : "default whisper.cpp model name",
|
|
121
|
+
exists: existsSync(path),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function resolveBackendPlan({ whisperCpp, whisperStream, whisper, transcribeCommand }) {
|
|
126
|
+
const requestedBackend = getTranscribeBackend();
|
|
127
|
+
const mode = getTranscriptionMode();
|
|
128
|
+
const whisperCppAvailable = Boolean(whisperCpp && existsSync(whisperCpp));
|
|
129
|
+
const whisperStreamAvailable = Boolean(whisperStream && existsSync(whisperStream));
|
|
130
|
+
const pythonAvailable = Boolean(whisper && existsSync(whisper));
|
|
131
|
+
const model = resolveWhisperCppModelSummary();
|
|
132
|
+
const warnings = [];
|
|
133
|
+
|
|
134
|
+
const invalidBackend = env("MICME_TRANSCRIBE_BACKEND")?.trim();
|
|
135
|
+
if (invalidBackend && !TRANSCRIBE_BACKENDS.has(invalidBackend)) warnings.push(`Invalid MICME_TRANSCRIBE_BACKEND=${invalidBackend}; using auto.`);
|
|
136
|
+
|
|
137
|
+
if (mode === "stream") {
|
|
138
|
+
if (requestedBackend === "python") {
|
|
139
|
+
return { requestedBackend, effectiveBackend: "none", effectiveModel: "unavailable", reason: "Streaming mode requires whisper.cpp; Python Whisper only supports clip transcription.", warnings };
|
|
140
|
+
}
|
|
141
|
+
if (requestedBackend === "custom") {
|
|
142
|
+
return { requestedBackend, effectiveBackend: "none", effectiveModel: "unavailable", reason: "Streaming mode requires whisper.cpp; custom transcribe commands only support clip transcription.", warnings };
|
|
143
|
+
}
|
|
144
|
+
if (whisperStreamAvailable) {
|
|
145
|
+
return { requestedBackend, effectiveBackend: "whisper.cpp", binary: whisperStream, model, effectiveModel: model.path, reason: "streaming uses whisper-stream", warnings };
|
|
146
|
+
}
|
|
147
|
+
return { requestedBackend, effectiveBackend: "none", effectiveModel: "unavailable", reason: "MICME_TRANSCRIPTION_MODE=stream but whisper-stream was not found.", warnings };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (requestedBackend === "custom") {
|
|
151
|
+
if (transcribeCommand?.trim()) return { requestedBackend, effectiveBackend: "custom", effectiveModel: "unknown", reason: "MICME_TRANSCRIBE_BACKEND=custom", warnings };
|
|
152
|
+
return { requestedBackend, effectiveBackend: "none", effectiveModel: "unavailable", reason: "MICME_TRANSCRIBE_BACKEND=custom but MICME_TRANSCRIBE_COMMAND is not set.", warnings };
|
|
153
|
+
}
|
|
154
|
+
if (requestedBackend === "whisper.cpp") {
|
|
155
|
+
if (whisperCppAvailable) return { requestedBackend, effectiveBackend: "whisper.cpp", binary: whisperCpp, model, effectiveModel: model.path, reason: "MICME_TRANSCRIBE_BACKEND=whisper.cpp", warnings };
|
|
156
|
+
return { requestedBackend, effectiveBackend: "none", effectiveModel: "unavailable", reason: "MICME_TRANSCRIBE_BACKEND=whisper.cpp but whisper.cpp was not found.", warnings };
|
|
157
|
+
}
|
|
158
|
+
if (requestedBackend === "python") {
|
|
159
|
+
if (pythonAvailable) return { requestedBackend, effectiveBackend: "python", binary: whisper, effectiveModel: env("MICME_WHISPER_MODEL") || "base.en", reason: "MICME_TRANSCRIBE_BACKEND=python", warnings };
|
|
160
|
+
return { requestedBackend, effectiveBackend: "none", effectiveModel: "unavailable", reason: "MICME_TRANSCRIBE_BACKEND=python but the `whisper` CLI was not found.", warnings };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (transcribeCommand?.trim()) return { requestedBackend, effectiveBackend: "custom", effectiveModel: "unknown", reason: "auto selected custom command because MICME_TRANSCRIBE_COMMAND is configured", warnings };
|
|
164
|
+
if (whisperCppAvailable) return { requestedBackend, effectiveBackend: "whisper.cpp", binary: whisperCpp, model, effectiveModel: model.path, reason: "auto selected whisper.cpp because a whisper.cpp binary is available", warnings };
|
|
165
|
+
if (pythonAvailable) return { requestedBackend, effectiveBackend: "python", binary: whisper, effectiveModel: env("MICME_WHISPER_MODEL") || "base.en", reason: "auto selected Python Whisper because whisper.cpp is unavailable", warnings };
|
|
166
|
+
return { requestedBackend, effectiveBackend: "none", effectiveModel: "unavailable", reason: "No Micme transcription backend found.", warnings };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function printBackendPlanDiagnostics(plan) {
|
|
170
|
+
info("requested backend", plan.requestedBackend);
|
|
171
|
+
if (plan.effectiveBackend === "none") warn("effective backend", plan.reason);
|
|
172
|
+
else ok("effective backend", `${plan.effectiveBackend} (${plan.reason})`);
|
|
173
|
+
|
|
174
|
+
if (plan.effectiveBackend === "custom") info("effective model", "unknown; controlled by MICME_TRANSCRIBE_COMMAND");
|
|
175
|
+
else if (plan.effectiveBackend === "whisper.cpp") {
|
|
176
|
+
info("effective model", `${plan.effectiveModel} (${plan.model?.source || "whisper.cpp model"})`);
|
|
177
|
+
if (plan.model && !plan.model.exists) warn("effective whisper.cpp model is missing", plan.effectiveModel);
|
|
178
|
+
} else if (plan.effectiveBackend === "python") info("effective model", plan.effectiveModel);
|
|
179
|
+
else info("effective model", "unavailable");
|
|
180
|
+
|
|
181
|
+
for (const warning of plan.warnings) warn("backend warning", warning);
|
|
182
|
+
}
|
|
183
|
+
|
|
94
184
|
function printConfigDiagnostics() {
|
|
95
185
|
if (micmeConfig.error) warn("micme.json invalid", `${micmeConfig.path}: ${micmeConfig.error}`);
|
|
96
186
|
else if (micmeConfig.found) ok("micme.json loaded", `${micmeConfig.path} (${Object.keys(micmeConfig.values).length} MICME_* key(s))`);
|
|
@@ -152,6 +242,8 @@ async function main() {
|
|
|
152
242
|
if (transcribeCommand) ok("custom transcribe command", summarizeConfiguredCommand(transcribeCommand));
|
|
153
243
|
else info("custom transcribe command", "not set");
|
|
154
244
|
|
|
245
|
+
printBackendPlanDiagnostics(resolveBackendPlan({ whisperCpp, whisperStream, whisper, transcribeCommand }));
|
|
246
|
+
|
|
155
247
|
const recordCommand = env("MICME_RECORD_COMMAND");
|
|
156
248
|
if (recordCommand) ok("custom record command", summarizeConfiguredCommand(recordCommand));
|
|
157
249
|
else info("custom record command", "not set");
|
package/src/backends.ts
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import type { TranscribeBackend, TranscriptionMode, ResolvedTranscriptionPlan, ResolvedWhisperCppModel } from "./types.ts";
|
|
3
|
+
import { DEFAULT_TRANSCRIBE_BACKEND } from "./constants.ts";
|
|
4
|
+
import { env, expandConfigPath, getTranscribeBackend, isTranscribeBackend } from "./config.ts";
|
|
5
|
+
import { getPythonWhisperModelName, resolveWhisperCppModel } from "./models.ts";
|
|
6
|
+
import { findExecutable } from "./processes.ts";
|
|
7
|
+
|
|
8
|
+
export type ResolveTranscriptionPlanOptions = {
|
|
9
|
+
requestedBackend?: TranscribeBackend | string;
|
|
10
|
+
transcriptionMode?: TranscriptionMode;
|
|
11
|
+
customCommand?: string | null;
|
|
12
|
+
whisperCppBinary?: string | null;
|
|
13
|
+
whisperCppBinaryError?: string;
|
|
14
|
+
whisperStreamBinary?: string | null;
|
|
15
|
+
whisperStreamBinaryError?: string;
|
|
16
|
+
pythonWhisperBinary?: string | null;
|
|
17
|
+
whisperCppModel?: ResolvedWhisperCppModel;
|
|
18
|
+
pythonModelName?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function resolveTranscriptionPlan(options: ResolveTranscriptionPlanOptions = {}): ResolvedTranscriptionPlan {
|
|
22
|
+
const warnings: string[] = [];
|
|
23
|
+
const requestedBackend = parseRequestedBackend(options.requestedBackend, warnings);
|
|
24
|
+
const transcriptionMode = options.transcriptionMode ?? "clip";
|
|
25
|
+
const customCommand = getOptionValue(options, "customCommand", () => env("MICME_TRANSCRIBE_COMMAND")?.trim() || undefined);
|
|
26
|
+
const whisperCppModel = options.whisperCppModel ?? resolveWhisperCppModel();
|
|
27
|
+
const pythonModelName = options.pythonModelName ?? getPythonWhisperModelName();
|
|
28
|
+
|
|
29
|
+
if (transcriptionMode === "stream") {
|
|
30
|
+
return resolveStreamingPlan({
|
|
31
|
+
requestedBackend,
|
|
32
|
+
customCommand: customCommand ?? undefined,
|
|
33
|
+
whisperCppModel,
|
|
34
|
+
warnings,
|
|
35
|
+
whisperStreamBinary: getExecutableOption(options, "whisperStreamBinary", "whisperStreamBinaryError", getWhisperStreamBinary),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const whisperCppBinary = getExecutableOption(options, "whisperCppBinary", "whisperCppBinaryError", getWhisperCppBinary);
|
|
40
|
+
const pythonWhisperBinary = getOptionValue(options, "pythonWhisperBinary", getPythonWhisperBinary);
|
|
41
|
+
|
|
42
|
+
if (requestedBackend === "custom") {
|
|
43
|
+
return customCommand
|
|
44
|
+
? customPlan(requestedBackend, customCommand, "MICME_TRANSCRIBE_BACKEND=custom")
|
|
45
|
+
: nonePlan(requestedBackend, "MICME_TRANSCRIBE_BACKEND=custom but MICME_TRANSCRIBE_COMMAND is not set.", warnings);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (requestedBackend === "whisper.cpp") {
|
|
49
|
+
return whisperCppBinary
|
|
50
|
+
? whisperCppPlan(requestedBackend, whisperCppBinary, whisperCppModel, "MICME_TRANSCRIBE_BACKEND=whisper.cpp")
|
|
51
|
+
: nonePlan(requestedBackend, "MICME_TRANSCRIBE_BACKEND=whisper.cpp but whisper.cpp was not found.", warnings);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (requestedBackend === "python") {
|
|
55
|
+
return pythonWhisperBinary
|
|
56
|
+
? pythonPlan(requestedBackend, pythonWhisperBinary, pythonModelName, "MICME_TRANSCRIBE_BACKEND=python")
|
|
57
|
+
: nonePlan(requestedBackend, "MICME_TRANSCRIBE_BACKEND=python but the `whisper` CLI was not found.", warnings);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (customCommand) return customPlan(requestedBackend, customCommand, "auto selected custom command because MICME_TRANSCRIBE_COMMAND is configured");
|
|
61
|
+
if (whisperCppBinary) return whisperCppPlan(requestedBackend, whisperCppBinary, whisperCppModel, "auto selected whisper.cpp because a whisper.cpp binary is available");
|
|
62
|
+
if (pythonWhisperBinary) return pythonPlan(requestedBackend, pythonWhisperBinary, pythonModelName, "auto selected Python Whisper because whisper.cpp is unavailable");
|
|
63
|
+
|
|
64
|
+
return nonePlan(
|
|
65
|
+
requestedBackend,
|
|
66
|
+
"No Micme transcription backend found. Install whisper-cpp, install openai-whisper, set MICME_TRANSCRIBE_COMMAND, or choose a backend in /micme conf.",
|
|
67
|
+
warnings,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function getWhisperCppBinary() {
|
|
72
|
+
const configured = env("MICME_WHISPER_CPP_BIN")?.trim();
|
|
73
|
+
if (configured) return resolveExecutableConfig(configured, "MICME_WHISPER_CPP_BIN");
|
|
74
|
+
return findExecutable(["whisper-cli", "whisper-cpp"]);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function getWhisperStreamBinary() {
|
|
78
|
+
const configured = env("MICME_WHISPER_STREAM_BIN")?.trim();
|
|
79
|
+
if (configured) return resolveExecutableConfig(configured, "MICME_WHISPER_STREAM_BIN");
|
|
80
|
+
return findExecutable(["whisper-stream"]);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function getPythonWhisperBinary() {
|
|
84
|
+
return findExecutable(["whisper"]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function resolveExecutableConfig(value: string, configName: string) {
|
|
88
|
+
const expanded = expandConfigPath(value);
|
|
89
|
+
if (/[/\\]/.test(expanded)) {
|
|
90
|
+
if (!existsSync(expanded)) throw new Error(`${configName} is set but not found: ${expanded}`);
|
|
91
|
+
return expanded;
|
|
92
|
+
}
|
|
93
|
+
const executable = findExecutable([expanded]);
|
|
94
|
+
if (!executable) throw new Error(`${configName} is set but not found on PATH: ${expanded}`);
|
|
95
|
+
return executable;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function formatTranscriptionPlan(plan: ResolvedTranscriptionPlan) {
|
|
99
|
+
const lines = [`Requested backend: ${formatBackendLabel(plan.requestedBackend)}`, `Effective backend: ${formatEffectiveBackendLabel(plan.effectiveBackend)}`];
|
|
100
|
+
if (plan.binary) lines.push(`Binary: ${plan.binary}`);
|
|
101
|
+
if (plan.modelPath) lines.push(`Model: ${plan.modelPath}`);
|
|
102
|
+
else if (plan.modelName) lines.push(`Model: ${plan.modelName}`);
|
|
103
|
+
if (plan.modelSource) lines.push(`Source: ${plan.modelSource}`);
|
|
104
|
+
for (const warning of plan.warnings) lines.push(`Warning: ${warning}`);
|
|
105
|
+
lines.push(`Reason: ${plan.reason}`);
|
|
106
|
+
return lines.join("\n");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function formatBackendLabel(backend: TranscribeBackend) {
|
|
110
|
+
switch (backend) {
|
|
111
|
+
case "auto":
|
|
112
|
+
return "Auto";
|
|
113
|
+
case "whisper.cpp":
|
|
114
|
+
return "whisper.cpp";
|
|
115
|
+
case "python":
|
|
116
|
+
return "Python Whisper";
|
|
117
|
+
case "custom":
|
|
118
|
+
return "Custom command";
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function formatEffectiveBackendLabel(backend: ResolvedTranscriptionPlan["effectiveBackend"]) {
|
|
123
|
+
switch (backend) {
|
|
124
|
+
case "whisper.cpp":
|
|
125
|
+
return "whisper.cpp";
|
|
126
|
+
case "python":
|
|
127
|
+
return "Python Whisper";
|
|
128
|
+
case "custom":
|
|
129
|
+
return "Custom command";
|
|
130
|
+
case "none":
|
|
131
|
+
return "none";
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function resolveStreamingPlan(options: {
|
|
136
|
+
requestedBackend: TranscribeBackend;
|
|
137
|
+
customCommand?: string;
|
|
138
|
+
whisperCppModel: ResolvedWhisperCppModel;
|
|
139
|
+
warnings: string[];
|
|
140
|
+
whisperStreamBinary?: string;
|
|
141
|
+
}): ResolvedTranscriptionPlan {
|
|
142
|
+
const { requestedBackend, whisperCppModel, warnings, whisperStreamBinary } = options;
|
|
143
|
+
if (requestedBackend === "python") {
|
|
144
|
+
return nonePlan(requestedBackend, "Streaming mode requires whisper.cpp; Python Whisper only supports clip transcription.", warnings);
|
|
145
|
+
}
|
|
146
|
+
if (requestedBackend === "custom") {
|
|
147
|
+
return nonePlan(requestedBackend, "Streaming mode requires whisper.cpp; custom transcribe commands only support clip transcription.", warnings);
|
|
148
|
+
}
|
|
149
|
+
if (!whisperStreamBinary) {
|
|
150
|
+
const reason = requestedBackend === "auto"
|
|
151
|
+
? "MICME_TRANSCRIPTION_MODE=stream but whisper-stream was not found. Auto stream mode requires whisper.cpp/whisper-stream."
|
|
152
|
+
: "MICME_TRANSCRIBE_BACKEND=whisper.cpp and MICME_TRANSCRIPTION_MODE=stream but whisper-stream was not found.";
|
|
153
|
+
return nonePlan(requestedBackend, reason, warnings);
|
|
154
|
+
}
|
|
155
|
+
return whisperCppPlan(requestedBackend, whisperStreamBinary, whisperCppModel, "streaming selected whisper.cpp because whisper-stream is available");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function customPlan(requestedBackend: TranscribeBackend, command: string, reason: string): ResolvedTranscriptionPlan {
|
|
159
|
+
return {
|
|
160
|
+
requestedBackend,
|
|
161
|
+
effectiveBackend: "custom",
|
|
162
|
+
reason,
|
|
163
|
+
command,
|
|
164
|
+
modelName: "unknown",
|
|
165
|
+
modelSource: "custom-command",
|
|
166
|
+
warnings: [],
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function whisperCppPlan(requestedBackend: TranscribeBackend, binary: string, model: ResolvedWhisperCppModel, reason: string): ResolvedTranscriptionPlan {
|
|
171
|
+
const warnings: string[] = [];
|
|
172
|
+
if (model.source === "explicit-path" && !model.exists && !model.downloadable) {
|
|
173
|
+
warnings.push(`MICME_WHISPER_CPP_MODEL is set but not found: ${model.path}`);
|
|
174
|
+
} else if (!model.exists && !model.downloadable) {
|
|
175
|
+
warnings.push(`Whisper.cpp model is missing and is not a standard downloadable model: ${model.path}`);
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
requestedBackend,
|
|
179
|
+
effectiveBackend: "whisper.cpp",
|
|
180
|
+
reason,
|
|
181
|
+
binary,
|
|
182
|
+
modelName: model.modelName,
|
|
183
|
+
modelPath: model.path,
|
|
184
|
+
modelSource: model.source,
|
|
185
|
+
modelDownloadable: model.downloadable,
|
|
186
|
+
warnings,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function pythonPlan(requestedBackend: TranscribeBackend, binary: string, modelName: string, reason: string): ResolvedTranscriptionPlan {
|
|
191
|
+
return {
|
|
192
|
+
requestedBackend,
|
|
193
|
+
effectiveBackend: "python",
|
|
194
|
+
reason,
|
|
195
|
+
binary,
|
|
196
|
+
modelName,
|
|
197
|
+
modelSource: "python-name",
|
|
198
|
+
warnings: [],
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function nonePlan(requestedBackend: TranscribeBackend, reason: string, warnings: string[]): ResolvedTranscriptionPlan {
|
|
203
|
+
return {
|
|
204
|
+
requestedBackend,
|
|
205
|
+
effectiveBackend: "none",
|
|
206
|
+
reason,
|
|
207
|
+
warnings: [...warnings],
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function parseRequestedBackend(value: TranscribeBackend | string | undefined, warnings: string[]) {
|
|
212
|
+
const raw = value ?? env("MICME_TRANSCRIBE_BACKEND")?.trim();
|
|
213
|
+
if (!raw) return getTranscribeBackend();
|
|
214
|
+
if (isTranscribeBackend(raw)) return raw;
|
|
215
|
+
warnings.push(`Invalid MICME_TRANSCRIBE_BACKEND=${raw}; using ${DEFAULT_TRANSCRIBE_BACKEND}.`);
|
|
216
|
+
return DEFAULT_TRANSCRIBE_BACKEND;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function getOptionValue<K extends keyof ResolveTranscriptionPlanOptions>(
|
|
220
|
+
options: ResolveTranscriptionPlanOptions,
|
|
221
|
+
key: K,
|
|
222
|
+
fallback: () => Extract<ResolveTranscriptionPlanOptions[K], string | null | undefined>,
|
|
223
|
+
) {
|
|
224
|
+
if (Object.prototype.hasOwnProperty.call(options, key)) {
|
|
225
|
+
const value = options[key];
|
|
226
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
227
|
+
}
|
|
228
|
+
const value = fallback();
|
|
229
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function getExecutableOption(
|
|
233
|
+
options: ResolveTranscriptionPlanOptions,
|
|
234
|
+
key: "whisperCppBinary" | "whisperStreamBinary",
|
|
235
|
+
errorKey: "whisperCppBinaryError" | "whisperStreamBinaryError",
|
|
236
|
+
fallback: () => string | undefined,
|
|
237
|
+
) {
|
|
238
|
+
const error = options[errorKey];
|
|
239
|
+
if (error) return undefined;
|
|
240
|
+
if (Object.prototype.hasOwnProperty.call(options, key)) {
|
|
241
|
+
const value = options[key];
|
|
242
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
243
|
+
}
|
|
244
|
+
try {
|
|
245
|
+
return fallback();
|
|
246
|
+
} catch {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { mkdir, rename, rm, writeFile } from "node:fs/promises";
|
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { dirname, join, resolve } from "node:path";
|
|
6
|
-
import type { MicmeConfigState, TranscriptionMode } from "./types.ts";
|
|
6
|
+
import type { MicmeConfigState, TranscribeBackend, TranscriptionMode } from "./types.ts";
|
|
7
7
|
import {
|
|
8
8
|
DEFAULT_MACOS_PRINTABLE_SHORTCUT,
|
|
9
9
|
DEFAULT_RECORD_SAMPLE_RATE,
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
DEFAULT_STREAM_STEP_MS,
|
|
15
15
|
DEFAULT_STREAM_VAD_THRESHOLD,
|
|
16
16
|
DEFAULT_STREAM_FLUSH_MS,
|
|
17
|
+
DEFAULT_TRANSCRIBE_BACKEND,
|
|
17
18
|
DEFAULT_TRANSCRIBE_SAMPLE_RATE,
|
|
18
19
|
DEFAULT_TRANSCRIBE_TIMEOUT_MS,
|
|
19
20
|
DEFAULT_MIN_MAX_VOLUME_DB,
|
|
@@ -154,6 +155,15 @@ export function getTranscriptionMode() {
|
|
|
154
155
|
return env("MICME_TRANSCRIPTION_MODE") === "stream" ? "stream" : "clip";
|
|
155
156
|
}
|
|
156
157
|
|
|
158
|
+
export function getTranscribeBackend(): TranscribeBackend {
|
|
159
|
+
const value = env("MICME_TRANSCRIBE_BACKEND")?.trim();
|
|
160
|
+
return isTranscribeBackend(value) ? value : DEFAULT_TRANSCRIBE_BACKEND;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function isTranscribeBackend(value: string | undefined): value is TranscribeBackend {
|
|
164
|
+
return value === "auto" || value === "whisper.cpp" || value === "python" || value === "custom";
|
|
165
|
+
}
|
|
166
|
+
|
|
157
167
|
export function getPrintableShortcuts() {
|
|
158
168
|
const configured = env("MICME_PRINTABLE_SHORTCUTS");
|
|
159
169
|
if (configured !== undefined) {
|
package/src/constants.ts
CHANGED
|
@@ -25,7 +25,9 @@ export const STREAM_PROFILE_VAD_THRESHOLD = 0.35;
|
|
|
25
25
|
export const STREAM_PROFILE_FLUSH_MS = 650;
|
|
26
26
|
export const DEFAULT_MIN_MAX_VOLUME_DB = -50;
|
|
27
27
|
export const AUDIO_VALIDATION_TIMEOUT_MS = 30_000;
|
|
28
|
+
export const DEFAULT_TRANSCRIBE_BACKEND = "auto";
|
|
28
29
|
export const DEFAULT_WHISPER_CPP_MODEL_NAME = "small.en";
|
|
30
|
+
export const DEFAULT_PYTHON_WHISPER_MODEL_NAME = "base.en";
|
|
29
31
|
export const WHISPER_CPP_MODEL_BASE_URL = "https://huggingface.co/ggerganov/whisper.cpp/resolve/main";
|
|
30
32
|
export const WHISPER_CPP_MODEL_NAMES = [
|
|
31
33
|
"tiny.en",
|
package/src/extension.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { RECORDER_STARTUP_GRACE_MS, STATUS_KEY } from "./constants.ts";
|
|
|
6
6
|
import {
|
|
7
7
|
env,
|
|
8
8
|
envFlag,
|
|
9
|
-
expandConfigPath,
|
|
10
9
|
getShortcut,
|
|
11
10
|
getStreamFinalizeWithClip,
|
|
12
11
|
getTranscriptionMode,
|
|
@@ -14,7 +13,8 @@ import {
|
|
|
14
13
|
} from "./config.ts";
|
|
15
14
|
import { buildRecorderCommand, listAudioDevices, prepareAudioForTranscription, registerDeviceMessageRenderer, validateRecordedAudio } from "./audio.ts";
|
|
16
15
|
import { installMicmeEditorFallback, type MicmeEditorInputHandlers } from "./editor.ts";
|
|
17
|
-
import {
|
|
16
|
+
import { resolveTranscriptionPlan, formatTranscriptionPlan } from "./backends.ts";
|
|
17
|
+
import { ensureWhisperCppModel } from "./models.ts";
|
|
18
18
|
import {
|
|
19
19
|
cleanup,
|
|
20
20
|
formatExit,
|
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
showStreamingDiagnostics,
|
|
39
39
|
} from "./streaming.ts";
|
|
40
40
|
import { pasteOrSubmitTranscript } from "./transcript-delivery.ts";
|
|
41
|
-
import {
|
|
41
|
+
import { transcribe } from "./transcription.ts";
|
|
42
42
|
import type { Recording } from "./types.ts";
|
|
43
43
|
|
|
44
44
|
const MICME_ACTIONS = ["devices", "conf", "last", "audio", "help"] as const;
|
|
@@ -240,16 +240,15 @@ async function stopAndTranscribe(ctx: ExtensionContext, pi: ExtensionAPI) {
|
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
async function startStreamingTranscription(ctx: ExtensionContext, stopHint = getShortcut()) {
|
|
243
|
-
const
|
|
244
|
-
if (!
|
|
245
|
-
throw new Error(
|
|
243
|
+
const plan = resolveTranscriptionPlan({ transcriptionMode: "stream" });
|
|
244
|
+
if (plan.effectiveBackend !== "whisper.cpp" || !plan.binary || !plan.modelPath) {
|
|
245
|
+
throw new Error(formatTranscriptionPlan(plan));
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
|
|
249
|
-
await ensureWhisperCppModel(whisperCppModel, ctx);
|
|
248
|
+
await ensureWhisperCppModel(plan.modelPath, ctx, { allowDownload: plan.modelDownloadable !== false });
|
|
250
249
|
|
|
251
250
|
const tempDir = await mkdtemp(join(tmpdir(), "micme-stream-"));
|
|
252
|
-
const command = buildWhisperStreamCommand(
|
|
251
|
+
const command = buildWhisperStreamCommand(plan.binary, plan.modelPath, tempDir);
|
|
253
252
|
const active = spawnRecording(command, "", tempDir);
|
|
254
253
|
const baseText = ctx.ui.getEditorText();
|
|
255
254
|
active.streaming = {
|
|
@@ -358,7 +357,4 @@ async function stopStreamingTranscription(ctx: ExtensionContext, pi: ExtensionAP
|
|
|
358
357
|
ctx.ui.setStatus(STATUS_KEY, undefined);
|
|
359
358
|
}
|
|
360
359
|
|
|
361
|
-
function getConfiguredWhisperCppModel() {
|
|
362
|
-
return env("MICME_WHISPER_CPP_MODEL") || getDefaultWhisperCppModelPath();
|
|
363
|
-
}
|
|
364
360
|
|
package/src/models.ts
CHANGED
|
@@ -6,13 +6,16 @@ import { homedir } from "node:os";
|
|
|
6
6
|
import { basename, dirname, join } from "node:path";
|
|
7
7
|
import { finished } from "node:stream/promises";
|
|
8
8
|
import {
|
|
9
|
+
DEFAULT_PYTHON_WHISPER_MODEL_NAME,
|
|
9
10
|
DEFAULT_WHISPER_CPP_MODEL_NAME,
|
|
11
|
+
PYTHON_WHISPER_MODEL_NAMES,
|
|
10
12
|
STATUS_KEY,
|
|
11
13
|
WHISPER_CPP_MODEL_BASE_URL,
|
|
12
14
|
WHISPER_CPP_MODEL_NAMES,
|
|
13
15
|
} from "./constants.ts";
|
|
14
16
|
import { env, expandConfigPath } from "./config.ts";
|
|
15
|
-
import
|
|
17
|
+
import { findExecutable, runProcess } from "./processes.ts";
|
|
18
|
+
import type { ModelCandidate, ResolvedWhisperCppModel } from "./types.ts";
|
|
16
19
|
|
|
17
20
|
const modelDownloads = new Map<string, Promise<void>>();
|
|
18
21
|
|
|
@@ -32,23 +35,25 @@ export function discoverWhisperCppModels(cwd: string): ModelCandidate[] {
|
|
|
32
35
|
add({
|
|
33
36
|
label: basename(expanded),
|
|
34
37
|
value: expanded,
|
|
35
|
-
description: existsSync(expanded) ? `current
|
|
38
|
+
description: existsSync(expanded) ? `current explicit path: ${expanded}` : `current explicit path is missing: ${expanded}`,
|
|
36
39
|
installed: existsSync(expanded),
|
|
40
|
+
kind: "path",
|
|
37
41
|
});
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
for (const file of scanModelFiles(cwd)) {
|
|
41
|
-
add({ label: basename(file), value: file, description: file, installed: true });
|
|
45
|
+
add({ label: basename(file), value: file, description: file, installed: true, kind: "path" });
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
const cacheDir = getWhisperCppModelCacheDir();
|
|
45
49
|
for (const modelName of WHISPER_CPP_MODEL_NAMES) {
|
|
46
50
|
const path = join(cacheDir, `ggml-${modelName}.bin`);
|
|
47
51
|
add({
|
|
48
|
-
label:
|
|
52
|
+
label: modelName,
|
|
49
53
|
value: path,
|
|
50
|
-
description: `${describeWhisperModel(modelName)}${existsSync(path) ? "" : " (expected path; download model first)"}`,
|
|
54
|
+
description: `${describeWhisperModel(modelName)} • ${basename(path)}${existsSync(path) ? "" : " (expected path; download model first)"}`,
|
|
51
55
|
installed: existsSync(path),
|
|
56
|
+
kind: "model-name",
|
|
52
57
|
});
|
|
53
58
|
}
|
|
54
59
|
|
|
@@ -111,8 +116,80 @@ export function describeWhisperModel(name: string) {
|
|
|
111
116
|
return "Whisper model";
|
|
112
117
|
}
|
|
113
118
|
|
|
114
|
-
export
|
|
119
|
+
export function resolveWhisperCppModel(): ResolvedWhisperCppModel {
|
|
120
|
+
const explicitPath = env("MICME_WHISPER_CPP_MODEL")?.trim();
|
|
121
|
+
if (explicitPath) {
|
|
122
|
+
const path = expandConfigPath(explicitPath);
|
|
123
|
+
return {
|
|
124
|
+
path,
|
|
125
|
+
modelName: getWhisperCppModelNameFromPath(path),
|
|
126
|
+
source: "explicit-path",
|
|
127
|
+
configuredValue: explicitPath,
|
|
128
|
+
exists: existsSync(path),
|
|
129
|
+
downloadable: isDownloadableWhisperCppModelPath(path),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const configuredName = env("MICME_DEFAULT_WHISPER_CPP_MODEL")?.trim();
|
|
134
|
+
const modelName = configuredName || DEFAULT_WHISPER_CPP_MODEL_NAME;
|
|
135
|
+
const path = join(getWhisperCppModelCacheDir(), `ggml-${modelName}.bin`);
|
|
136
|
+
return {
|
|
137
|
+
path,
|
|
138
|
+
modelName,
|
|
139
|
+
source: configuredName ? "configured-name" : "default-name",
|
|
140
|
+
configuredValue: configuredName,
|
|
141
|
+
exists: existsSync(path),
|
|
142
|
+
downloadable: isDownloadableWhisperCppModelPath(path),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function getPythonWhisperModelName() {
|
|
147
|
+
return env("MICME_WHISPER_MODEL")?.trim() || DEFAULT_PYTHON_WHISPER_MODEL_NAME;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function discoverPythonWhisperModels(): Promise<ModelCandidate[]> {
|
|
151
|
+
const dynamicNames = await queryPythonWhisperModelNames();
|
|
152
|
+
const names = dynamicNames.length > 0 ? dynamicNames : [...PYTHON_WHISPER_MODEL_NAMES];
|
|
153
|
+
const source = dynamicNames.length > 0 ? "reported by whisper.available_models()" : "built-in fallback list";
|
|
154
|
+
return names.map((name) => ({
|
|
155
|
+
label: name,
|
|
156
|
+
value: name,
|
|
157
|
+
description: `${describeWhisperModel(name)} • ${source}`,
|
|
158
|
+
installed: dynamicNames.length > 0,
|
|
159
|
+
kind: "model-name",
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export async function queryPythonWhisperModelNames(): Promise<string[]> {
|
|
164
|
+
const python = findExecutable(["python3", "python"]);
|
|
165
|
+
if (!python) return [];
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
const result = await runProcess(python, ["-c", "import whisper; print('\\n'.join(whisper.available_models()))"], 2_000);
|
|
169
|
+
if (result.code !== 0 || result.timedOut) return [];
|
|
170
|
+
return uniqueModelNames(result.stdout.split(/\r?\n/).map((line) => line.trim()).filter(Boolean));
|
|
171
|
+
} catch {
|
|
172
|
+
return [];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function uniqueModelNames(names: string[]) {
|
|
177
|
+
const seen = new Set<string>();
|
|
178
|
+
const output: string[] = [];
|
|
179
|
+
for (const name of names) {
|
|
180
|
+
const normalized = name.trim();
|
|
181
|
+
if (!normalized || seen.has(normalized)) continue;
|
|
182
|
+
seen.add(normalized);
|
|
183
|
+
output.push(normalized);
|
|
184
|
+
}
|
|
185
|
+
return output;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export async function ensureWhisperCppModel(modelPath: string, ctx?: ExtensionContext, options: { allowDownload?: boolean } = {}) {
|
|
115
189
|
if (existsSync(modelPath)) return;
|
|
190
|
+
if (options.allowDownload === false) {
|
|
191
|
+
throw new Error(`Micme model is missing: ${modelPath}`);
|
|
192
|
+
}
|
|
116
193
|
if (env("MICME_AUTO_DOWNLOAD_MODEL") === "0") {
|
|
117
194
|
throw new Error(`Micme model is missing and auto-download is disabled: ${modelPath}`);
|
|
118
195
|
}
|
|
@@ -128,9 +205,9 @@ export async function ensureWhisperCppModel(modelPath: string, ctx?: ExtensionCo
|
|
|
128
205
|
return;
|
|
129
206
|
}
|
|
130
207
|
|
|
131
|
-
const modelName =
|
|
208
|
+
const modelName = getDownloadableWhisperCppModelName(modelPath);
|
|
132
209
|
if (!modelName) {
|
|
133
|
-
throw new Error(`Micme model is missing and cannot infer download URL: ${modelPath}`);
|
|
210
|
+
throw new Error(`Micme model is missing and cannot infer a standard download URL: ${modelPath}`);
|
|
134
211
|
}
|
|
135
212
|
|
|
136
213
|
const download = downloadWhisperCppModel(modelName, modelPath, ctx);
|
|
@@ -204,6 +281,20 @@ export function getWhisperCppModelNameFromPath(modelPath: string) {
|
|
|
204
281
|
return match?.[1];
|
|
205
282
|
}
|
|
206
283
|
|
|
284
|
+
export function getDownloadableWhisperCppModelName(modelPath: string) {
|
|
285
|
+
const match = basename(modelPath).match(/^ggml-(.+)\.bin$/i);
|
|
286
|
+
const modelName = match?.[1];
|
|
287
|
+
return modelName && isKnownWhisperCppModelName(modelName) ? modelName : undefined;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function isDownloadableWhisperCppModelPath(modelPath: string) {
|
|
291
|
+
return getDownloadableWhisperCppModelName(modelPath) !== undefined;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export function isKnownWhisperCppModelName(modelName: string): modelName is (typeof WHISPER_CPP_MODEL_NAMES)[number] {
|
|
295
|
+
return WHISPER_CPP_MODEL_NAMES.includes(modelName as (typeof WHISPER_CPP_MODEL_NAMES)[number]);
|
|
296
|
+
}
|
|
297
|
+
|
|
207
298
|
export function getWhisperCppModelUrl(modelName: string) {
|
|
208
299
|
return `${WHISPER_CPP_MODEL_BASE_URL}/ggml-${modelName}.bin`;
|
|
209
300
|
}
|
|
@@ -213,7 +304,7 @@ export function getWhisperCppModelCacheDir() {
|
|
|
213
304
|
}
|
|
214
305
|
|
|
215
306
|
export function getDefaultWhisperCppModelPath() {
|
|
216
|
-
const modelName = env("MICME_DEFAULT_WHISPER_CPP_MODEL") || DEFAULT_WHISPER_CPP_MODEL_NAME;
|
|
307
|
+
const modelName = env("MICME_DEFAULT_WHISPER_CPP_MODEL")?.trim() || DEFAULT_WHISPER_CPP_MODEL_NAME;
|
|
217
308
|
return join(getWhisperCppModelCacheDir(), `ggml-${modelName}.bin`);
|
|
218
309
|
}
|
|
219
310
|
|
package/src/settings.ts
CHANGED
|
@@ -20,9 +20,6 @@ import {
|
|
|
20
20
|
DEFAULT_STREAM_VAD_THRESHOLD,
|
|
21
21
|
DEFAULT_STREAM_FLUSH_MS,
|
|
22
22
|
DEFAULT_TRANSCRIBE_SAMPLE_RATE,
|
|
23
|
-
DEFAULT_WHISPER_CPP_MODEL_NAME,
|
|
24
|
-
PYTHON_WHISPER_MODEL_NAMES,
|
|
25
|
-
WHISPER_CPP_MODEL_NAMES,
|
|
26
23
|
} from "./constants.ts";
|
|
27
24
|
import {
|
|
28
25
|
env,
|
|
@@ -33,13 +30,14 @@ import {
|
|
|
33
30
|
writeMicmeConfigValues,
|
|
34
31
|
} from "./config.ts";
|
|
35
32
|
import { discoverAudioDevices } from "./audio.ts";
|
|
36
|
-
import {
|
|
33
|
+
import { formatBackendLabel, resolveTranscriptionPlan } from "./backends.ts";
|
|
34
|
+
import { discoverPythonWhisperModels, discoverWhisperCppModels, ensureWhisperCppModel, resolveWhisperCppModel } from "./models.ts";
|
|
37
35
|
import { findExecutable } from "./processes.ts";
|
|
38
|
-
import type { AudioDeviceCandidate, ModelCandidate } from "./types.ts";
|
|
36
|
+
import type { AudioDeviceCandidate, ModelCandidate, ResolvedTranscriptionPlan } from "./types.ts";
|
|
39
37
|
|
|
40
38
|
type MicmeTheme = ExtensionContext["ui"]["theme"];
|
|
41
39
|
|
|
42
|
-
type ConfigurationCategoryId = "general" | "transcription" | "streaming" | "audio"
|
|
40
|
+
type ConfigurationCategoryId = "general" | "transcription" | "streaming" | "audio";
|
|
43
41
|
type FocusedPane = "categories" | "settings";
|
|
44
42
|
type DisplayKind = "boolean" | "number" | "path" | "slider" | "text" | "model";
|
|
45
43
|
|
|
@@ -55,6 +53,7 @@ interface ConfigurationItem extends SettingItem {
|
|
|
55
53
|
displayKind?: DisplayKind;
|
|
56
54
|
emptyLabel?: string;
|
|
57
55
|
valueLabels?: Record<string, string>;
|
|
56
|
+
visibleWhen?: (plan: ResolvedTranscriptionPlan) => boolean;
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
const CONFIGURATION_CATEGORIES: ConfigurationCategory[] = [
|
|
@@ -62,8 +61,6 @@ const CONFIGURATION_CATEGORIES: ConfigurationCategory[] = [
|
|
|
62
61
|
{ id: "transcription", label: "Transcription", description: "Backend model, mode, and transcription fallback settings." },
|
|
63
62
|
{ id: "streaming", label: "Streaming", description: "Low-latency live transcription behavior." },
|
|
64
63
|
{ id: "audio", label: "Audio", description: "Recording, preprocessing, and metering settings." },
|
|
65
|
-
{ id: "shortcuts", label: "Shortcuts", description: "Terminal and printable-character shortcut bindings." },
|
|
66
|
-
{ id: "diagnostics", label: "Diagnostics", description: "Debug and timing output." },
|
|
67
64
|
];
|
|
68
65
|
|
|
69
66
|
const TWO_PANE_MIN_WIDTH = 72;
|
|
@@ -81,9 +78,10 @@ export async function showConfiguration(ctx: ExtensionContext) {
|
|
|
81
78
|
}
|
|
82
79
|
const audioDevices = await discoverAudioDevices();
|
|
83
80
|
const modelCandidates = discoverWhisperCppModels(ctx.cwd);
|
|
81
|
+
const pythonModelCandidates = await discoverPythonWhisperModels();
|
|
84
82
|
|
|
85
83
|
await ctx.ui.custom<void>((tui, theme, _keybindings, done) => {
|
|
86
|
-
const items = buildConfigurationItems(modelCandidates, audioDevices, theme);
|
|
84
|
+
const items = buildConfigurationItems(modelCandidates, pythonModelCandidates, audioDevices, theme);
|
|
87
85
|
return new ConfigurationScreen({
|
|
88
86
|
configPath: configState.path,
|
|
89
87
|
items,
|
|
@@ -134,6 +132,7 @@ class ConfigurationScreen implements Component {
|
|
|
134
132
|
}
|
|
135
133
|
|
|
136
134
|
render(width: number): string[] {
|
|
135
|
+
this.refreshDerivedItems();
|
|
137
136
|
if (this.submenuComponent) return this.submenuComponent.render(width);
|
|
138
137
|
if (width < TWO_PANE_MIN_WIDTH) return this.renderNarrow(width);
|
|
139
138
|
return this.renderTwoPane(width);
|
|
@@ -350,9 +349,9 @@ class ConfigurationScreen implements Component {
|
|
|
350
349
|
const category = this.currentCategory();
|
|
351
350
|
const selection = this.getSelectionText();
|
|
352
351
|
const search = this.searchActive ? `Search: ${this.searchQuery || "type to filter all settings"}` : "";
|
|
353
|
-
const lead = this.statusText || search
|
|
352
|
+
const lead = this.statusText || search;
|
|
354
353
|
const description = selected?.description ?? category.description;
|
|
355
|
-
return `${lead} • ${selection} • ${description}`;
|
|
354
|
+
return lead ? `${lead} • ${selection} • ${description}` : `${selection} • ${description}`;
|
|
356
355
|
}
|
|
357
356
|
|
|
358
357
|
private formatValue(item: ConfigurationItem, width: number) {
|
|
@@ -409,12 +408,22 @@ class ConfigurationScreen implements Component {
|
|
|
409
408
|
}
|
|
410
409
|
|
|
411
410
|
private getCategoryItems(categoryId = this.currentCategory().id) {
|
|
412
|
-
|
|
411
|
+
const plan = this.getCurrentPlan();
|
|
412
|
+
return this.items.filter((item) => item.categoryId === categoryId && this.isItemVisible(item, plan));
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
private getVisibleItems() {
|
|
416
|
+
const plan = this.getCurrentPlan();
|
|
417
|
+
return this.items.filter((item) => this.isItemVisible(item, plan));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
private isItemVisible(item: ConfigurationItem, plan: ResolvedTranscriptionPlan) {
|
|
421
|
+
return item.visibleWhen ? item.visibleWhen(plan) : true;
|
|
413
422
|
}
|
|
414
423
|
|
|
415
424
|
private getDisplaySettings() {
|
|
416
425
|
if (!this.hasSearchQuery()) return this.getCategoryItems();
|
|
417
|
-
return fuzzyFilter(this.
|
|
426
|
+
return fuzzyFilter(this.getVisibleItems(), this.searchQuery, (item) => `${item.label} ${item.id} ${item.description ?? ""} ${this.getCategory(item.categoryId).label}`);
|
|
418
427
|
}
|
|
419
428
|
|
|
420
429
|
private getSelectedSetting() {
|
|
@@ -479,7 +488,8 @@ class ConfigurationScreen implements Component {
|
|
|
479
488
|
void this.onSave(item.id, nextValue)
|
|
480
489
|
.then((updatedValues) => {
|
|
481
490
|
this.updateValues(updatedValues);
|
|
482
|
-
this.
|
|
491
|
+
this.refreshDerivedItems();
|
|
492
|
+
this.clampSelections();
|
|
483
493
|
this.statusText = formatSaveStatus(item.id, nextValue);
|
|
484
494
|
})
|
|
485
495
|
.catch((error) => {
|
|
@@ -501,14 +511,41 @@ class ConfigurationScreen implements Component {
|
|
|
501
511
|
}
|
|
502
512
|
}
|
|
503
513
|
|
|
504
|
-
private
|
|
505
|
-
|
|
506
|
-
const
|
|
507
|
-
if (!
|
|
508
|
-
|
|
509
|
-
|
|
514
|
+
private refreshDerivedItems() {
|
|
515
|
+
const plan = this.getCurrentPlan();
|
|
516
|
+
const backend = this.items.find((candidate) => candidate.id === "MICME_TRANSCRIBE_BACKEND");
|
|
517
|
+
if (backend && !["whisper.cpp", "python"].includes(backend.rawValue)) {
|
|
518
|
+
backend.rawValue = getUiBackendValue(plan);
|
|
519
|
+
backend.currentValue = displayConfigurationValue(backend.id, backend.rawValue);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
const model = this.items.find((candidate) => candidate.id === "MICME_WHISPER_CPP_MODEL");
|
|
523
|
+
if (model) {
|
|
524
|
+
model.rawValue = getCurrentWhisperCppModelValue();
|
|
525
|
+
model.currentValue = displayConfigurationValue(model.id, model.rawValue);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const mode = this.items.find((candidate) => candidate.id === "MICME_TRANSCRIPTION_MODE");
|
|
529
|
+
if (mode) {
|
|
530
|
+
const base = "Changing this applies the matching profile: stable clip defaults or low-latency stream settings.";
|
|
531
|
+
mode.description = plan.requestedBackend === "python" || plan.requestedBackend === "custom"
|
|
532
|
+
? `${base} Streaming mode requires whisper.cpp. Switch to clip mode or choose auto/whisper.cpp.`
|
|
533
|
+
: base;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
private getCurrentPlan() {
|
|
538
|
+
return resolveTranscriptionPlan({ transcriptionMode: getTranscriptionMode() });
|
|
510
539
|
}
|
|
511
540
|
|
|
541
|
+
private clampSelections() {
|
|
542
|
+
for (const category of CONFIGURATION_CATEGORIES) {
|
|
543
|
+
const count = this.getCategoryItems(category.id).length;
|
|
544
|
+
this.selectedByCategory.set(category.id, clamp(this.selectedByCategory.get(category.id) ?? 0, 0, Math.max(0, count - 1)));
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
|
|
512
549
|
private handleSearchInput(data: string) {
|
|
513
550
|
if (matchesKey(data, Key.slash)) {
|
|
514
551
|
this.searchActive = true;
|
|
@@ -549,8 +586,16 @@ class ConfigurationScreen implements Component {
|
|
|
549
586
|
}
|
|
550
587
|
}
|
|
551
588
|
|
|
552
|
-
export function buildConfigurationItems(
|
|
553
|
-
|
|
589
|
+
export function buildConfigurationItems(
|
|
590
|
+
modelCandidates: ModelCandidate[],
|
|
591
|
+
pythonModelCandidatesOrAudioDevices: ModelCandidate[] | AudioDeviceCandidate[],
|
|
592
|
+
audioDevicesOrTheme: AudioDeviceCandidate[] | MicmeTheme,
|
|
593
|
+
maybeTheme?: MicmeTheme,
|
|
594
|
+
): ConfigurationItem[] {
|
|
595
|
+
const pythonModelCandidates = maybeTheme ? (pythonModelCandidatesOrAudioDevices as ModelCandidate[]) : [];
|
|
596
|
+
const audioDevices = maybeTheme ? (audioDevicesOrTheme as AudioDeviceCandidate[]) : (pythonModelCandidatesOrAudioDevices as AudioDeviceCandidate[]);
|
|
597
|
+
const theme = maybeTheme ?? (audioDevicesOrTheme as MicmeTheme);
|
|
598
|
+
const currentModelPath = getCurrentWhisperCppModelValue();
|
|
554
599
|
const currentDevice = env("MICME_AUDIO_DEVICE") ?? "0";
|
|
555
600
|
const audioValues = audioDevices.length > 0 ? audioDevices.map((device) => device.value) : [currentDevice];
|
|
556
601
|
if (!audioValues.includes(currentDevice)) audioValues.unshift(currentDevice);
|
|
@@ -559,6 +604,15 @@ export function buildConfigurationItems(modelCandidates: ModelCandidate[], audio
|
|
|
559
604
|
const whisperStreamBinValues = uniqueStrings([env("MICME_WHISPER_STREAM_BIN") ?? "", findExecutable(["whisper-stream"]) ?? "", "whisper-stream"]);
|
|
560
605
|
const audioFilter = env("MICME_AUDIO_FILTER") ?? "highpass=f=80,lowpass=f=7600";
|
|
561
606
|
const macosPrintableShortcut = env("MICME_PRINTABLE_SHORTCUTS") ?? (process.platform === "darwin" ? DEFAULT_MACOS_PRINTABLE_SHORTCUT : "");
|
|
607
|
+
const plan = resolveTranscriptionPlan({ transcriptionMode: getTranscriptionMode() });
|
|
608
|
+
const backendValues = ["whisper.cpp", "python"] as const;
|
|
609
|
+
const backendLabels = Object.fromEntries(backendValues.map((value) => [value, formatBackendLabel(value)]));
|
|
610
|
+
const uiBackendValue = getUiBackendValue(plan);
|
|
611
|
+
const whisperCppVisible = (candidate: ResolvedTranscriptionPlan) => getUiBackendValue(candidate) === "whisper.cpp";
|
|
612
|
+
const pythonVisible = (candidate: ResolvedTranscriptionPlan) => getUiBackendValue(candidate) === "python";
|
|
613
|
+
const pythonModelValues = uniqueStrings([env("MICME_WHISPER_MODEL") ?? "base.en", ...pythonModelCandidates.map((candidate) => candidate.value)]);
|
|
614
|
+
const pythonModelLabels = Object.fromEntries(pythonModelCandidates.map((candidate) => [candidate.value, candidate.label]));
|
|
615
|
+
const modelPathCandidates = [{ label: "Use default model", value: "", description: "Clear explicit path override and use Micme's default whisper.cpp model path.", installed: true, kind: "path" as const }, ...modelCandidates];
|
|
562
616
|
|
|
563
617
|
return [
|
|
564
618
|
{
|
|
@@ -571,16 +625,6 @@ export function buildConfigurationItems(modelCandidates: ModelCandidate[], audio
|
|
|
571
625
|
values: ["1", "0"],
|
|
572
626
|
displayKind: "boolean",
|
|
573
627
|
},
|
|
574
|
-
{
|
|
575
|
-
id: "MICME_DEFAULT_WHISPER_CPP_MODEL",
|
|
576
|
-
categoryId: "general",
|
|
577
|
-
label: "Default model name",
|
|
578
|
-
description: "Used when no explicit whisper.cpp model path is configured.",
|
|
579
|
-
rawValue: env("MICME_DEFAULT_WHISPER_CPP_MODEL") ?? DEFAULT_WHISPER_CPP_MODEL_NAME,
|
|
580
|
-
currentValue: env("MICME_DEFAULT_WHISPER_CPP_MODEL") ?? DEFAULT_WHISPER_CPP_MODEL_NAME,
|
|
581
|
-
values: [...WHISPER_CPP_MODEL_NAMES],
|
|
582
|
-
displayKind: "text",
|
|
583
|
-
},
|
|
584
628
|
{
|
|
585
629
|
id: "MICME_LANGUAGE",
|
|
586
630
|
categoryId: "general",
|
|
@@ -601,38 +645,54 @@ export function buildConfigurationItems(modelCandidates: ModelCandidate[], audio
|
|
|
601
645
|
values: ["clip", "stream"],
|
|
602
646
|
displayKind: "text",
|
|
603
647
|
},
|
|
648
|
+
{
|
|
649
|
+
id: "MICME_TRANSCRIBE_BACKEND",
|
|
650
|
+
categoryId: "transcription",
|
|
651
|
+
label: "Backend",
|
|
652
|
+
description: "Choose the transcription backend.",
|
|
653
|
+
rawValue: uiBackendValue,
|
|
654
|
+
currentValue: uiBackendValue,
|
|
655
|
+
values: [...backendValues],
|
|
656
|
+
valueLabels: backendLabels,
|
|
657
|
+
displayKind: "text",
|
|
658
|
+
},
|
|
604
659
|
{
|
|
605
660
|
id: "MICME_WHISPER_CPP_MODEL",
|
|
606
661
|
categoryId: "transcription",
|
|
607
|
-
label: "
|
|
608
|
-
description: "
|
|
609
|
-
rawValue:
|
|
610
|
-
currentValue: displayConfigurationValue("MICME_WHISPER_CPP_MODEL",
|
|
662
|
+
label: "Model",
|
|
663
|
+
description: "Whisper.cpp ggml/gguf model file.",
|
|
664
|
+
rawValue: currentModelPath,
|
|
665
|
+
currentValue: displayConfigurationValue("MICME_WHISPER_CPP_MODEL", currentModelPath),
|
|
611
666
|
displayKind: "model",
|
|
612
667
|
emptyLabel: "not set",
|
|
613
|
-
submenu: (_currentValue, done) => createModelSelector(
|
|
668
|
+
submenu: (_currentValue, done) => createModelSelector(modelPathCandidates, theme, done),
|
|
669
|
+
visibleWhen: whisperCppVisible,
|
|
614
670
|
},
|
|
615
671
|
{
|
|
616
672
|
id: "MICME_WHISPER_CPP_BIN",
|
|
617
673
|
categoryId: "transcription",
|
|
618
|
-
label: "
|
|
674
|
+
label: "Binary",
|
|
619
675
|
description: "Command/path for whisper.cpp transcription. Leave unset to use whisper-cli/whisper-cpp from PATH.",
|
|
620
676
|
rawValue: env("MICME_WHISPER_CPP_BIN") ?? "",
|
|
621
677
|
currentValue: displayConfigurationValue("MICME_WHISPER_CPP_BIN", env("MICME_WHISPER_CPP_BIN") ?? ""),
|
|
622
678
|
values: whisperCppBinValues,
|
|
623
679
|
displayKind: "path",
|
|
624
680
|
emptyLabel: "not set",
|
|
681
|
+
visibleWhen: whisperCppVisible,
|
|
625
682
|
},
|
|
626
683
|
{
|
|
627
684
|
id: "MICME_WHISPER_MODEL",
|
|
628
685
|
categoryId: "transcription",
|
|
629
|
-
label: "
|
|
630
|
-
description: "
|
|
686
|
+
label: "Model",
|
|
687
|
+
description: "Model name passed to the OpenAI Whisper Python CLI.",
|
|
631
688
|
rawValue: env("MICME_WHISPER_MODEL") ?? "base.en",
|
|
632
689
|
currentValue: env("MICME_WHISPER_MODEL") ?? "base.en",
|
|
633
|
-
values:
|
|
690
|
+
values: pythonModelValues,
|
|
691
|
+
valueLabels: pythonModelLabels,
|
|
634
692
|
displayKind: "text",
|
|
693
|
+
visibleWhen: pythonVisible,
|
|
635
694
|
},
|
|
695
|
+
|
|
636
696
|
{
|
|
637
697
|
id: "MICME_WHISPER_STREAM_BIN",
|
|
638
698
|
categoryId: "streaming",
|
|
@@ -788,7 +848,7 @@ export function buildConfigurationItems(modelCandidates: ModelCandidate[], audio
|
|
|
788
848
|
},
|
|
789
849
|
{
|
|
790
850
|
id: "MICME_SHORTCUT",
|
|
791
|
-
categoryId: "
|
|
851
|
+
categoryId: "general",
|
|
792
852
|
label: "Terminal shortcut",
|
|
793
853
|
description: "Shortcut when your terminal sends real Alt/Ctrl keys. Requires /reload or restart after changing.",
|
|
794
854
|
rawValue: env("MICME_SHORTCUT") ?? DEFAULT_SHORTCUT,
|
|
@@ -798,7 +858,7 @@ export function buildConfigurationItems(modelCandidates: ModelCandidate[], audio
|
|
|
798
858
|
},
|
|
799
859
|
{
|
|
800
860
|
id: "MICME_PRINTABLE_SHORTCUTS",
|
|
801
|
-
categoryId: "
|
|
861
|
+
categoryId: "general",
|
|
802
862
|
label: "macOS printable shortcut",
|
|
803
863
|
description: "Toggle-only fallback for terminals where Option+M inserts a character instead of sending Alt+M. Use /reload after changing.",
|
|
804
864
|
rawValue: macosPrintableShortcut,
|
|
@@ -809,7 +869,7 @@ export function buildConfigurationItems(modelCandidates: ModelCandidate[], audio
|
|
|
809
869
|
},
|
|
810
870
|
{
|
|
811
871
|
id: "MICME_STREAM_DIAGNOSTICS",
|
|
812
|
-
categoryId: "
|
|
872
|
+
categoryId: "general",
|
|
813
873
|
label: "Stream diagnostics",
|
|
814
874
|
description: "Show opt-in whisper-stream frame/state diagnostics and first-output timing notifications.",
|
|
815
875
|
rawValue: env("MICME_STREAM_DIAGNOSTICS") ?? "0",
|
|
@@ -876,10 +936,21 @@ export async function saveConfigurationValue(ctx: ExtensionContext, id: string,
|
|
|
876
936
|
|
|
877
937
|
export function displayConfigurationValue(id: string, value: string) {
|
|
878
938
|
if (id === "MICME_WHISPER_CPP_MODEL") return value ? basename(value) : "not set";
|
|
939
|
+
if (id === "MICME_TRANSCRIBE_COMMAND") return value ? "configured" : "not set";
|
|
879
940
|
if (id === "MICME_AUDIO_FILTER") return value || "<empty>";
|
|
880
941
|
return value || "not set";
|
|
881
942
|
}
|
|
882
943
|
|
|
944
|
+
function getUiBackendValue(plan: ResolvedTranscriptionPlan): "whisper.cpp" | "python" {
|
|
945
|
+
if (plan.requestedBackend === "python" || plan.requestedBackend === "whisper.cpp") return plan.requestedBackend;
|
|
946
|
+
return plan.effectiveBackend === "python" ? "python" : "whisper.cpp";
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
function getCurrentWhisperCppModelValue() {
|
|
950
|
+
const explicit = env("MICME_WHISPER_CPP_MODEL")?.trim();
|
|
951
|
+
return explicit ? expandConfigPath(explicit) : resolveWhisperCppModel().path;
|
|
952
|
+
}
|
|
953
|
+
|
|
883
954
|
export function uniqueStrings(values: string[]) {
|
|
884
955
|
const seen = new Set<string>();
|
|
885
956
|
const output: string[] = [];
|
package/src/transcription.ts
CHANGED
|
@@ -2,31 +2,31 @@ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { basename, join } from "node:path";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { resolveTranscriptionPlan, formatTranscriptionPlan } from "./backends.ts";
|
|
6
|
+
import { env, getTranscribeTimeoutMs } from "./config.ts";
|
|
7
|
+
import { ensureWhisperCppModel } from "./models.ts";
|
|
8
|
+
import { formatRunExit, replacePlaceholders, runProcess, runShell } from "./processes.ts";
|
|
8
9
|
|
|
9
|
-
export
|
|
10
|
-
const custom = env("MICME_TRANSCRIBE_COMMAND");
|
|
11
|
-
if (custom?.trim()) {
|
|
12
|
-
return transcribeWithCustomCommand(custom, audioPath, tempDir);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const whisperCppBinary = getWhisperCppBinary();
|
|
16
|
-
const whisperCppModel = env("MICME_WHISPER_CPP_MODEL") || (whisperCppBinary ? getDefaultWhisperCppModelPath() : undefined);
|
|
17
|
-
if (whisperCppModel && whisperCppBinary) {
|
|
18
|
-
return transcribeWithWhisperCpp(whisperCppBinary, expandConfigPath(whisperCppModel), audioPath, tempDir, ctx);
|
|
19
|
-
}
|
|
10
|
+
export { getWhisperCppBinary, getWhisperStreamBinary, resolveExecutableConfig } from "./backends.ts";
|
|
20
11
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
export async function transcribe(audioPath: string, tempDir: string, ctx?: ExtensionContext): Promise<string> {
|
|
13
|
+
const plan = resolveTranscriptionPlan({ transcriptionMode: "clip" });
|
|
14
|
+
|
|
15
|
+
switch (plan.effectiveBackend) {
|
|
16
|
+
case "custom":
|
|
17
|
+
if (!plan.command) break;
|
|
18
|
+
return transcribeWithCustomCommand(plan.command, audioPath, tempDir);
|
|
19
|
+
case "whisper.cpp":
|
|
20
|
+
if (!plan.binary || !plan.modelPath) break;
|
|
21
|
+
return transcribeWithWhisperCpp(plan.binary, plan.modelPath, audioPath, tempDir, ctx, { allowDownload: plan.modelDownloadable !== false });
|
|
22
|
+
case "python":
|
|
23
|
+
if (!plan.binary) break;
|
|
24
|
+
return transcribeWithOpenAiWhisper(plan.binary, audioPath, tempDir, plan.modelName);
|
|
25
|
+
case "none":
|
|
26
|
+
break;
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
throw new Error(
|
|
27
|
-
"No Micme transcription backend found. Install whisper-cpp and set MICME_WHISPER_CPP_MODEL, " +
|
|
28
|
-
"install openai-whisper, or set MICME_TRANSCRIBE_COMMAND.",
|
|
29
|
-
);
|
|
29
|
+
throw new Error(formatTranscriptionPlan(plan));
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export async function transcribeWithCustomCommand(template: string, audioPath: string, tempDir: string) {
|
|
@@ -45,8 +45,15 @@ export async function transcribeWithCustomCommand(template: string, audioPath: s
|
|
|
45
45
|
return result.stdout;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export async function transcribeWithWhisperCpp(
|
|
49
|
-
|
|
48
|
+
export async function transcribeWithWhisperCpp(
|
|
49
|
+
binary: string,
|
|
50
|
+
modelPath: string,
|
|
51
|
+
audioPath: string,
|
|
52
|
+
tempDir: string,
|
|
53
|
+
ctx?: ExtensionContext,
|
|
54
|
+
options: { allowDownload?: boolean } = {},
|
|
55
|
+
) {
|
|
56
|
+
await ensureWhisperCppModel(modelPath, ctx, options);
|
|
50
57
|
const outputBase = join(tempDir, "whisper-cpp");
|
|
51
58
|
const args = ["-m", modelPath, "-f", audioPath, "-otxt", "-of", outputBase, "-nt", "-np", "-nf", "-sns"];
|
|
52
59
|
const language = env("MICME_LANGUAGE");
|
|
@@ -66,8 +73,8 @@ export async function transcribeWithWhisperCpp(binary: string, modelPath: string
|
|
|
66
73
|
return result.stdout;
|
|
67
74
|
}
|
|
68
75
|
|
|
69
|
-
export async function transcribeWithOpenAiWhisper(binary: string, audioPath: string, tempDir: string) {
|
|
70
|
-
const model = env("MICME_WHISPER_MODEL") || "base.en";
|
|
76
|
+
export async function transcribeWithOpenAiWhisper(binary: string, audioPath: string, tempDir: string, modelName?: string) {
|
|
77
|
+
const model = modelName || env("MICME_WHISPER_MODEL") || "base.en";
|
|
71
78
|
const args = [
|
|
72
79
|
audioPath,
|
|
73
80
|
"--model",
|
|
@@ -106,26 +113,3 @@ export async function transcribeWithOpenAiWhisper(binary: string, audioPath: str
|
|
|
106
113
|
|
|
107
114
|
return result.stdout;
|
|
108
115
|
}
|
|
109
|
-
|
|
110
|
-
export function getWhisperCppBinary() {
|
|
111
|
-
const configured = env("MICME_WHISPER_CPP_BIN")?.trim();
|
|
112
|
-
if (configured) return resolveExecutableConfig(configured, "MICME_WHISPER_CPP_BIN");
|
|
113
|
-
return findExecutable(["whisper-cli", "whisper-cpp"]);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export function getWhisperStreamBinary() {
|
|
117
|
-
const configured = env("MICME_WHISPER_STREAM_BIN")?.trim();
|
|
118
|
-
if (configured) return resolveExecutableConfig(configured, "MICME_WHISPER_STREAM_BIN");
|
|
119
|
-
return findExecutable(["whisper-stream"]);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function resolveExecutableConfig(value: string, configName: string) {
|
|
123
|
-
const expanded = expandConfigPath(value);
|
|
124
|
-
if (/[/\\]/.test(expanded)) {
|
|
125
|
-
if (!existsSync(expanded)) throw new Error(`${configName} is set but not found: ${expanded}`);
|
|
126
|
-
return expanded;
|
|
127
|
-
}
|
|
128
|
-
const executable = findExecutable([expanded]);
|
|
129
|
-
if (!executable) throw new Error(`${configName} is set but not found on PATH: ${expanded}`);
|
|
130
|
-
return executable;
|
|
131
|
-
}
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
import type { ChildProcess } from "node:child_process";
|
|
2
2
|
|
|
3
3
|
export type TranscriptionMode = "clip" | "stream";
|
|
4
|
+
export type TranscribeBackend = "auto" | "whisper.cpp" | "python" | "custom";
|
|
5
|
+
export type EffectiveBackend = "whisper.cpp" | "python" | "custom" | "none";
|
|
6
|
+
export type WhisperCppModelSource = "explicit-path" | "configured-name" | "default-name";
|
|
7
|
+
export type TranscriptionModelSource = WhisperCppModelSource | "python-name" | "custom-command";
|
|
8
|
+
|
|
9
|
+
export type ResolvedWhisperCppModel = {
|
|
10
|
+
path: string;
|
|
11
|
+
modelName?: string;
|
|
12
|
+
source: WhisperCppModelSource;
|
|
13
|
+
configuredValue?: string;
|
|
14
|
+
exists: boolean;
|
|
15
|
+
downloadable: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type ResolvedTranscriptionPlan = {
|
|
19
|
+
requestedBackend: TranscribeBackend;
|
|
20
|
+
effectiveBackend: EffectiveBackend;
|
|
21
|
+
reason: string;
|
|
22
|
+
command?: string;
|
|
23
|
+
binary?: string;
|
|
24
|
+
modelName?: string;
|
|
25
|
+
modelPath?: string;
|
|
26
|
+
modelSource?: TranscriptionModelSource;
|
|
27
|
+
modelDownloadable?: boolean;
|
|
28
|
+
warnings: string[];
|
|
29
|
+
};
|
|
4
30
|
|
|
5
31
|
export type CommandSpec = {
|
|
6
32
|
command: string;
|
|
@@ -71,6 +97,7 @@ export type ModelCandidate = {
|
|
|
71
97
|
value: string;
|
|
72
98
|
description: string;
|
|
73
99
|
installed: boolean;
|
|
100
|
+
kind?: "model-name" | "path";
|
|
74
101
|
};
|
|
75
102
|
|
|
76
103
|
export type AudioDeviceCandidate = {
|