@scotteza/opencode-spoken-replies 1.0.3 → 1.0.5
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/dist/server-plugin.js +22 -20
- package/dist/tui-plugin.js +2 -2
- package/dist/voice-constants.d.ts +2 -2
- package/dist/voice-helper-process.js +51 -10
- package/dist/voice-kokoro.d.ts +6 -0
- package/dist/voice-rpc.d.ts +1 -1
- package/package.json +1 -1
package/dist/server-plugin.js
CHANGED
|
@@ -40,28 +40,9 @@ function createTtsFriendlySystemPrompt() {
|
|
|
40
40
|
|
|
41
41
|
// src/voice-rpc.ts
|
|
42
42
|
import { Rpc } from "@opencode/plugin/rpc";
|
|
43
|
-
var state = {
|
|
44
|
-
type: "object",
|
|
45
|
-
properties: { enabled: { type: "boolean" } },
|
|
46
|
-
required: ["enabled"],
|
|
47
|
-
additionalProperties: false
|
|
48
|
-
};
|
|
49
|
-
var VoiceRpc = Rpc.define({
|
|
50
|
-
id: "semirhuduti.tts.voice",
|
|
51
|
-
methods: {
|
|
52
|
-
getEnabled: {
|
|
53
|
-
input: { type: "object", additionalProperties: false },
|
|
54
|
-
output: state
|
|
55
|
-
},
|
|
56
|
-
setEnabled: { input: state, output: state }
|
|
57
|
-
},
|
|
58
|
-
events: {
|
|
59
|
-
stateChanged: { schema: state }
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
43
|
|
|
63
44
|
// src/voice-constants.ts
|
|
64
|
-
var PLUGIN_ID = "
|
|
45
|
+
var PLUGIN_ID = "opencode-spoken-replies";
|
|
65
46
|
var KV_ENABLED = `${PLUGIN_ID}.enabled`;
|
|
66
47
|
var DEFAULT_MODEL = "onnx-community/Kokoro-82M-v1.0-ONNX";
|
|
67
48
|
var DEFAULT_CONFIG = {
|
|
@@ -104,6 +85,27 @@ var PLAYER_DEFAULT_ARGS = {
|
|
|
104
85
|
};
|
|
105
86
|
var PLAYER_CANDIDATES = ["ffplay", "mpv", "paplay", "aplay"];
|
|
106
87
|
|
|
88
|
+
// src/voice-rpc.ts
|
|
89
|
+
var state = {
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: { enabled: { type: "boolean" } },
|
|
92
|
+
required: ["enabled"],
|
|
93
|
+
additionalProperties: false
|
|
94
|
+
};
|
|
95
|
+
var VoiceRpc = Rpc.define({
|
|
96
|
+
id: PLUGIN_ID,
|
|
97
|
+
methods: {
|
|
98
|
+
getEnabled: {
|
|
99
|
+
input: { type: "object", additionalProperties: false },
|
|
100
|
+
output: state
|
|
101
|
+
},
|
|
102
|
+
setEnabled: { input: state, output: state }
|
|
103
|
+
},
|
|
104
|
+
events: {
|
|
105
|
+
stateChanged: { schema: state }
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
107
109
|
// src/voice-log.ts
|
|
108
110
|
import * as fs from "fs";
|
|
109
111
|
import * as os from "os";
|
package/dist/tui-plugin.js
CHANGED
|
@@ -1433,7 +1433,7 @@ import * as fsSync2 from "fs";
|
|
|
1433
1433
|
import * as path3 from "path";
|
|
1434
1434
|
|
|
1435
1435
|
// src/voice-constants.ts
|
|
1436
|
-
var PLUGIN_ID = "
|
|
1436
|
+
var PLUGIN_ID = "opencode-spoken-replies";
|
|
1437
1437
|
var KV_ENABLED = `${PLUGIN_ID}.enabled`;
|
|
1438
1438
|
var DEFAULT_MODEL = "onnx-community/Kokoro-82M-v1.0-ONNX";
|
|
1439
1439
|
var DEFAULT_CONFIG = {
|
|
@@ -2990,7 +2990,7 @@ var state = {
|
|
|
2990
2990
|
additionalProperties: false
|
|
2991
2991
|
};
|
|
2992
2992
|
var VoiceRpc = Rpc.define({
|
|
2993
|
-
id:
|
|
2993
|
+
id: PLUGIN_ID,
|
|
2994
2994
|
methods: {
|
|
2995
2995
|
getEnabled: {
|
|
2996
2996
|
input: { type: "object", additionalProperties: false },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { VoiceConfig } from "./voice-types.js";
|
|
2
|
-
export declare const PLUGIN_ID = "
|
|
3
|
-
export declare const KV_ENABLED = "
|
|
2
|
+
export declare const PLUGIN_ID = "opencode-spoken-replies";
|
|
3
|
+
export declare const KV_ENABLED = "opencode-spoken-replies.enabled";
|
|
4
4
|
export declare const DEFAULT_MODEL = "onnx-community/Kokoro-82M-v1.0-ONNX";
|
|
5
5
|
export declare const DEFAULT_CONFIG: VoiceConfig;
|
|
6
6
|
export declare const PLAYER_DEFAULT_ARGS: Record<string, string[]>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// src/voice-helper-process.ts
|
|
3
3
|
import * as fs2 from "fs/promises";
|
|
4
4
|
import * as os2 from "os";
|
|
5
|
-
import * as
|
|
5
|
+
import * as path3 from "path";
|
|
6
6
|
import { stdin, stdout } from "process";
|
|
7
7
|
import { createInterface } from "readline";
|
|
8
8
|
import { pathToFileURL } from "url";
|
|
@@ -52,6 +52,9 @@ function wavFromFloat32(audio, sampleRate) {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
// src/voice-kokoro.ts
|
|
55
|
+
import { existsSync } from "fs";
|
|
56
|
+
import { createRequire } from "module";
|
|
57
|
+
import * as path from "path";
|
|
55
58
|
function unique(values) {
|
|
56
59
|
return Array.from(new Set(values));
|
|
57
60
|
}
|
|
@@ -74,6 +77,32 @@ function candidateDevices(device) {
|
|
|
74
77
|
return ["gpu", "cuda", "dml", "webgpu", "cpu"];
|
|
75
78
|
}
|
|
76
79
|
}
|
|
80
|
+
function filterCandidateDevices(devices, available) {
|
|
81
|
+
return unique(devices.filter((device) => {
|
|
82
|
+
if (device === "gpu")
|
|
83
|
+
return available.cuda || available.dml || available.webgpu;
|
|
84
|
+
if (device === "cuda")
|
|
85
|
+
return available.cuda;
|
|
86
|
+
if (device === "dml")
|
|
87
|
+
return available.dml;
|
|
88
|
+
if (device === "webgpu")
|
|
89
|
+
return available.webgpu;
|
|
90
|
+
if (device === "wasm")
|
|
91
|
+
return false;
|
|
92
|
+
return device === "cpu";
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
function availableProviders() {
|
|
96
|
+
const require2 = createRequire(import.meta.url);
|
|
97
|
+
const runtimeEntry = require2.resolve("onnxruntime-node");
|
|
98
|
+
const runtimePackage = path.resolve(path.dirname(runtimeEntry), "..");
|
|
99
|
+
const nativeDirectory = path.join(runtimePackage, "bin", "napi-v3", process.platform, process.arch);
|
|
100
|
+
return {
|
|
101
|
+
cuda: process.platform === "linux" && process.arch === "x64" && existsSync(path.join(nativeDirectory, "libonnxruntime_providers_cuda.so")),
|
|
102
|
+
dml: process.platform === "win32" && existsSync(path.join(nativeDirectory, "DirectML.dll")),
|
|
103
|
+
webgpu: false
|
|
104
|
+
};
|
|
105
|
+
}
|
|
77
106
|
function formatError(error) {
|
|
78
107
|
if (error instanceof Error && error.message)
|
|
79
108
|
return error.message;
|
|
@@ -84,7 +113,18 @@ async function prepareOnnxRuntime() {
|
|
|
84
113
|
ort.env.logLevel = "error";
|
|
85
114
|
}
|
|
86
115
|
async function loadKokoroModule() {
|
|
87
|
-
|
|
116
|
+
const runtimeSymbol = Symbol.for("onnxruntime");
|
|
117
|
+
const runtimeHost = globalThis;
|
|
118
|
+
const hadRuntimeOverride = runtimeSymbol in runtimeHost;
|
|
119
|
+
const runtimeOverride = runtimeHost[runtimeSymbol];
|
|
120
|
+
if (hadRuntimeOverride)
|
|
121
|
+
delete runtimeHost[runtimeSymbol];
|
|
122
|
+
try {
|
|
123
|
+
return await import("kokoro-js");
|
|
124
|
+
} finally {
|
|
125
|
+
if (hadRuntimeOverride)
|
|
126
|
+
runtimeHost[runtimeSymbol] = runtimeOverride;
|
|
127
|
+
}
|
|
88
128
|
}
|
|
89
129
|
|
|
90
130
|
class KokoroRuntime {
|
|
@@ -198,7 +238,8 @@ class KokoroRuntime {
|
|
|
198
238
|
device
|
|
199
239
|
});
|
|
200
240
|
const errors = [];
|
|
201
|
-
|
|
241
|
+
const devices = filterCandidateDevices(candidateDevices(this.config.device), availableProviders());
|
|
242
|
+
for (const device of devices) {
|
|
202
243
|
this.logger.info("runtime init attempt", { device });
|
|
203
244
|
try {
|
|
204
245
|
const tts = await loadKokoro(device);
|
|
@@ -246,7 +287,7 @@ class KokoroRuntime {
|
|
|
246
287
|
// src/voice-log.ts
|
|
247
288
|
import * as fs from "fs";
|
|
248
289
|
import * as os from "os";
|
|
249
|
-
import * as
|
|
290
|
+
import * as path2 from "path";
|
|
250
291
|
var LOG_PREFIX = "[opencode-tts-voice]";
|
|
251
292
|
var LOG_FILE_PREFIX = "opencode-tts-voice";
|
|
252
293
|
var LEVELS = {
|
|
@@ -293,9 +334,9 @@ function resolveLogFile() {
|
|
|
293
334
|
fileLogDisabled = true;
|
|
294
335
|
return;
|
|
295
336
|
}
|
|
296
|
-
const dataDir = process.env.XDG_DATA_HOME ??
|
|
297
|
-
const dir =
|
|
298
|
-
const file =
|
|
337
|
+
const dataDir = process.env.XDG_DATA_HOME ?? path2.join(home, ".local", "share");
|
|
338
|
+
const dir = path2.join(dataDir, "opencode", "log");
|
|
339
|
+
const file = path2.join(dir, `${LOG_FILE_PREFIX}-${timestampForFile(new Date)}.log`);
|
|
299
340
|
try {
|
|
300
341
|
fs.mkdirSync(dir, { recursive: true });
|
|
301
342
|
logFile = file;
|
|
@@ -409,7 +450,7 @@ function runtimeFor(state, config) {
|
|
|
409
450
|
}
|
|
410
451
|
async function ensureTempDir(state) {
|
|
411
452
|
if (!state.tempDir) {
|
|
412
|
-
state.tempDir = fs2.mkdtemp(
|
|
453
|
+
state.tempDir = fs2.mkdtemp(path3.join(os2.tmpdir(), "opencode-tts-voice-"));
|
|
413
454
|
logger.info("temp dir requested");
|
|
414
455
|
}
|
|
415
456
|
return state.tempDir;
|
|
@@ -420,7 +461,7 @@ async function writeAudioFile(state, audio, sampleRate, request) {
|
|
|
420
461
|
throw new Error("Missing voice config");
|
|
421
462
|
const dir = await ensureTempDir(state);
|
|
422
463
|
const trimmed = trimSilence(audio, sampleRate, config.trimSilenceThreshold, config.leadingAudioPadMs);
|
|
423
|
-
const file =
|
|
464
|
+
const file = path3.join(dir, `${Date.now()}-${request.id}-${state.sequence++}.wav`);
|
|
424
465
|
await fs2.writeFile(file, wavFromFloat32(trimmed, sampleRate));
|
|
425
466
|
logger.info("audio file written", {
|
|
426
467
|
file,
|
|
@@ -598,7 +639,7 @@ function isEntrypoint() {
|
|
|
598
639
|
const entry = process.argv[1];
|
|
599
640
|
if (!entry)
|
|
600
641
|
return process.env.OPENCODE_TTS_VOICE_HELPER_MODE === "worker";
|
|
601
|
-
return pathToFileURL(
|
|
642
|
+
return pathToFileURL(path3.resolve(entry)).href === import.meta.url;
|
|
602
643
|
}
|
|
603
644
|
if (isEntrypoint()) {
|
|
604
645
|
if (process.env.OPENCODE_TTS_VOICE_HELPER_MODE === "worker") {
|
package/dist/voice-kokoro.d.ts
CHANGED
|
@@ -3,6 +3,12 @@ import type { VoiceLogger } from "./voice-log.js";
|
|
|
3
3
|
type TransformDevice = "auto" | "cpu" | "gpu" | "cuda" | "dml" | "wasm" | "webgpu";
|
|
4
4
|
type RuntimeStatus = Partial<Pick<VoiceState, "device" | "error">>;
|
|
5
5
|
export declare function candidateDevices(device: VoiceConfig["device"]): TransformDevice[];
|
|
6
|
+
type AvailableProviders = {
|
|
7
|
+
cuda: boolean;
|
|
8
|
+
dml: boolean;
|
|
9
|
+
webgpu: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function filterCandidateDevices(devices: TransformDevice[], available: AvailableProviders): TransformDevice[];
|
|
6
12
|
export declare class KokoroRuntime {
|
|
7
13
|
private readonly config;
|
|
8
14
|
private readonly onStatus;
|
package/dist/voice-rpc.d.ts
CHANGED