@senad-d/micme 0.3.0 → 0.3.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 +2 -0
- package/README.md +6 -3
- package/micme.example.json +1 -0
- package/micme.schema.json +8 -1
- package/package.json +1 -1
- package/scripts/doctor.mjs +42 -5
- package/src/backends.ts +14 -3
- package/src/config.ts +6 -0
- package/src/models.ts +76 -18
- package/src/settings.ts +48 -8
- package/src/streaming.ts +8 -2
- package/src/transcription.ts +17 -7
- package/src/types.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -10,8 +10,10 @@ All notable changes to Micme will be documented in this file.
|
|
|
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
12
|
- Add explicit transcription backend selection with backend-specific `/micme conf` model rows, doctor diagnostics, schema, and docs.
|
|
13
|
+
- Add a single `MICME_TRANSLATE_TO_ENGLISH` setting that translates selected source languages to English and switches default Whisper model names to multilingual variants.
|
|
13
14
|
- Store kept audio in sequential project directories under `./micme-rec/rec-###/` instead of the system temp directory.
|
|
14
15
|
- Make the recorder quality-safe by default: preserve recorder timing from ffmpeg timestamps, disable the stdout meter branch, and ask macOS AVFoundation not to drop late frames.
|
|
16
|
+
- Rename the translation UI to “Translate from” and automatically route translation away from non-translation Whisper turbo models to the closest translate-capable model.
|
|
15
17
|
|
|
16
18
|
## 0.1.0 - 2026-06-18
|
|
17
19
|
|
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
|
-
MicMe is a
|
|
18
|
+
MicMe is a Pi extension for 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
20
|
<table align="center">
|
|
21
21
|
<tr>
|
|
@@ -147,7 +147,7 @@ MICME_WHISPER_CPP_MODEL=/path/to/ggml-small.en.bin
|
|
|
147
147
|
|
|
148
148
|
## Configuration
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
MicMe reads settings from shell environment variables and from the global Micme config file at `~/.pi/agent/micme.json`. Shell variables win. `/micme conf` writes only `MICME_*` keys to that JSON file, so settings follow you across pi projects on the same machine.
|
|
151
151
|
|
|
152
152
|
The usual setup path is to run:
|
|
153
153
|
|
|
@@ -161,6 +161,7 @@ You can also edit the JSON manually. Minimal `~/.pi/agent/micme.json`:
|
|
|
161
161
|
{
|
|
162
162
|
"$schema": "https://raw.githubusercontent.com/senad-d/micme/main/micme.schema.json",
|
|
163
163
|
"MICME_LANGUAGE": "en",
|
|
164
|
+
"MICME_TRANSLATE_TO_ENGLISH": "off",
|
|
164
165
|
"MICME_TRANSCRIBE_BACKEND": "auto",
|
|
165
166
|
"MICME_AUTO_DOWNLOAD_MODEL": "1",
|
|
166
167
|
"MICME_DEFAULT_WHISPER_CPP_MODEL": "small.en",
|
|
@@ -178,6 +179,8 @@ Common settings:
|
|
|
178
179
|
| `MICME_TRANSCRIBE_BACKEND=auto` | Backend selector. `auto` preserves priority: custom command, whisper.cpp, then Python Whisper. |
|
|
179
180
|
| `MICME_TRANSCRIPTION_MODE=clip` | Stable default: transcribe after recording stops. |
|
|
180
181
|
| `MICME_TRANSCRIPTION_MODE=stream` | Experimental append-only live dictation with `whisper-stream`; requires whisper.cpp. |
|
|
182
|
+
| `MICME_LANGUAGE=en` | Transcription language when translation is off. Use `auto` for detection. |
|
|
183
|
+
| `MICME_TRANSLATE_TO_ENGLISH=off` | “Translate from” option. Leave `off`, or set the spoken source language code such as `hr`, `bs`, `de`, or `tr` to output English. |
|
|
181
184
|
| `MICME_STREAM_KEEP_CONTEXT=0` | Stream default: avoid Whisper prompt carry-over so live chunks are less likely to rewrite each other. |
|
|
182
185
|
| `MICME_STREAM_FLUSH_MS=650` | Stream profile quiet interval before tentative words are committed append-only. |
|
|
183
186
|
| `MICME_STREAM_FINALIZE_WITH_CLIP=0` | Keep the append-only live transcript on stop. Set `1` to opt in to final clip replacement. |
|
|
@@ -225,7 +228,7 @@ With `MICME_AUTO_DOWNLOAD_MODEL=1`, Micme downloads missing standard whisper.cpp
|
|
|
225
228
|
MICME_AUTO_DOWNLOAD_MODEL=0
|
|
226
229
|
```
|
|
227
230
|
|
|
228
|
-
Recommended model progression: `base.en` for speed, `small.en` for a stronger default, `medium.en` for accuracy.
|
|
231
|
+
Recommended model progression: `base.en` for speed, `small.en` for a stronger default, `medium.en` for accuracy. Translation uses Whisper's built-in translate task and needs translate-capable multilingual models; when `MICME_TRANSLATE_TO_ENGLISH` is enabled, Micme maps `.en` model names to multilingual defaults (`small.en` → `small`, `base.en` → `base`) and maps non-translation turbo models to the closest translate-capable model (`large-v3-turbo` → `large-v3`).
|
|
229
232
|
|
|
230
233
|
Advanced users can replace the recorder or transcriber:
|
|
231
234
|
|
package/micme.example.json
CHANGED
package/micme.schema.json
CHANGED
|
@@ -34,7 +34,14 @@
|
|
|
34
34
|
},
|
|
35
35
|
"MICME_LANGUAGE": {
|
|
36
36
|
"type": "string",
|
|
37
|
-
"default": "en"
|
|
37
|
+
"default": "en",
|
|
38
|
+
"description": "Transcription language when translation is off. Use auto for language detection."
|
|
39
|
+
},
|
|
40
|
+
"MICME_TRANSLATE_TO_ENGLISH": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"enum": ["off", "bs", "hr", "sr", "de", "es", "fr", "it", "pt", "nl", "pl", "tr"],
|
|
43
|
+
"default": "off",
|
|
44
|
+
"description": "Translate from control. off disables translation; any language code means translate speech in that source language to English."
|
|
38
45
|
},
|
|
39
46
|
"MICME_AUTO_DOWNLOAD_MODEL": {
|
|
40
47
|
"$ref": "#/$defs/stringFlag"
|
package/package.json
CHANGED
package/scripts/doctor.mjs
CHANGED
|
@@ -102,16 +102,43 @@ function getTranscriptionMode() {
|
|
|
102
102
|
return env("MICME_TRANSCRIPTION_MODE") === "stream" ? "stream" : "clip";
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
function getTranslateToEnglishLanguage() {
|
|
106
|
+
const value = env("MICME_TRANSLATE_TO_ENGLISH")?.trim();
|
|
107
|
+
if (!value || /^(0|false|no|off)$/i.test(value)) return undefined;
|
|
108
|
+
return value;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function toMultilingualWhisperModelName(modelName) {
|
|
112
|
+
return modelName.replace(/\.en$/i, "");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function getTranslationAwareWhisperModelName(modelName) {
|
|
116
|
+
return getTranslateToEnglishLanguage() ? toMultilingualWhisperModelName(modelName) : modelName;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function isEnglishOnlyWhisperModelName(modelName) {
|
|
120
|
+
return Boolean(modelName && /\.en$/i.test(modelName));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function inferWhisperCppModelName(modelPath) {
|
|
124
|
+
return modelPath.match(/(?:^|[/\\])ggml-(.+)\.(?:bin|gguf)$/i)?.[1];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function getPythonWhisperModelName() {
|
|
128
|
+
return getTranslationAwareWhisperModelName(env("MICME_WHISPER_MODEL") || "base.en");
|
|
129
|
+
}
|
|
130
|
+
|
|
105
131
|
function resolveWhisperCppModelSummary() {
|
|
106
132
|
const explicit = envPath("MICME_WHISPER_CPP_MODEL");
|
|
107
133
|
if (explicit) {
|
|
108
134
|
return {
|
|
109
135
|
path: explicit,
|
|
136
|
+
modelName: inferWhisperCppModelName(explicit),
|
|
110
137
|
source: "MICME_WHISPER_CPP_MODEL explicit path",
|
|
111
138
|
exists: existsSync(explicit),
|
|
112
139
|
};
|
|
113
140
|
}
|
|
114
|
-
const defaultModel = env("MICME_DEFAULT_WHISPER_CPP_MODEL") || "small.en";
|
|
141
|
+
const defaultModel = getTranslationAwareWhisperModelName(env("MICME_DEFAULT_WHISPER_CPP_MODEL") || "small.en");
|
|
115
142
|
const modelDir = expandConfigValue(env("MICME_MODEL_DIR") || join(homedir(), ".cache", "whisper.cpp"));
|
|
116
143
|
const path = join(modelDir, `ggml-${defaultModel}.bin`);
|
|
117
144
|
return {
|
|
@@ -156,13 +183,13 @@ function resolveBackendPlan({ whisperCpp, whisperStream, whisper, transcribeComm
|
|
|
156
183
|
return { requestedBackend, effectiveBackend: "none", effectiveModel: "unavailable", reason: "MICME_TRANSCRIBE_BACKEND=whisper.cpp but whisper.cpp was not found.", warnings };
|
|
157
184
|
}
|
|
158
185
|
if (requestedBackend === "python") {
|
|
159
|
-
if (pythonAvailable) return { requestedBackend, effectiveBackend: "python", binary: whisper, effectiveModel:
|
|
186
|
+
if (pythonAvailable) return { requestedBackend, effectiveBackend: "python", binary: whisper, effectiveModel: getPythonWhisperModelName(), reason: "MICME_TRANSCRIBE_BACKEND=python", warnings };
|
|
160
187
|
return { requestedBackend, effectiveBackend: "none", effectiveModel: "unavailable", reason: "MICME_TRANSCRIBE_BACKEND=python but the `whisper` CLI was not found.", warnings };
|
|
161
188
|
}
|
|
162
189
|
|
|
163
190
|
if (transcribeCommand?.trim()) return { requestedBackend, effectiveBackend: "custom", effectiveModel: "unknown", reason: "auto selected custom command because MICME_TRANSCRIBE_COMMAND is configured", warnings };
|
|
164
191
|
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:
|
|
192
|
+
if (pythonAvailable) return { requestedBackend, effectiveBackend: "python", binary: whisper, effectiveModel: getPythonWhisperModelName(), reason: "auto selected Python Whisper because whisper.cpp is unavailable", warnings };
|
|
166
193
|
return { requestedBackend, effectiveBackend: "none", effectiveModel: "unavailable", reason: "No Micme transcription backend found.", warnings };
|
|
167
194
|
}
|
|
168
195
|
|
|
@@ -178,6 +205,16 @@ function printBackendPlanDiagnostics(plan) {
|
|
|
178
205
|
} else if (plan.effectiveBackend === "python") info("effective model", plan.effectiveModel);
|
|
179
206
|
else info("effective model", "unavailable");
|
|
180
207
|
|
|
208
|
+
const translateLanguage = getTranslateToEnglishLanguage();
|
|
209
|
+
if (translateLanguage) {
|
|
210
|
+
ok("translation", `${translateLanguage} -> English`);
|
|
211
|
+
if (plan.effectiveBackend === "custom") warn("translation backend", "custom transcribe commands must implement translation themselves");
|
|
212
|
+
if (plan.effectiveBackend === "whisper.cpp" && isEnglishOnlyWhisperModelName(plan.model?.modelName)) warn("translation model", `${plan.model.modelName} appears to be English-only; use a multilingual model`);
|
|
213
|
+
if (plan.effectiveBackend === "python" && isEnglishOnlyWhisperModelName(plan.effectiveModel)) warn("translation model", `${plan.effectiveModel} appears to be English-only; use a multilingual model`);
|
|
214
|
+
} else {
|
|
215
|
+
info("translation", "off");
|
|
216
|
+
}
|
|
217
|
+
|
|
181
218
|
for (const warning of plan.warnings) warn("backend warning", warning);
|
|
182
219
|
}
|
|
183
220
|
|
|
@@ -229,7 +266,7 @@ async function main() {
|
|
|
229
266
|
warn("MICME_WHISPER_CPP_MODEL is set but not readable", auto ? `${whisperCppModel} (Micme will try to download if it is a standard ggml model path)` : whisperCppModel);
|
|
230
267
|
}
|
|
231
268
|
} else {
|
|
232
|
-
const defaultModel = env("MICME_DEFAULT_WHISPER_CPP_MODEL") || "small.en";
|
|
269
|
+
const defaultModel = getTranslationAwareWhisperModelName(env("MICME_DEFAULT_WHISPER_CPP_MODEL") || "small.en");
|
|
233
270
|
const modelDir = expandConfigValue(env("MICME_MODEL_DIR") || join(homedir(), ".cache", "whisper.cpp"));
|
|
234
271
|
info("MICME_WHISPER_CPP_MODEL", `not set; Micme defaults to ${modelDir}/ggml-${defaultModel}.bin and auto-downloads when needed`);
|
|
235
272
|
}
|
|
@@ -250,7 +287,7 @@ async function main() {
|
|
|
250
287
|
|
|
251
288
|
console.log("\nRecommended macOS setup:");
|
|
252
289
|
console.log(" brew install ffmpeg whisper-cpp");
|
|
253
|
-
console.log(" # Then use /micme conf, or let Micme auto-download
|
|
290
|
+
console.log(" # Then use /micme conf, or let Micme auto-download the default model on first use.");
|
|
254
291
|
|
|
255
292
|
if (process.platform === "darwin" && ffmpeg) {
|
|
256
293
|
console.log("\nmacOS microphone devices:");
|
package/src/backends.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import type { TranscribeBackend, TranscriptionMode, ResolvedTranscriptionPlan, ResolvedWhisperCppModel } from "./types.ts";
|
|
3
3
|
import { DEFAULT_TRANSCRIBE_BACKEND } from "./constants.ts";
|
|
4
|
-
import { env, expandConfigPath, getTranscribeBackend, isTranscribeBackend } from "./config.ts";
|
|
5
|
-
import { getPythonWhisperModelName, resolveWhisperCppModel } from "./models.ts";
|
|
4
|
+
import { env, expandConfigPath, getTranscribeBackend, getTranslateToEnglishLanguage, isTranscribeBackend } from "./config.ts";
|
|
5
|
+
import { getPythonWhisperModelName, isEnglishOnlyWhisperModelName, isTranslationUnsupportedWhisperModelName, resolveWhisperCppModel } from "./models.ts";
|
|
6
6
|
import { findExecutable } from "./processes.ts";
|
|
7
7
|
|
|
8
8
|
export type ResolveTranscriptionPlanOptions = {
|
|
@@ -174,6 +174,10 @@ function whisperCppPlan(requestedBackend: TranscribeBackend, binary: string, mod
|
|
|
174
174
|
} else if (!model.exists && !model.downloadable) {
|
|
175
175
|
warnings.push(`Whisper.cpp model is missing and is not a standard downloadable model: ${model.path}`);
|
|
176
176
|
}
|
|
177
|
+
if (model.translationFallbackFrom && model.modelName) {
|
|
178
|
+
warnings.push(`Translation to English uses ${model.modelName} instead of ${model.translationFallbackFrom} because the selected model does not support translation.`);
|
|
179
|
+
}
|
|
180
|
+
warnings.push(...getTranslationModelWarnings(model.modelName));
|
|
177
181
|
return {
|
|
178
182
|
requestedBackend,
|
|
179
183
|
effectiveBackend: "whisper.cpp",
|
|
@@ -195,10 +199,17 @@ function pythonPlan(requestedBackend: TranscribeBackend, binary: string, modelNa
|
|
|
195
199
|
binary,
|
|
196
200
|
modelName,
|
|
197
201
|
modelSource: "python-name",
|
|
198
|
-
warnings:
|
|
202
|
+
warnings: getTranslationModelWarnings(modelName),
|
|
199
203
|
};
|
|
200
204
|
}
|
|
201
205
|
|
|
206
|
+
function getTranslationModelWarnings(modelName: string | undefined) {
|
|
207
|
+
if (!getTranslateToEnglishLanguage()) return [];
|
|
208
|
+
if (isEnglishOnlyWhisperModelName(modelName)) return [`Translation to English requires a multilingual Whisper model; ${modelName} appears to be English-only.`];
|
|
209
|
+
if (isTranslationUnsupportedWhisperModelName(modelName)) return [`Translation to English is not supported by ${modelName}; choose large-v3 or another multilingual translate-capable model.`];
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
212
|
+
|
|
202
213
|
function nonePlan(requestedBackend: TranscribeBackend, reason: string, warnings: string[]): ResolvedTranscriptionPlan {
|
|
203
214
|
return {
|
|
204
215
|
requestedBackend,
|
package/src/config.ts
CHANGED
|
@@ -175,6 +175,12 @@ export function getTranscriptionMode() {
|
|
|
175
175
|
return env("MICME_TRANSCRIPTION_MODE") === "stream" ? "stream" : "clip";
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
export function getTranslateToEnglishLanguage() {
|
|
179
|
+
const value = env("MICME_TRANSLATE_TO_ENGLISH")?.trim();
|
|
180
|
+
if (!value || /^(0|false|no|off)$/i.test(value)) return undefined;
|
|
181
|
+
return value;
|
|
182
|
+
}
|
|
183
|
+
|
|
178
184
|
export function getTranscribeBackend(): TranscribeBackend {
|
|
179
185
|
const value = env("MICME_TRANSCRIBE_BACKEND")?.trim();
|
|
180
186
|
return isTranscribeBackend(value) ? value : DEFAULT_TRANSCRIBE_BACKEND;
|
package/src/models.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { once } from "node:events";
|
|
|
3
3
|
import { createWriteStream, existsSync, readdirSync, statSync } from "node:fs";
|
|
4
4
|
import { mkdir, rename, unlink } from "node:fs/promises";
|
|
5
5
|
import { homedir } from "node:os";
|
|
6
|
-
import { basename, dirname, join } from "node:path";
|
|
6
|
+
import { basename, dirname, extname, join } from "node:path";
|
|
7
7
|
import { finished } from "node:stream/promises";
|
|
8
8
|
import {
|
|
9
9
|
DEFAULT_PYTHON_WHISPER_MODEL_NAME,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
WHISPER_CPP_MODEL_BASE_URL,
|
|
14
14
|
WHISPER_CPP_MODEL_NAMES,
|
|
15
15
|
} from "./constants.ts";
|
|
16
|
-
import { env, expandConfigPath } from "./config.ts";
|
|
16
|
+
import { env, expandConfigPath, getTranslateToEnglishLanguage } from "./config.ts";
|
|
17
17
|
import { findExecutable, runProcess } from "./processes.ts";
|
|
18
18
|
import type { ModelCandidate, ResolvedWhisperCppModel } from "./types.ts";
|
|
19
19
|
|
|
@@ -118,33 +118,90 @@ export function describeWhisperModel(name: string) {
|
|
|
118
118
|
|
|
119
119
|
export function resolveWhisperCppModel(): ResolvedWhisperCppModel {
|
|
120
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
|
-
}
|
|
121
|
+
if (explicitPath) return resolveExplicitWhisperCppModel(expandConfigPath(explicitPath), explicitPath);
|
|
132
122
|
|
|
133
123
|
const configuredName = env("MICME_DEFAULT_WHISPER_CPP_MODEL")?.trim();
|
|
134
|
-
const
|
|
124
|
+
const rawModelName = configuredName || DEFAULT_WHISPER_CPP_MODEL_NAME;
|
|
125
|
+
const modelName = getTranslationAwareWhisperModelName(rawModelName);
|
|
135
126
|
const path = join(getWhisperCppModelCacheDir(), `ggml-${modelName}.bin`);
|
|
136
|
-
return {
|
|
137
|
-
path,
|
|
127
|
+
return buildResolvedWhisperCppModel(path, {
|
|
138
128
|
modelName,
|
|
139
129
|
source: configuredName ? "configured-name" : "default-name",
|
|
140
130
|
configuredValue: configuredName,
|
|
131
|
+
translationFallbackFrom: getTranslationFallbackSource(rawModelName, modelName),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function resolveExplicitWhisperCppModel(path: string, configuredValue: string): ResolvedWhisperCppModel {
|
|
136
|
+
const modelName = getWhisperCppModelNameFromPath(path);
|
|
137
|
+
const translationModelName = modelName ? getTranslationAwareWhisperModelName(modelName) : undefined;
|
|
138
|
+
if (modelName && translationModelName && translationModelName !== modelName) {
|
|
139
|
+
const fallbackPath = getSiblingWhisperCppModelPath(path, translationModelName);
|
|
140
|
+
return buildResolvedWhisperCppModel(fallbackPath, {
|
|
141
|
+
modelName: translationModelName,
|
|
142
|
+
source: "explicit-path",
|
|
143
|
+
configuredValue,
|
|
144
|
+
translationFallbackFrom: modelName,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return buildResolvedWhisperCppModel(path, {
|
|
149
|
+
modelName,
|
|
150
|
+
source: "explicit-path",
|
|
151
|
+
configuredValue,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function buildResolvedWhisperCppModel(
|
|
156
|
+
path: string,
|
|
157
|
+
metadata: Pick<ResolvedWhisperCppModel, "source"> & Pick<Partial<ResolvedWhisperCppModel>, "modelName" | "configuredValue" | "translationFallbackFrom">,
|
|
158
|
+
): ResolvedWhisperCppModel {
|
|
159
|
+
return {
|
|
160
|
+
path,
|
|
161
|
+
modelName: metadata.modelName,
|
|
162
|
+
source: metadata.source,
|
|
163
|
+
configuredValue: metadata.configuredValue,
|
|
141
164
|
exists: existsSync(path),
|
|
142
165
|
downloadable: isDownloadableWhisperCppModelPath(path),
|
|
166
|
+
translationFallbackFrom: metadata.translationFallbackFrom,
|
|
143
167
|
};
|
|
144
168
|
}
|
|
145
169
|
|
|
170
|
+
function getSiblingWhisperCppModelPath(modelPath: string, modelName: string) {
|
|
171
|
+
const extension = extname(modelPath) || ".bin";
|
|
172
|
+
return join(dirname(modelPath), `ggml-${modelName}${extension}`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function getTranslationFallbackSource(rawModelName: string, modelName: string) {
|
|
176
|
+
return rawModelName !== modelName ? rawModelName : undefined;
|
|
177
|
+
}
|
|
178
|
+
|
|
146
179
|
export function getPythonWhisperModelName() {
|
|
147
|
-
|
|
180
|
+
const modelName = env("MICME_WHISPER_MODEL")?.trim() || DEFAULT_PYTHON_WHISPER_MODEL_NAME;
|
|
181
|
+
return getTranslationAwareWhisperModelName(modelName);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function getTranslationAwareWhisperModelName(modelName: string) {
|
|
185
|
+
return getTranslateToEnglishLanguage() ? toTranslationCapableWhisperModelName(modelName) : modelName;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function toTranslationCapableWhisperModelName(modelName: string) {
|
|
189
|
+
const multilingualName = toMultilingualWhisperModelName(modelName);
|
|
190
|
+
return isTranslationUnsupportedWhisperModelName(multilingualName) ? "large-v3" : multilingualName;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export function toMultilingualWhisperModelName(modelName: string) {
|
|
194
|
+
return modelName.replace(/\.en$/i, "");
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function isEnglishOnlyWhisperModelName(modelName: string | undefined) {
|
|
198
|
+
return Boolean(modelName && /\.en$/i.test(modelName));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function isTranslationUnsupportedWhisperModelName(modelName: string | undefined) {
|
|
202
|
+
if (!modelName) return false;
|
|
203
|
+
const normalized = modelName.toLowerCase();
|
|
204
|
+
return normalized === "turbo" || normalized === "large-v3-turbo" || normalized.startsWith("large-v3-turbo-");
|
|
148
205
|
}
|
|
149
206
|
|
|
150
207
|
export async function discoverPythonWhisperModels(): Promise<ModelCandidate[]> {
|
|
@@ -304,7 +361,8 @@ export function getWhisperCppModelCacheDir() {
|
|
|
304
361
|
}
|
|
305
362
|
|
|
306
363
|
export function getDefaultWhisperCppModelPath() {
|
|
307
|
-
const
|
|
364
|
+
const rawModelName = env("MICME_DEFAULT_WHISPER_CPP_MODEL")?.trim() || DEFAULT_WHISPER_CPP_MODEL_NAME;
|
|
365
|
+
const modelName = getTranslationAwareWhisperModelName(rawModelName);
|
|
308
366
|
return join(getWhisperCppModelCacheDir(), `ggml-${modelName}.bin`);
|
|
309
367
|
}
|
|
310
368
|
|
package/src/settings.ts
CHANGED
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
} from "./config.ts";
|
|
33
33
|
import { discoverAudioDevices } from "./audio.ts";
|
|
34
34
|
import { formatBackendLabel, resolveTranscriptionPlan } from "./backends.ts";
|
|
35
|
-
import { discoverPythonWhisperModels, discoverWhisperCppModels, ensureWhisperCppModel, resolveWhisperCppModel } from "./models.ts";
|
|
35
|
+
import { discoverPythonWhisperModels, discoverWhisperCppModels, ensureWhisperCppModel, getPythonWhisperModelName, resolveWhisperCppModel } from "./models.ts";
|
|
36
36
|
import { findExecutable } from "./processes.ts";
|
|
37
37
|
import type { AudioDeviceCandidate, ModelCandidate, ResolvedTranscriptionPlan } from "./types.ts";
|
|
38
38
|
|
|
@@ -66,6 +66,27 @@ const CONFIGURATION_CATEGORIES: ConfigurationCategory[] = [
|
|
|
66
66
|
|
|
67
67
|
const TWO_PANE_MIN_WIDTH = 72;
|
|
68
68
|
const MAX_SETTINGS_ROWS = 10;
|
|
69
|
+
const LANGUAGE_LABELS: Record<string, string> = {
|
|
70
|
+
auto: "Auto detect",
|
|
71
|
+
en: "English",
|
|
72
|
+
bs: "Bosnian",
|
|
73
|
+
hr: "Croatian",
|
|
74
|
+
sr: "Serbian",
|
|
75
|
+
de: "German",
|
|
76
|
+
es: "Spanish",
|
|
77
|
+
fr: "French",
|
|
78
|
+
it: "Italian",
|
|
79
|
+
pt: "Portuguese",
|
|
80
|
+
nl: "Dutch",
|
|
81
|
+
pl: "Polish",
|
|
82
|
+
tr: "Turkish",
|
|
83
|
+
};
|
|
84
|
+
const TRANSCRIPTION_LANGUAGE_VALUES = ["en", "auto", "bs", "hr", "sr", "de", "es", "fr", "it", "pt", "nl", "pl", "tr"];
|
|
85
|
+
const TRANSLATION_SOURCE_LANGUAGE_VALUES = ["bs", "hr", "sr", "de", "es", "fr", "it", "pt", "nl", "pl", "tr"];
|
|
86
|
+
const TRANSLATE_FROM_VALUE_LABELS: Record<string, string> = {
|
|
87
|
+
off: "Off",
|
|
88
|
+
...Object.fromEntries(TRANSLATION_SOURCE_LANGUAGE_VALUES.map((language) => [language, `${LANGUAGE_LABELS[language] ?? language} → English`])),
|
|
89
|
+
};
|
|
69
90
|
|
|
70
91
|
export async function showConfiguration(ctx: ExtensionContext) {
|
|
71
92
|
if (ctx.mode !== "tui") {
|
|
@@ -587,6 +608,12 @@ class ConfigurationScreen implements Component {
|
|
|
587
608
|
model.currentValue = displayConfigurationValue(model.id, model.rawValue);
|
|
588
609
|
}
|
|
589
610
|
|
|
611
|
+
const pythonModel = this.items.find((candidate) => candidate.id === "MICME_WHISPER_MODEL");
|
|
612
|
+
if (pythonModel) {
|
|
613
|
+
pythonModel.rawValue = getPythonWhisperModelName();
|
|
614
|
+
pythonModel.currentValue = pythonModel.rawValue;
|
|
615
|
+
}
|
|
616
|
+
|
|
590
617
|
const mode = this.items.find((candidate) => candidate.id === "MICME_TRANSCRIPTION_MODE");
|
|
591
618
|
if (mode) {
|
|
592
619
|
const base = "Changing this applies the matching profile: stable clip defaults or low-latency stream settings.";
|
|
@@ -666,13 +693,15 @@ export function buildConfigurationItems(
|
|
|
666
693
|
const whisperStreamBinValues = uniqueStrings([env("MICME_WHISPER_STREAM_BIN") ?? "", findExecutable(["whisper-stream"]) ?? "", "whisper-stream"]);
|
|
667
694
|
const audioFilter = env("MICME_AUDIO_FILTER") ?? "highpass=f=80,lowpass=f=7600";
|
|
668
695
|
const shortcut = getShortcutSettingValue();
|
|
696
|
+
const translateToEnglish = env("MICME_TRANSLATE_TO_ENGLISH") ?? "off";
|
|
669
697
|
const plan = resolveTranscriptionPlan({ transcriptionMode: getTranscriptionMode() });
|
|
670
698
|
const backendValues = ["whisper.cpp", "python"] as const;
|
|
671
699
|
const backendLabels = Object.fromEntries(backendValues.map((value) => [value, formatBackendLabel(value)]));
|
|
672
700
|
const uiBackendValue = getUiBackendValue(plan);
|
|
673
701
|
const whisperCppVisible = (candidate: ResolvedTranscriptionPlan) => getUiBackendValue(candidate) === "whisper.cpp";
|
|
674
702
|
const pythonVisible = (candidate: ResolvedTranscriptionPlan) => getUiBackendValue(candidate) === "python";
|
|
675
|
-
const
|
|
703
|
+
const currentPythonModel = getPythonWhisperModelName();
|
|
704
|
+
const pythonModelValues = uniqueStrings([currentPythonModel, env("MICME_WHISPER_MODEL") ?? "", ...pythonModelCandidates.map((candidate) => candidate.value)]);
|
|
676
705
|
const pythonModelLabels = Object.fromEntries(pythonModelCandidates.map((candidate) => [candidate.value, candidate.label]));
|
|
677
706
|
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];
|
|
678
707
|
|
|
@@ -691,10 +720,22 @@ export function buildConfigurationItems(
|
|
|
691
720
|
id: "MICME_LANGUAGE",
|
|
692
721
|
categoryId: "general",
|
|
693
722
|
label: "Language",
|
|
694
|
-
description: "
|
|
723
|
+
description: "Transcription language when translation is off. Use auto for detection.",
|
|
695
724
|
rawValue: env("MICME_LANGUAGE") ?? "en",
|
|
696
725
|
currentValue: env("MICME_LANGUAGE") ?? "en",
|
|
697
|
-
values: [
|
|
726
|
+
values: [...TRANSCRIPTION_LANGUAGE_VALUES],
|
|
727
|
+
valueLabels: LANGUAGE_LABELS,
|
|
728
|
+
displayKind: "text",
|
|
729
|
+
},
|
|
730
|
+
{
|
|
731
|
+
id: "MICME_TRANSLATE_TO_ENGLISH",
|
|
732
|
+
categoryId: "general",
|
|
733
|
+
label: "Translate from",
|
|
734
|
+
description: "Off by default. Choose the spoken source language to output English.",
|
|
735
|
+
rawValue: translateToEnglish,
|
|
736
|
+
currentValue: translateToEnglish,
|
|
737
|
+
values: ["off", ...TRANSLATION_SOURCE_LANGUAGE_VALUES],
|
|
738
|
+
valueLabels: TRANSLATE_FROM_VALUE_LABELS,
|
|
698
739
|
displayKind: "text",
|
|
699
740
|
},
|
|
700
741
|
{
|
|
@@ -747,8 +788,8 @@ export function buildConfigurationItems(
|
|
|
747
788
|
categoryId: "transcription",
|
|
748
789
|
label: "Model",
|
|
749
790
|
description: "Model name passed to the OpenAI Whisper Python CLI.",
|
|
750
|
-
rawValue:
|
|
751
|
-
currentValue:
|
|
791
|
+
rawValue: currentPythonModel,
|
|
792
|
+
currentValue: currentPythonModel,
|
|
752
793
|
values: pythonModelValues,
|
|
753
794
|
valueLabels: pythonModelLabels,
|
|
754
795
|
displayKind: "text",
|
|
@@ -1032,8 +1073,7 @@ function getUiBackendValue(plan: ResolvedTranscriptionPlan): "whisper.cpp" | "py
|
|
|
1032
1073
|
}
|
|
1033
1074
|
|
|
1034
1075
|
function getCurrentWhisperCppModelValue() {
|
|
1035
|
-
|
|
1036
|
-
return explicit ? expandConfigPath(explicit) : resolveWhisperCppModel().path;
|
|
1076
|
+
return resolveWhisperCppModel().path;
|
|
1037
1077
|
}
|
|
1038
1078
|
|
|
1039
1079
|
export function uniqueStrings(values: string[]) {
|
package/src/streaming.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { MAX_CAPTURED_OUTPUT_CHARS } from "./constants.ts";
|
|
|
3
3
|
import {
|
|
4
4
|
env,
|
|
5
5
|
envFlag,
|
|
6
|
+
getTranslateToEnglishLanguage,
|
|
6
7
|
getStreamFlushMs,
|
|
7
8
|
getStreamKeepContext,
|
|
8
9
|
getStreamKeepMs,
|
|
@@ -54,8 +55,13 @@ export function buildWhisperStreamCommand(binary: string, modelPath: string, tem
|
|
|
54
55
|
const capture = env("MICME_STREAM_CAPTURE");
|
|
55
56
|
if (capture?.trim()) args.push("--capture", capture.trim());
|
|
56
57
|
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
58
|
+
const translateLanguage = getTranslateToEnglishLanguage();
|
|
59
|
+
if (translateLanguage) {
|
|
60
|
+
args.push("-tr", "-l", translateLanguage);
|
|
61
|
+
} else {
|
|
62
|
+
const language = env("MICME_LANGUAGE");
|
|
63
|
+
if (language?.trim()) args.push("-l", language.trim());
|
|
64
|
+
}
|
|
59
65
|
|
|
60
66
|
return { command: binary, args, display: `${binary} ${args.map(shellQuote).join(" ")}` };
|
|
61
67
|
}
|
package/src/transcription.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { existsSync } from "node:fs";
|
|
|
3
3
|
import { readFile } from "node:fs/promises";
|
|
4
4
|
import { basename, join } from "node:path";
|
|
5
5
|
import { resolveTranscriptionPlan, formatTranscriptionPlan } from "./backends.ts";
|
|
6
|
-
import { env, getTranscribeTimeoutMs } from "./config.ts";
|
|
7
|
-
import { ensureWhisperCppModel } from "./models.ts";
|
|
6
|
+
import { env, getTranscribeTimeoutMs, getTranslateToEnglishLanguage } from "./config.ts";
|
|
7
|
+
import { ensureWhisperCppModel, getPythonWhisperModelName } from "./models.ts";
|
|
8
8
|
import { formatRunExit, replacePlaceholders, runProcess, runShell } from "./processes.ts";
|
|
9
9
|
|
|
10
10
|
export { getWhisperCppBinary, getWhisperStreamBinary, resolveExecutableConfig } from "./backends.ts";
|
|
@@ -56,8 +56,13 @@ export async function transcribeWithWhisperCpp(
|
|
|
56
56
|
await ensureWhisperCppModel(modelPath, ctx, options);
|
|
57
57
|
const outputBase = join(tempDir, "whisper-cpp");
|
|
58
58
|
const args = ["-m", modelPath, "-f", audioPath, "-otxt", "-of", outputBase, "-nt", "-np", "-nf", "-sns"];
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
59
|
+
const translateLanguage = getTranslateToEnglishLanguage();
|
|
60
|
+
if (translateLanguage) {
|
|
61
|
+
args.push("-tr", "-l", translateLanguage);
|
|
62
|
+
} else {
|
|
63
|
+
const language = env("MICME_LANGUAGE");
|
|
64
|
+
if (language?.trim()) args.push("-l", language.trim());
|
|
65
|
+
}
|
|
61
66
|
|
|
62
67
|
const result = await runProcess(binary, args, getTranscribeTimeoutMs());
|
|
63
68
|
if (result.code !== 0) {
|
|
@@ -74,7 +79,7 @@ export async function transcribeWithWhisperCpp(
|
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
export async function transcribeWithOpenAiWhisper(binary: string, audioPath: string, tempDir: string, modelName?: string) {
|
|
77
|
-
const model = modelName ||
|
|
82
|
+
const model = modelName || getPythonWhisperModelName();
|
|
78
83
|
const args = [
|
|
79
84
|
audioPath,
|
|
80
85
|
"--model",
|
|
@@ -89,8 +94,13 @@ export async function transcribeWithOpenAiWhisper(binary: string, audioPath: str
|
|
|
89
94
|
"False",
|
|
90
95
|
];
|
|
91
96
|
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
97
|
+
const translateLanguage = getTranslateToEnglishLanguage();
|
|
98
|
+
if (translateLanguage) {
|
|
99
|
+
args.push("--task", "translate", "--language", translateLanguage);
|
|
100
|
+
} else {
|
|
101
|
+
const language = env("MICME_LANGUAGE");
|
|
102
|
+
if (language?.trim() && language.trim().toLowerCase() !== "auto") args.push("--language", language.trim());
|
|
103
|
+
}
|
|
94
104
|
|
|
95
105
|
const device = env("MICME_WHISPER_DEVICE");
|
|
96
106
|
if (device?.trim()) args.push("--device", device.trim());
|