Skip to content

Build your personal knowledge base with Trilium Notes

feat(transcription): use the full-precision Parakeet model when installed

Elian Doran547b0058f89e
diff --git a/.claude/skills/working-with-transcription/SKILL.md b/.claude/skills/working-with-transcription/SKILL.md
index bd9c9c4f34..df27d13ef4 100644
--- a/.claude/skills/working-with-transcription/SKILL.md
+++ b/.claude/skills/working-with-transcription/SKILL.md
@@ -18,7 +18,7 @@ capture window (hidden, offscreen) transcription process (Electron
│
per source: SourcePipeline → VadSegmenter (Silero, 512-sample windows)
│ utterances
- one queue: recognizer.transcribe() (Parakeet TDT 0.6B v3 int8, libuv pool)
+ one queue: recognizer.transcribe() (Parakeet TDT 0.6B v3, fp32 or int8, libuv pool)
│ speaker: EmbeddingSpeakerTracker (TitaNet, synchronous)
sinks: posted to the main process, dev: TranscriptFileSink
│ parentPort: ready / pending / utterance / log / stopped
@@ -53,14 +53,22 @@ Nothing the transcription process imports may reach `@triliumnext/core` or `@tri
## The model
-Both files go in `<data dir>/transcription-model`; for `pnpm desktop:start` that is `apps/desktop/data/transcription-model`.
+The files go in `<data dir>/transcription-model`; for `pnpm desktop:start` that is `apps/desktop/data/transcription-model`. Parakeet comes in two precisions, and `loadSherpaEngine()` takes the full-precision one when `encoder.onnx` is present, else the int8 one; it records which as `precision` in the engine settings and applies `blankPenalty` to int8 only (see "Findings so far").
-- Parakeet: the `sherpa-onnx-nemo-parakeet-tdt-0.6b-v3-int8` archive from the `asr-models` release of `k2-fsa/sherpa-onnx` — `encoder.int8.onnx`, `decoder.int8.onnx`, `joiner.int8.onnx`, `tokens.txt` (641 MB).
-- `silero_vad.onnx` from the same release.
+- **Full precision** (recommended): `csukuangfj/sherpa-onnx-nemo-parakeet-tdt-0.6b-v3` on Hugging Face, not in the sherpa releases — `encoder.onnx` + `encoder.weights`, `decoder.onnx`, `joiner.onnx`, `tokens.txt` (2.4 GB). Loads in ~2 s to ~2.3 GB RSS.
+- **int8**: the `sherpa-onnx-nemo-parakeet-tdt-0.6b-v3-int8` archive from the `asr-models` release of `k2-fsa/sherpa-onnx` — `encoder.int8.onnx`, `decoder.int8.onnx`, `joiner.int8.onnx`, `tokens.txt` (641 MB).
+- `silero_vad.onnx` from the `asr-models` release.
-Without the directory, starting fails with `transcription.model-missing`.
+```bash
+cd apps/desktop/data && mkdir -p transcription-model/speaker && cd transcription-model
+H=https://huggingface.co/csukuangfj/sherpa-onnx-nemo-parakeet-tdt-0.6b-v3/resolve/main
+R=https://github.com/k2-fsa/sherpa-onnx/releases/download
+for f in tokens.txt decoder.onnx joiner.onnx encoder.onnx encoder.weights; do curl -fL -o $f "$H/$f"; done
+curl -fL -o silero_vad.onnx "$R/asr-models/silero_vad.onnx"
+curl -fL -o speaker/nemo_en_titanet_small.onnx "$R/speaker-recongition-models/nemo_en_titanet_small.onnx"
+```
-The **full-precision** export is not in the releases: it is `csukuangfj/sherpa-onnx-nemo-parakeet-tdt-0.6b-v3` on Hugging Face (`encoder.onnx` + `encoder.weights`, `decoder.onnx`, `joiner.onnx`, `tokens.txt`; 2.4 GB). Keep it in its own directory (here `apps/desktop/data/transcription-model-fp32`, with `silero_vad.onnx` linked in) and pass `--model` to `replay.mjs`, which takes `<part>.int8.onnx` and falls back to `<part>.onnx`. `engine.ts` still names the int8 files.
+Without the directory, starting fails with `transcription.model-missing`. `replay.mjs` takes the precision `recording.json` names (int8 for recordings made before it was recorded) and falls back to the other.
## Development recordings
diff --git a/.claude/skills/working-with-transcription/replay.mjs b/.claude/skills/working-with-transcription/replay.mjs
index 4d9fab202c..e39bd33774 100644
--- a/.claude/skills/working-with-transcription/replay.mjs
+++ b/.claude/skills/working-with-transcription/replay.mjs
@@ -10,7 +10,8 @@
// (the value is parsed as JSON when it parses, else kept as a string)
// --hotwords <a/b/c> per-utterance hotwords, separated by "/" (needs modified_beam_search)
// --model <dir> model directory (default: <data dir>/transcription-model); takes
-// <part>.int8.onnx, else <part>.onnx, for encoder, decoder and joiner
+// <part>.onnx for a full-precision recording, else <part>.int8.onnx,
+// falling back to the other, for encoder, decoder and joiner
// --source <name> replay only microphone or system
// --pad <seconds> extend each segment by this much audio on both sides before decoding
// --force overwrite an existing transcript.<label>.json
@@ -139,10 +140,15 @@ function buildRecognizerConfig(settings, modelDir) {
return config;
}
-/** The int8 file the app ships, or the full-precision `<part>.onnx` of another export. */
+/**
+ * The file of the precision the recording used (`engine.precision`, int8 for recordings made before
+ * the app recorded it), else the other one.
+ */
function modelFile(modelDir, part) {
const int8 = path.join(modelDir, `${part}.int8.onnx`);
- return fs.existsSync(int8) ? int8 : path.join(modelDir, `${part}.onnx`);
+ const fp32 = path.join(modelDir, `${part}.onnx`);
+ const [ preferred, fallback ] = engine.precision === "fp32" ? [ fp32, int8 ] : [ int8, fp32 ];
+ return fs.existsSync(preferred) ? preferred : fallback;
}
function applySetting(target, assignment) {
diff --git a/apps/desktop/src/services/transcription/engine.spec.ts b/apps/desktop/src/services/transcription/engine.spec.ts
index edfd20bc6c..ccdefa5d31 100644
--- a/apps/desktop/src/services/transcription/engine.spec.ts
+++ b/apps/desktop/src/services/transcription/engine.spec.ts
@@ -4,7 +4,8 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import { loadSherpaEngine } from "./engine";
const h = vi.hoisted(() => ({
- hasSpeakerModel: false,
+ /** Base names of the optional model files the model directory holds. */
+ installed: [] as string[],
recognizerConfig: null as Record<string, unknown> | null,
vadConfig: null as Record<string, unknown> | null,
extractorConfig: null as Record<string, unknown> | null,
@@ -86,13 +87,13 @@ vi.mock("sherpa-onnx-node", () => ({
}
}));
vi.mock("fs", () => ({
- default: { existsSync: (file: string) => h.hasSpeakerModel && file.endsWith(".onnx") }
+ default: { existsSync: (file: string) => h.installed.includes(path.basename(file)) }
}));
const MODEL_DIR = "/models/parakeet";
beforeEach(() => {
- h.hasSpeakerModel = false;
+ h.installed = [];
h.isEmbeddingReady = true;
h.decoded.length = 0;
h.embeddings.length = 0;
@@ -120,6 +121,7 @@ describe("loadSherpaEngine", () => {
expect(engine.createSpeakerTracker).toBeUndefined();
expect(engine.settings).toMatchObject({
modelDirectory: path.resolve(MODEL_DIR),
+ precision: "int8",
recognizer: { modelType: "nemo_transducer", blankPenalty: 0.5 },
vad: { minSilenceDuration: 0.75, maxSpeechDuration: 20, windowSize: 512 },
speakers: null
@@ -130,6 +132,25 @@ describe("loadSherpaEngine", () => {
expect(h.decoded).toEqual([ samples ]);
});
+ it("prefers the full-precision model, decoding it without a blank penalty", async () => {
+ h.installed = [ "encoder.onnx" ];
+ const engine = await loadSherpaEngine(MODEL_DIR);
+
+ expect(h.recognizerConfig).toMatchObject({
+ modelConfig: {
+ transducer: {
+ encoder: path.join(MODEL_DIR, "encoder.onnx"),
+ decoder: path.join(MODEL_DIR, "decoder.onnx"),
+ joiner: path.join(MODEL_DIR, "joiner.onnx")
+ }
+ },
+ decodingMethod: "greedy_search"
+ });
+ expect(h.recognizerConfig).not.toHaveProperty("blankPenalty");
+ expect(engine.settings).toMatchObject({ precision: "fp32" });
+ expect(engine.settings.recognizer).not.toHaveProperty("blankPenalty");
+ });
+
it("segments a source in whole 512-sample windows, handing out what the VAD completes", async () => {
const engine = await loadSherpaEngine(MODEL_DIR);
const segmenter = engine.createSegmenter();
@@ -154,7 +175,7 @@ describe("loadSherpaEngine", () => {
});
it("tells speakers apart with the speaker model, when it is installed", async () => {
- h.hasSpeakerModel = true;
+ h.installed = [ "nemo_en_titanet_small.onnx" ];
const engine = await loadSherpaEngine(MODEL_DIR);
expect(h.extractorConfig?.model)
.toBe(path.join(MODEL_DIR, "speaker", "nemo_en_titanet_small.onnx"));
diff --git a/apps/desktop/src/services/transcription/engine.ts b/apps/desktop/src/services/transcription/engine.ts
index fe8a5fc6ef..b478a8b2af 100644
--- a/apps/desktop/src/services/transcription/engine.ts
+++ b/apps/desktop/src/services/transcription/engine.ts
@@ -56,11 +56,17 @@ const RECOGNIZER_SETTINGS = {
provider: "cpu"
};
-const DECODING_SETTINGS = {
- decodingMethod: "greedy_search",
- // Makes Parakeet less likely to emit nothing over a stretch of speech, which otherwise drops
- // whole clauses from segments that contain pauses.
- blankPenalty: 0.5
+/** `fp32` is the full-precision export (2.4 GB), `int8` the quantized one (641 MB). */
+type ModelPrecision = "fp32" | "int8";
+
+/**
+ * The int8 model emits nothing over some stretches of speech and drops whole clauses from segments
+ * with pauses; `blankPenalty` counters that. The full-precision model drops none, and the penalty
+ * only adds stray words to its transcript.
+ */
+const DECODING_SETTINGS: Record<ModelPrecision, Record<string, unknown>> = {
+ fp32: { decodingMethod: "greedy_search" },
+ int8: { decodingMethod: "greedy_search", blankPenalty: 0.5 }
};
const SPEAKER_SETTINGS: SpeakerClustererOptions = {
@@ -80,25 +86,32 @@ const VAD_SETTINGS = {
/**
* Loads the local engine from `modelDir`: Silero VAD for segmentation (`silero_vad.onnx`) and
- * Parakeet TDT 0.6B v3 int8 for recognition, both through sherpa-onnx. Recognition runs on the
- * libuv thread pool; the VAD and the speaker embeddings run on the calling thread.
+ * Parakeet TDT 0.6B v3 for recognition, both through sherpa-onnx. Recognition uses the
+ * full-precision model (`encoder.onnx` with `encoder.weights`) when the directory holds it, else
+ * the int8 one (`encoder.int8.onnx`). Recognition runs on the libuv thread pool; the VAD and the
+ * speaker embeddings run on the calling thread.
*/
export async function loadSherpaEngine(modelDir: string): Promise<SpeechEngine> {
const speakerModel = path.join(modelDir, SPEAKER_MODEL);
+ const precision: ModelPrecision = fs.existsSync(path.join(modelDir, "encoder.onnx"))
+ ? "fp32"
+ : "int8";
+ const suffix = precision === "fp32" ? ".onnx" : ".int8.onnx";
+ const decodingSettings = DECODING_SETTINGS[precision];
const mod = await import("sherpa-onnx-node");
const sherpa = mod.default ?? mod;
const recognizer = await sherpa.OfflineRecognizer.createAsync({
featConfig: { sampleRate: SAMPLE_RATE, featureDim: 80 },
modelConfig: {
transducer: {
- encoder: path.join(modelDir, "encoder.int8.onnx"),
- decoder: path.join(modelDir, "decoder.int8.onnx"),
- joiner: path.join(modelDir, "joiner.int8.onnx")
+ encoder: path.join(modelDir, `encoder${suffix}`),
+ decoder: path.join(modelDir, `decoder${suffix}`),
+ joiner: path.join(modelDir, `joiner${suffix}`)
},
tokens: path.join(modelDir, "tokens.txt"),
...RECOGNIZER_SETTINGS
},
- ...DECODING_SETTINGS
+ ...decodingSettings
});
const speakerExtractor = fs.existsSync(speakerModel)
@@ -129,7 +142,8 @@ export async function loadSherpaEngine(modelDir: string): Promise<SpeechEngine>
: undefined,
settings: {
modelDirectory: path.resolve(modelDir),
- recognizer: { ...RECOGNIZER_SETTINGS, ...DECODING_SETTINGS },
+ precision,
+ recognizer: { ...RECOGNIZER_SETTINGS, ...decodingSettings },
vad: VAD_SETTINGS,
speakers: speakerExtractor
? { model: path.basename(speakerModel), ...SPEAKER_SETTINGS }