@jcode.labs/mimir-tts 0.4.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jean-Baptiste Thery
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Mimir TTS
2
+
3
+ Plug-and-play local text-to-speech for Mimir audio summaries.
4
+
5
+ `@jcode.labs/mimir-tts` renders narration text to WAV with Transformers.js. It does not require
6
+ Python, ffmpeg, Piper, XTTS, or a local server. The first render can download a public ONNX model
7
+ from Hugging Face into `.mimir/models/tts`; the source text is processed locally.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add -D @jcode.labs/mimir-tts
13
+ ```
14
+
15
+ ## Render
16
+
17
+ ```bash
18
+ pnpm exec mimir-tts render /tmp/MIMIR-SUMMARY-tax.txt --out .mimir/audio/tax-summary.wav
19
+ ```
20
+
21
+ For offline or air-gapped use, preload the model files and run:
22
+
23
+ ```bash
24
+ pnpm exec mimir-tts render summary.txt --offline --model-path .mimir/models/tts
25
+ ```
26
+
27
+ ## Doctor
28
+
29
+ ```bash
30
+ pnpm exec mimir-tts doctor --json
31
+ ```
32
+
33
+ The default model is `Xenova/mms-tts-fra`. Override it with `--model` or `MIMIR_TTS_MODEL`.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,140 @@
1
+ #!/usr/bin/env node
2
+ import { parseArgs } from "node:util";
3
+ import { doctor, renderSpeech } from "./index.js";
4
+ const command = process.argv[2];
5
+ try {
6
+ if (command === "doctor") {
7
+ await runDoctor(process.argv.slice(3));
8
+ }
9
+ else if (command === "render") {
10
+ await runRender(process.argv.slice(3));
11
+ }
12
+ else {
13
+ printHelp();
14
+ process.exitCode = command ? 1 : 0;
15
+ }
16
+ }
17
+ catch (error) {
18
+ console.error(error instanceof Error ? error.message : String(error));
19
+ process.exitCode = 1;
20
+ }
21
+ async function runDoctor(args) {
22
+ const { values } = parseArgs({
23
+ args,
24
+ options: {
25
+ json: { type: "boolean" },
26
+ },
27
+ });
28
+ const report = await doctor();
29
+ if (values.json) {
30
+ console.log(JSON.stringify(report, null, 2));
31
+ return;
32
+ }
33
+ printKeyValue("node", report.node);
34
+ printKeyValue("defaultModel", report.defaultModel);
35
+ printKeyValue("defaultModelPath", report.defaultModelPath);
36
+ printKeyValue("transformersAvailable", String(report.transformersAvailable));
37
+ printKeyValue("pythonRequired", String(report.pythonRequired));
38
+ printKeyValue("ffmpegRequired", String(report.ffmpegRequired));
39
+ printKeyValue("outputFormat", report.outputFormat);
40
+ }
41
+ async function runRender(args) {
42
+ const { values, positionals } = parseArgs({
43
+ args,
44
+ allowPositionals: true,
45
+ options: {
46
+ out: { type: "string", short: "o" },
47
+ model: { type: "string" },
48
+ "model-path": { type: "string" },
49
+ offline: { type: "boolean" },
50
+ "allow-remote-models": { type: "boolean" },
51
+ "speaker-embeddings": { type: "string" },
52
+ speed: { type: "string" },
53
+ json: { type: "boolean" },
54
+ },
55
+ });
56
+ const textFile = positionals[0];
57
+ if (!textFile) {
58
+ throw new Error("usage: mimir-tts render <text-file> [--out output.wav]");
59
+ }
60
+ const renderOptions = {
61
+ textFile,
62
+ };
63
+ addStringOption(renderOptions, "outputPath", stringValue(values, "out"));
64
+ addStringOption(renderOptions, "model", stringValue(values, "model"));
65
+ addStringOption(renderOptions, "modelPath", stringValue(values, "model-path"));
66
+ addBooleanOption(renderOptions, "allowRemoteModels", allowRemoteModels(values));
67
+ addStringOption(renderOptions, "speakerEmbeddings", stringValue(values, "speaker-embeddings"));
68
+ addNumberOption(renderOptions, "speed", numberValue(values, "speed"));
69
+ const result = await renderSpeech(renderOptions);
70
+ if (values.json) {
71
+ console.log(JSON.stringify(result, null, 2));
72
+ return;
73
+ }
74
+ printKeyValue("outputPath", result.outputPath);
75
+ printKeyValue("model", result.model);
76
+ printKeyValue("modelPath", result.modelPath);
77
+ printKeyValue("allowRemoteModels", String(result.allowRemoteModels));
78
+ printKeyValue("samplingRate", String(result.samplingRate ?? "unknown"));
79
+ printKeyValue("samples", String(result.samples ?? "unknown"));
80
+ }
81
+ function allowRemoteModels(values) {
82
+ if (values.offline === true) {
83
+ return false;
84
+ }
85
+ if (values["allow-remote-models"] === true) {
86
+ return true;
87
+ }
88
+ return undefined;
89
+ }
90
+ function stringValue(values, key) {
91
+ const value = values[key];
92
+ return typeof value === "string" ? value : undefined;
93
+ }
94
+ function addStringOption(target, key, value) {
95
+ if (value !== undefined) {
96
+ target[key] = value;
97
+ }
98
+ }
99
+ function addBooleanOption(target, key, value) {
100
+ if (value !== undefined) {
101
+ target[key] = value;
102
+ }
103
+ }
104
+ function addNumberOption(target, key, value) {
105
+ if (value !== undefined) {
106
+ target[key] = value;
107
+ }
108
+ }
109
+ function numberValue(values, key) {
110
+ const value = stringValue(values, key);
111
+ if (!value) {
112
+ return undefined;
113
+ }
114
+ const parsed = Number.parseFloat(value);
115
+ if (!Number.isFinite(parsed)) {
116
+ throw new Error(`Expected a number for --${key}.`);
117
+ }
118
+ return parsed;
119
+ }
120
+ function printKeyValue(key, value) {
121
+ console.log(`${key}=${value}`);
122
+ }
123
+ function printHelp() {
124
+ console.log(`mimir-tts
125
+
126
+ Usage:
127
+ mimir-tts doctor [--json]
128
+ mimir-tts render <text-file> [--out output.wav] [--offline]
129
+
130
+ Options:
131
+ --model <id> Transformers.js TTS model ID.
132
+ --model-path <path> Local model/cache path. Defaults to .mimir/models/tts.
133
+ --offline Disable remote model downloads.
134
+ --allow-remote-models Explicitly allow remote model downloads.
135
+ --speaker-embeddings <path> Optional model-specific speaker embedding path or URL.
136
+ --speed <number> Optional model-specific speech speed.
137
+ --json Print JSON output.
138
+ `);
139
+ }
140
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,MAAM,EAA4B,YAAY,EAAE,MAAM,YAAY,CAAA;AAI3E,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAE/B,IAAI,CAAC;IACH,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;QACzB,MAAM,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACxC,CAAC;SAAM,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK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;;;;;;;;CAcb,CAAC,CAAA;AACF,CAAC"}
@@ -0,0 +1,46 @@
1
+ export declare const DEFAULT_TTS_MODEL = "Xenova/mms-tts-fra";
2
+ export declare const DEFAULT_TTS_MODEL_PATH = ".mimir/models/tts";
3
+ export declare const DEFAULT_AUDIO_DIR = ".mimir/audio";
4
+ export interface TextToAudioOutputLike {
5
+ save(path: string): Promise<void>;
6
+ sampling_rate?: number;
7
+ data?: Float32Array;
8
+ }
9
+ export type TextToAudioSynthesizer = (text: string, options?: TextToAudioOptions) => Promise<TextToAudioOutputLike>;
10
+ export interface TextToAudioOptions {
11
+ speaker_embeddings?: string;
12
+ speed?: number;
13
+ }
14
+ export interface RenderSpeechOptions {
15
+ cwd?: string;
16
+ text?: string;
17
+ textFile?: string;
18
+ outputPath?: string;
19
+ model?: string;
20
+ modelPath?: string;
21
+ allowRemoteModels?: boolean;
22
+ speakerEmbeddings?: string;
23
+ speed?: number;
24
+ synthesizer?: TextToAudioSynthesizer;
25
+ }
26
+ export interface RenderSpeechResult {
27
+ outputPath: string;
28
+ model: string;
29
+ modelPath: string;
30
+ allowRemoteModels: boolean;
31
+ samplingRate: number | null;
32
+ samples: number | null;
33
+ }
34
+ export interface DoctorReport {
35
+ node: string;
36
+ defaultModel: string;
37
+ defaultModelPath: string;
38
+ transformersAvailable: boolean;
39
+ pythonRequired: false;
40
+ ffmpegRequired: false;
41
+ outputFormat: "wav";
42
+ }
43
+ export declare function renderSpeech(options: RenderSpeechOptions): Promise<RenderSpeechResult>;
44
+ export declare function doctor(): Promise<DoctorReport>;
45
+ export declare function modelCacheExists(cwd?: string): boolean;
46
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB,uBAAuB,CAAA;AACrD,eAAO,MAAM,sBAAsB,sBAAsB,CAAA;AACzD,eAAO,MAAM,iBAAiB,iBAAiB,C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AAA;IACrB,cAAc,EAAE,KAAK,CAAA;IACrB,YAAY,EAAE,KAAK,CAAA;CACpB;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA6B5F;AAED,wBAAsB,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC,CAUpD;AAgED,wBAAgB,gBAAgB,CAAC,GAAG,SAAgB,GAAG,OAAO,CAE7D"}
package/dist/index.js ADDED
@@ -0,0 +1,92 @@
1
+ import { existsSync } from "node:fs";
2
+ import { mkdir, readFile } from "node:fs/promises";
3
+ import path from "node:path";
4
+ export const DEFAULT_TTS_MODEL = "Xenova/mms-tts-fra";
5
+ export const DEFAULT_TTS_MODEL_PATH = ".mimir/models/tts";
6
+ export const DEFAULT_AUDIO_DIR = ".mimir/audio";
7
+ export async function renderSpeech(options) {
8
+ const cwd = path.resolve(options.cwd ?? process.cwd());
9
+ const text = await readInputText(options);
10
+ const model = options.model ?? process.env.MIMIR_TTS_MODEL ?? DEFAULT_TTS_MODEL;
11
+ const modelPath = resolveFromCwd(cwd, options.modelPath ?? process.env.MIMIR_TTS_MODEL_PATH ?? DEFAULT_TTS_MODEL_PATH);
12
+ const outputPath = resolveFromCwd(cwd, options.outputPath ?? defaultOutputPath(cwd, options.textFile));
13
+ const allowRemoteModels = options.allowRemoteModels ?? readBooleanEnv("MIMIR_TTS_ALLOW_REMOTE_MODELS", true);
14
+ await mkdir(path.dirname(outputPath), { recursive: true });
15
+ const synthesizer = options.synthesizer ?? (await transformerSynthesizer(model, modelPath, allowRemoteModels));
16
+ const output = await synthesizer(text, textToAudioOptions(options));
17
+ await output.save(outputPath);
18
+ return {
19
+ outputPath,
20
+ model,
21
+ modelPath,
22
+ allowRemoteModels,
23
+ samplingRate: typeof output.sampling_rate === "number" ? output.sampling_rate : null,
24
+ samples: output.data instanceof Float32Array ? output.data.length : null,
25
+ };
26
+ }
27
+ export async function doctor() {
28
+ return {
29
+ node: process.versions.node,
30
+ defaultModel: DEFAULT_TTS_MODEL,
31
+ defaultModelPath: DEFAULT_TTS_MODEL_PATH,
32
+ transformersAvailable: await canImportTransformers(),
33
+ pythonRequired: false,
34
+ ffmpegRequired: false,
35
+ outputFormat: "wav",
36
+ };
37
+ }
38
+ async function readInputText(options) {
39
+ const text = options.text ?? (options.textFile ? await readFile(options.textFile, "utf8") : "");
40
+ const trimmed = text.trim();
41
+ if (!trimmed) {
42
+ throw new Error("A non-empty text input or text file is required.");
43
+ }
44
+ return trimmed;
45
+ }
46
+ function defaultOutputPath(cwd, textFile) {
47
+ const name = textFile ? path.basename(textFile, path.extname(textFile)) : "mimir-summary";
48
+ return path.join(cwd, DEFAULT_AUDIO_DIR, `${name}.wav`);
49
+ }
50
+ function resolveFromCwd(cwd, input) {
51
+ return path.isAbsolute(input) ? input : path.resolve(cwd, input);
52
+ }
53
+ function textToAudioOptions(options) {
54
+ const output = {};
55
+ if (options.speakerEmbeddings) {
56
+ output.speaker_embeddings = options.speakerEmbeddings;
57
+ }
58
+ if (typeof options.speed === "number") {
59
+ output.speed = options.speed;
60
+ }
61
+ return Object.keys(output).length > 0 ? output : undefined;
62
+ }
63
+ async function transformerSynthesizer(model, modelPath, allowRemoteModels) {
64
+ const transformers = await import("@huggingface/transformers");
65
+ transformers.env.localModelPath = modelPath;
66
+ transformers.env.cacheDir = modelPath;
67
+ transformers.env.allowRemoteModels = allowRemoteModels;
68
+ return (await transformers.pipeline("text-to-speech", model));
69
+ }
70
+ async function canImportTransformers() {
71
+ try {
72
+ await import("@huggingface/transformers");
73
+ return true;
74
+ }
75
+ catch {
76
+ return false;
77
+ }
78
+ }
79
+ function readBooleanEnv(name, fallback) {
80
+ const raw = process.env[name]?.toLowerCase();
81
+ if (raw === "1" || raw === "true" || raw === "yes") {
82
+ return true;
83
+ }
84
+ if (raw === "0" || raw === "false" || raw === "no") {
85
+ return false;
86
+ }
87
+ return fallback;
88
+ }
89
+ export function modelCacheExists(cwd = process.cwd()) {
90
+ return existsSync(path.resolve(cwd, process.env.MIMIR_TTS_MODEL_PATH ?? DEFAULT_TTS_MODEL_PATH));
91
+ }
92
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,MAAM,CAAC,MAAM,iBAAiB,GAAG,oBAAoB,CAAA;AACrD,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CAAA;AACzD,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAA;AAkD/C,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAA4B;IAC7D,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;IACtD,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,CAAA;IACzC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,iBAAiB,CAAA;IAC/E,MAAM,SAAS,GAAG,cAAc,CAC9B,GAAG,EACH,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,sBAAsB,CAChF,CAAA;IACD,MAAM,UAAU,GAAG,cAAc,CAC/B,GAAG,EACH,OAAO,CAAC,UAAU,IAAI,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,CAC/D,CAAA;IACD,MAAM,iBAAiB,GACrB,OAAO,CAAC,iBAAiB,IAAI,cAAc,CAAC,+BAA+B,EAAE,IAAI,CAAC,CAAA;IAEpF,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CA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c,GAAG,SAAS,CAAA;IAC3C,YAAY,CAAC,GAAG,CAAC,QAAQ,GAAG,SAAS,CAAA;IACrC,YAAY,CAAC,GAAG,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;IAEtD,OAAO,CAAC,MAAM,YAAY,CAAC,QAAQ,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAA2B,CAAA;AACzF,CAAC;AAED,KAAK,UAAU,qBAAqB;IAClC,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,2BAA2B,CAAC,CAAA;QACzC,OAAO,IAAI,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,IAAY,EAAE,QAAiB;IACrD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,WAAW,EAAE,CAAA;IAC5C,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC;QACnD,OAAO,IAAI,CAAA;IACb,CAAC;IACD,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,IAAI,EAAE,CAAC;QACnD,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE;IAClD,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,sBAAsB,CAAC,CAAC,CAAA;AAClG,CAAC"}
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@jcode.labs/mimir-tts",
3
+ "version": "0.4.0",
4
+ "description": "Plug-and-play local text-to-speech for Mimir audio summaries.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": {
8
+ "name": "Jean-Baptiste Thery",
9
+ "url": "https://github.com/jb-thery"
10
+ },
11
+ "keywords": [
12
+ "jcode",
13
+ "mimir",
14
+ "text-to-speech",
15
+ "tts",
16
+ "local-first",
17
+ "transformers",
18
+ "onnx",
19
+ "audio"
20
+ ],
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/jcode-works/jcode-mimir.git",
24
+ "directory": "packages/mimir-tts"
25
+ },
26
+ "homepage": "https://github.com/jcode-works/jcode-mimir/tree/main/packages/mimir-tts#readme",
27
+ "bugs": {
28
+ "url": "https://github.com/jcode-works/jcode-mimir/issues"
29
+ },
30
+ "engines": {
31
+ "node": ">=20"
32
+ },
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.js"
37
+ }
38
+ },
39
+ "bin": {
40
+ "mimir-tts": "dist/cli.js"
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "README.md",
45
+ "LICENSE"
46
+ ],
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "dependencies": {
51
+ "@huggingface/transformers": "^4.2.0"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^24.10.1",
55
+ "publint": "^0.3.21",
56
+ "typescript": "^5.9.3",
57
+ "vitest": "^4.0.15"
58
+ },
59
+ "scripts": {
60
+ "build": "tsc -p tsconfig.json",
61
+ "check": "tsc -p tsconfig.json --noEmit",
62
+ "package:check": "publint",
63
+ "smoke": "node dist/cli.js doctor --json",
64
+ "test": "vitest run"
65
+ }
66
+ }