@scotteza/opencode-spoken-replies 1.0.4 → 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.
@@ -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 = "semirhuduti.tts.voice";
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";
@@ -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 = "semirhuduti.tts.voice";
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: "semirhuduti.tts.voice",
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 = "semirhuduti.tts.voice";
3
- export declare const KV_ENABLED = "semirhuduti.tts.voice.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 path2 from "path";
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;
@@ -209,7 +238,8 @@ class KokoroRuntime {
209
238
  device
210
239
  });
211
240
  const errors = [];
212
- for (const device of unique(candidateDevices(this.config.device))) {
241
+ const devices = filterCandidateDevices(candidateDevices(this.config.device), availableProviders());
242
+ for (const device of devices) {
213
243
  this.logger.info("runtime init attempt", { device });
214
244
  try {
215
245
  const tts = await loadKokoro(device);
@@ -257,7 +287,7 @@ class KokoroRuntime {
257
287
  // src/voice-log.ts
258
288
  import * as fs from "fs";
259
289
  import * as os from "os";
260
- import * as path from "path";
290
+ import * as path2 from "path";
261
291
  var LOG_PREFIX = "[opencode-tts-voice]";
262
292
  var LOG_FILE_PREFIX = "opencode-tts-voice";
263
293
  var LEVELS = {
@@ -304,9 +334,9 @@ function resolveLogFile() {
304
334
  fileLogDisabled = true;
305
335
  return;
306
336
  }
307
- const dataDir = process.env.XDG_DATA_HOME ?? path.join(home, ".local", "share");
308
- const dir = path.join(dataDir, "opencode", "log");
309
- const file = path.join(dir, `${LOG_FILE_PREFIX}-${timestampForFile(new Date)}.log`);
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`);
310
340
  try {
311
341
  fs.mkdirSync(dir, { recursive: true });
312
342
  logFile = file;
@@ -420,7 +450,7 @@ function runtimeFor(state, config) {
420
450
  }
421
451
  async function ensureTempDir(state) {
422
452
  if (!state.tempDir) {
423
- state.tempDir = fs2.mkdtemp(path2.join(os2.tmpdir(), "opencode-tts-voice-"));
453
+ state.tempDir = fs2.mkdtemp(path3.join(os2.tmpdir(), "opencode-tts-voice-"));
424
454
  logger.info("temp dir requested");
425
455
  }
426
456
  return state.tempDir;
@@ -431,7 +461,7 @@ async function writeAudioFile(state, audio, sampleRate, request) {
431
461
  throw new Error("Missing voice config");
432
462
  const dir = await ensureTempDir(state);
433
463
  const trimmed = trimSilence(audio, sampleRate, config.trimSilenceThreshold, config.leadingAudioPadMs);
434
- const file = path2.join(dir, `${Date.now()}-${request.id}-${state.sequence++}.wav`);
464
+ const file = path3.join(dir, `${Date.now()}-${request.id}-${state.sequence++}.wav`);
435
465
  await fs2.writeFile(file, wavFromFloat32(trimmed, sampleRate));
436
466
  logger.info("audio file written", {
437
467
  file,
@@ -609,7 +639,7 @@ function isEntrypoint() {
609
639
  const entry = process.argv[1];
610
640
  if (!entry)
611
641
  return process.env.OPENCODE_TTS_VOICE_HELPER_MODE === "worker";
612
- return pathToFileURL(path2.resolve(entry)).href === import.meta.url;
642
+ return pathToFileURL(path3.resolve(entry)).href === import.meta.url;
613
643
  }
614
644
  if (isEntrypoint()) {
615
645
  if (process.env.OPENCODE_TTS_VOICE_HELPER_MODE === "worker") {
@@ -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;
@@ -1,5 +1,5 @@
1
1
  export declare const VoiceRpc: {
2
- readonly id: "semirhuduti.tts.voice";
2
+ readonly id: "opencode-spoken-replies";
3
3
  readonly methods: {
4
4
  readonly getEnabled: {
5
5
  readonly input: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scotteza/opencode-spoken-replies",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Local Kokoro text-to-speech for OpenCode assistant replies",
5
5
  "keywords": [
6
6
  "opencode",