@scotteza/opencode-spoken-replies 1.0.4 → 1.0.6
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/README.md +26 -2
- package/dist/server-plugin.js +23 -20
- package/dist/tui-plugin.js +52 -3
- package/dist/voice-constants.d.ts +3 -2
- package/dist/voice-helper-process.js +39 -9
- package/dist/voice-kokoro.d.ts +6 -0
- package/dist/voice-plugin-options.d.ts +3 -0
- package/dist/voice-rpc.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
OpenCode Spoken Replies lets OpenCode read assistant replies aloud as they arrive. Choose a voice, adjust the speed, and pause or replay speech from the terminal interface.
|
|
4
4
|
|
|
5
|
-
This independently maintained fork builds on [opencode-tts-voice](https://github.com/semirhuduti/opencode-tts-voice). It is not maintained, endorsed, or supported by the original author.
|
|
5
|
+
This independently maintained fork builds on [opencode-tts-voice](https://github.com/semirhuduti/opencode-tts-voice) from Semir Huduti. It is not maintained, endorsed, or supported by the original author.
|
|
6
6
|
|
|
7
|
-
If you appreciate the original author's work, please
|
|
7
|
+
If you appreciate the original author's work, please buy him a coffee using the link below .
|
|
8
8
|
|
|
9
9
|
[](https://www.buymeacoffee.com/semirhuduti)
|
|
10
10
|
|
|
@@ -27,6 +27,30 @@ Install the published npm package with:
|
|
|
27
27
|
opencode plugin add @scotteza/opencode-spoken-replies
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
### Windows setup
|
|
31
|
+
|
|
32
|
+
The TTS helper needs Node.js or Bun available to the OpenCode process. If OpenCode reports that it cannot find either runtime, install [Node.js](https://nodejs.org/en/download/) for Windows and enable the installer option to add Node to `PATH`. Then fully exit and restart OpenCode so it inherits the updated `PATH`. Verify Node is available in PowerShell with:
|
|
33
|
+
|
|
34
|
+
```powershell
|
|
35
|
+
node --version
|
|
36
|
+
where.exe node
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Windows also needs an audio player on `PATH`; install a Windows build of `ffplay` or `mpv`. If OpenCode still cannot find Node, set `ttsServiceCommand` in this plugin's `options` to the full path to `node.exe`, for example:
|
|
40
|
+
|
|
41
|
+
```jsonc
|
|
42
|
+
{
|
|
43
|
+
"plugins": [
|
|
44
|
+
{
|
|
45
|
+
"package": "@scotteza/opencode-spoken-replies",
|
|
46
|
+
"options": {
|
|
47
|
+
"ttsServiceCommand": "C:\\Program Files\\nodejs\\node.exe"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
30
54
|
Or add it to the `plugins` array in your OpenCode `opencode.json` or `opencode.jsonc`:
|
|
31
55
|
|
|
32
56
|
```jsonc
|
package/dist/server-plugin.js
CHANGED
|
@@ -40,28 +40,10 @@ 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";
|
|
46
|
+
var PLUGIN_PACKAGE = "@scotteza/opencode-spoken-replies";
|
|
65
47
|
var KV_ENABLED = `${PLUGIN_ID}.enabled`;
|
|
66
48
|
var DEFAULT_MODEL = "onnx-community/Kokoro-82M-v1.0-ONNX";
|
|
67
49
|
var DEFAULT_CONFIG = {
|
|
@@ -104,6 +86,27 @@ var PLAYER_DEFAULT_ARGS = {
|
|
|
104
86
|
};
|
|
105
87
|
var PLAYER_CANDIDATES = ["ffplay", "mpv", "paplay", "aplay"];
|
|
106
88
|
|
|
89
|
+
// src/voice-rpc.ts
|
|
90
|
+
var state = {
|
|
91
|
+
type: "object",
|
|
92
|
+
properties: { enabled: { type: "boolean" } },
|
|
93
|
+
required: ["enabled"],
|
|
94
|
+
additionalProperties: false
|
|
95
|
+
};
|
|
96
|
+
var VoiceRpc = Rpc.define({
|
|
97
|
+
id: PLUGIN_ID,
|
|
98
|
+
methods: {
|
|
99
|
+
getEnabled: {
|
|
100
|
+
input: { type: "object", additionalProperties: false },
|
|
101
|
+
output: state
|
|
102
|
+
},
|
|
103
|
+
setEnabled: { input: state, output: state }
|
|
104
|
+
},
|
|
105
|
+
events: {
|
|
106
|
+
stateChanged: { schema: state }
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
107
110
|
// src/voice-log.ts
|
|
108
111
|
import * as fs from "fs";
|
|
109
112
|
import * as os from "os";
|
package/dist/tui-plugin.js
CHANGED
|
@@ -1433,7 +1433,8 @@ 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
|
+
var PLUGIN_PACKAGE = "@scotteza/opencode-spoken-replies";
|
|
1437
1438
|
var KV_ENABLED = `${PLUGIN_ID}.enabled`;
|
|
1438
1439
|
var DEFAULT_MODEL = "onnx-community/Kokoro-82M-v1.0-ONNX";
|
|
1439
1440
|
var DEFAULT_CONFIG = {
|
|
@@ -2981,6 +2982,46 @@ function resolveVoiceConfig(options) {
|
|
|
2981
2982
|
};
|
|
2982
2983
|
}
|
|
2983
2984
|
|
|
2985
|
+
// src/voice-plugin-options.ts
|
|
2986
|
+
function isRecord2(value) {
|
|
2987
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
2988
|
+
}
|
|
2989
|
+
function optionsFromEntry(entry) {
|
|
2990
|
+
if (isRecord2(entry) && entry.package === PLUGIN_PACKAGE && isRecord2(entry.options)) {
|
|
2991
|
+
return entry.options;
|
|
2992
|
+
}
|
|
2993
|
+
if (Array.isArray(entry) && entry[0] === PLUGIN_PACKAGE && isRecord2(entry[1])) {
|
|
2994
|
+
return entry[1];
|
|
2995
|
+
}
|
|
2996
|
+
return;
|
|
2997
|
+
}
|
|
2998
|
+
function findVoicePluginOptions(response) {
|
|
2999
|
+
const payload = isRecord2(response) && "data" in response ? response.data : response;
|
|
3000
|
+
const documents = Array.isArray(payload) ? payload : [payload];
|
|
3001
|
+
const options = {};
|
|
3002
|
+
let found = false;
|
|
3003
|
+
for (const document of documents) {
|
|
3004
|
+
if (!isRecord2(document))
|
|
3005
|
+
continue;
|
|
3006
|
+
const info = isRecord2(document.info) ? document.info : document;
|
|
3007
|
+
const entries = Array.isArray(info.plugins) ? info.plugins : Array.isArray(info.plugin) ? info.plugin : [];
|
|
3008
|
+
for (const entry of entries) {
|
|
3009
|
+
const configured = optionsFromEntry(entry);
|
|
3010
|
+
if (!configured)
|
|
3011
|
+
continue;
|
|
3012
|
+
Object.assign(options, configured);
|
|
3013
|
+
found = true;
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
return found ? options : undefined;
|
|
3017
|
+
}
|
|
3018
|
+
function mergeVoicePluginOptions(configured, runtime) {
|
|
3019
|
+
return {
|
|
3020
|
+
...configured ?? {},
|
|
3021
|
+
...isRecord2(runtime) ? runtime : {}
|
|
3022
|
+
};
|
|
3023
|
+
}
|
|
3024
|
+
|
|
2984
3025
|
// src/voice-rpc.ts
|
|
2985
3026
|
import { Rpc } from "@opencode/plugin/rpc";
|
|
2986
3027
|
var state = {
|
|
@@ -2990,7 +3031,7 @@ var state = {
|
|
|
2990
3031
|
additionalProperties: false
|
|
2991
3032
|
};
|
|
2992
3033
|
var VoiceRpc = Rpc.define({
|
|
2993
|
-
id:
|
|
3034
|
+
id: PLUGIN_ID,
|
|
2994
3035
|
methods: {
|
|
2995
3036
|
getEnabled: {
|
|
2996
3037
|
input: { type: "object", additionalProperties: false },
|
|
@@ -3018,7 +3059,15 @@ function Status(props) {
|
|
|
3018
3059
|
var tui_plugin_default = Plugin.define({
|
|
3019
3060
|
id: PLUGIN_ID,
|
|
3020
3061
|
async setup(api) {
|
|
3021
|
-
|
|
3062
|
+
let configuredOptions;
|
|
3063
|
+
try {
|
|
3064
|
+
configuredOptions = findVoicePluginOptions(await api.client.config.get());
|
|
3065
|
+
} catch (error) {
|
|
3066
|
+
log.warn("could not read plugin options from OpenCode config", {
|
|
3067
|
+
error: String(error)
|
|
3068
|
+
});
|
|
3069
|
+
}
|
|
3070
|
+
const config = resolveVoiceConfig(mergeVoicePluginOptions(configuredOptions, api.options));
|
|
3022
3071
|
const voice = api.client.rpc(VoiceRpc);
|
|
3023
3072
|
const location = api.location ?? api.data.location.default();
|
|
3024
3073
|
let enabled = true;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { VoiceConfig } from "./voice-types.js";
|
|
2
|
-
export declare const PLUGIN_ID = "
|
|
3
|
-
export declare const
|
|
2
|
+
export declare const PLUGIN_ID = "opencode-spoken-replies";
|
|
3
|
+
export declare const PLUGIN_PACKAGE = "@scotteza/opencode-spoken-replies";
|
|
4
|
+
export declare const KV_ENABLED = "opencode-spoken-replies.enabled";
|
|
4
5
|
export declare const DEFAULT_MODEL = "onnx-community/Kokoro-82M-v1.0-ONNX";
|
|
5
6
|
export declare const DEFAULT_CONFIG: VoiceConfig;
|
|
6
7
|
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;
|
|
@@ -209,7 +238,8 @@ class KokoroRuntime {
|
|
|
209
238
|
device
|
|
210
239
|
});
|
|
211
240
|
const errors = [];
|
|
212
|
-
|
|
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
|
|
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 ??
|
|
308
|
-
const dir =
|
|
309
|
-
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`);
|
|
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(
|
|
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 =
|
|
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(
|
|
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") {
|
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;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { VoicePluginOptions } from "./voice-types.js";
|
|
2
|
+
export declare function findVoicePluginOptions(response: unknown): VoicePluginOptions | undefined;
|
|
3
|
+
export declare function mergeVoicePluginOptions(configured: VoicePluginOptions | undefined, runtime: unknown): VoicePluginOptions;
|
package/dist/voice-rpc.d.ts
CHANGED