@scotteza/opencode-spoken-replies 0.0.0-stage → 1.0.1
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 +22 -0
- package/README.md +138 -2
- package/dist/commands/voice-commands.d.ts +41 -0
- package/dist/commands/voice-menu.d.ts +5 -0
- package/dist/commands/voice-picker.d.ts +2 -0
- package/dist/latest/latest-message-store.d.ts +56 -0
- package/dist/messages/message-store.d.ts +18 -0
- package/dist/playback/playback-pipeline.d.ts +52 -0
- package/dist/playback/player-service.d.ts +30 -0
- package/dist/playback/queue.d.ts +112 -0
- package/dist/server-plugin.d.ts +3 -0
- package/dist/server-plugin.js +264 -0
- package/dist/session/idle-controller.d.ts +19 -0
- package/dist/session/question-controller.d.ts +20 -0
- package/dist/session/session-store.d.ts +25 -0
- package/dist/shared/timer-registry.d.ts +12 -0
- package/dist/shared/voice-utils.d.ts +8 -0
- package/dist/state/voice-state-store.d.ts +32 -0
- package/dist/state/voice-status.d.ts +2 -0
- package/dist/streaming/stream-buffer.d.ts +59 -0
- package/dist/streaming/streaming-controller.d.ts +33 -0
- package/dist/system-prompt-injection.d.ts +1 -0
- package/dist/tui-plugin.d.ts +4 -0
- package/dist/tui-plugin.js +3342 -0
- package/dist/voice-audio.d.ts +2 -0
- package/dist/voice-config.d.ts +2 -0
- package/dist/voice-constants.d.ts +7 -0
- package/dist/voice-helper-process.d.ts +26 -0
- package/dist/voice-helper-process.js +615 -0
- package/dist/voice-helper-protocol.d.ts +38 -0
- package/dist/voice-helper-runtime.d.ts +34 -0
- package/dist/voice-kokoro.d.ts +24 -0
- package/dist/voice-log.d.ts +12 -0
- package/dist/voice-rpc.d.ts +57 -0
- package/dist/voice-sanitize.d.ts +23 -0
- package/dist/voice-selection.d.ts +26 -0
- package/dist/voice-speed.d.ts +27 -0
- package/dist/voice-text.d.ts +9 -0
- package/dist/voice-types.d.ts +79 -0
- package/package.json +72 -4
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { RuntimeStatus } from "./voice-helper-protocol.js";
|
|
2
|
+
import type { VoiceConfig } from "./voice-types.js";
|
|
3
|
+
import type { VoiceLogger } from "./voice-log.js";
|
|
4
|
+
type GeneratedSegment = {
|
|
5
|
+
text: string;
|
|
6
|
+
file: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function resolveHelperServiceLaunch(config: Pick<VoiceConfig, "ttsServiceCommand" | "ttsServiceArgs">, helper: string, execPath?: string, env?: NodeJS.ProcessEnv): {
|
|
9
|
+
command: string;
|
|
10
|
+
args: string[];
|
|
11
|
+
};
|
|
12
|
+
export declare class TtsHelperRuntime {
|
|
13
|
+
private readonly config;
|
|
14
|
+
private readonly onStatus;
|
|
15
|
+
private readonly logger;
|
|
16
|
+
private child?;
|
|
17
|
+
private started?;
|
|
18
|
+
private disposed;
|
|
19
|
+
private nextID;
|
|
20
|
+
private pending;
|
|
21
|
+
constructor(config: VoiceConfig, onStatus: (status: RuntimeStatus) => void, logger: VoiceLogger);
|
|
22
|
+
stream(text: string, epoch: number, voice?: string): AsyncGenerator<GeneratedSegment, void, void>;
|
|
23
|
+
cancelEpoch(epoch: number): Promise<void>;
|
|
24
|
+
dispose(): Promise<void>;
|
|
25
|
+
private send;
|
|
26
|
+
private write;
|
|
27
|
+
private ensureStarted;
|
|
28
|
+
private start;
|
|
29
|
+
private handleResponse;
|
|
30
|
+
private failAll;
|
|
31
|
+
private wait;
|
|
32
|
+
private wake;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { VoiceConfig, VoiceState } from "./voice-types.js";
|
|
2
|
+
import type { VoiceLogger } from "./voice-log.js";
|
|
3
|
+
type RuntimeStatus = Partial<Pick<VoiceState, "device" | "error">>;
|
|
4
|
+
export declare class KokoroRuntime {
|
|
5
|
+
private readonly config;
|
|
6
|
+
private readonly onStatus;
|
|
7
|
+
private readonly logger;
|
|
8
|
+
private loaded?;
|
|
9
|
+
private loading?;
|
|
10
|
+
constructor(config: VoiceConfig, onStatus: (status: RuntimeStatus) => void, logger: VoiceLogger);
|
|
11
|
+
generate(text: string): Promise<{
|
|
12
|
+
audio: Float32Array<ArrayBufferLike>;
|
|
13
|
+
sampleRate: number;
|
|
14
|
+
}>;
|
|
15
|
+
stream(text: string, speed?: number, voice?: string): AsyncGenerator<{
|
|
16
|
+
text: string;
|
|
17
|
+
audio: Float32Array<ArrayBufferLike>;
|
|
18
|
+
sampleRate: number;
|
|
19
|
+
}, void, unknown>;
|
|
20
|
+
dispose(): Promise<void>;
|
|
21
|
+
private load;
|
|
22
|
+
private create;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type LogFields = Record<string, unknown>;
|
|
2
|
+
type LoggerOptions = {
|
|
3
|
+
console?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare function createLogger(scope: string, options?: LoggerOptions): {
|
|
6
|
+
debug(message: string, fields?: LogFields): void;
|
|
7
|
+
info(message: string, fields?: LogFields): void;
|
|
8
|
+
warn(message: string, fields?: LogFields): void;
|
|
9
|
+
error(message: string, fields?: LogFields): void;
|
|
10
|
+
};
|
|
11
|
+
export type VoiceLogger = ReturnType<typeof createLogger>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export declare const VoiceRpc: {
|
|
2
|
+
readonly id: "semirhuduti.tts.voice";
|
|
3
|
+
readonly methods: {
|
|
4
|
+
readonly getEnabled: {
|
|
5
|
+
readonly input: {
|
|
6
|
+
readonly type: "object";
|
|
7
|
+
readonly additionalProperties: false;
|
|
8
|
+
};
|
|
9
|
+
readonly output: {
|
|
10
|
+
readonly type: "object";
|
|
11
|
+
readonly properties: {
|
|
12
|
+
readonly enabled: {
|
|
13
|
+
readonly type: "boolean";
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
readonly required: readonly ["enabled"];
|
|
17
|
+
readonly additionalProperties: false;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
readonly setEnabled: {
|
|
21
|
+
readonly input: {
|
|
22
|
+
readonly type: "object";
|
|
23
|
+
readonly properties: {
|
|
24
|
+
readonly enabled: {
|
|
25
|
+
readonly type: "boolean";
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
readonly required: readonly ["enabled"];
|
|
29
|
+
readonly additionalProperties: false;
|
|
30
|
+
};
|
|
31
|
+
readonly output: {
|
|
32
|
+
readonly type: "object";
|
|
33
|
+
readonly properties: {
|
|
34
|
+
readonly enabled: {
|
|
35
|
+
readonly type: "boolean";
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
readonly required: readonly ["enabled"];
|
|
39
|
+
readonly additionalProperties: false;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
readonly events: {
|
|
44
|
+
readonly stateChanged: {
|
|
45
|
+
readonly schema: {
|
|
46
|
+
readonly type: "object";
|
|
47
|
+
readonly properties: {
|
|
48
|
+
readonly enabled: {
|
|
49
|
+
readonly type: "boolean";
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
readonly required: readonly ["enabled"];
|
|
53
|
+
readonly additionalProperties: false;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const BUILT_IN_FILE_EXTENSIONS: readonly ["astro", "avif", "cjs", "css", "csv", "gif", "go", "html", "jpeg", "jpg", "js", "json", "jsx", "lock", "md", "mjs", "png", "py", "rs", "sh", "svg", "svelte", "toml", "ts", "tsx", "txt", "vue", "webp", "xml", "yaml", "yml"];
|
|
2
|
+
export type SpeechSanitizerOptions = {
|
|
3
|
+
fileExtensions?: readonly string[];
|
|
4
|
+
};
|
|
5
|
+
export declare function normalizeFileExtensions(value: unknown): string[];
|
|
6
|
+
export declare class SpeechSanitizer {
|
|
7
|
+
private readonly settings;
|
|
8
|
+
private buffer;
|
|
9
|
+
private inCodeBlock;
|
|
10
|
+
private inTable;
|
|
11
|
+
private pendingTableHeader;
|
|
12
|
+
private atLineStart;
|
|
13
|
+
constructor(options?: SpeechSanitizerOptions);
|
|
14
|
+
push(text: string, final?: boolean): string;
|
|
15
|
+
private takeLine;
|
|
16
|
+
private takePartialText;
|
|
17
|
+
private skipCodeBlock;
|
|
18
|
+
private shouldHoldPartialLine;
|
|
19
|
+
private processLine;
|
|
20
|
+
private processPlainLine;
|
|
21
|
+
}
|
|
22
|
+
export declare function createSpeechSanitizer(options?: SpeechSanitizerOptions): SpeechSanitizer;
|
|
23
|
+
export declare function sanitizeSpeechText(text: string, options?: SpeechSanitizerOptions): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type VoiceChoice = {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
accent: "American English" | "British English";
|
|
5
|
+
gender: "Female" | "Male";
|
|
6
|
+
};
|
|
7
|
+
export declare const VOICE_CHOICES: VoiceChoice[];
|
|
8
|
+
export declare function isSelectableVoice(value: unknown): value is string;
|
|
9
|
+
export declare function createVoiceSelectionController(configuredVoice: unknown, defaultVoice: string, storage: {
|
|
10
|
+
store(key: string, options: {
|
|
11
|
+
initial: {
|
|
12
|
+
voice: string | null;
|
|
13
|
+
};
|
|
14
|
+
}): readonly [
|
|
15
|
+
{
|
|
16
|
+
readonly voice: string | null;
|
|
17
|
+
},
|
|
18
|
+
(mutation: (draft: {
|
|
19
|
+
voice: string | null;
|
|
20
|
+
}) => void) => Promise<void>
|
|
21
|
+
];
|
|
22
|
+
}, onSaveError: (error: unknown) => void): {
|
|
23
|
+
readonly voice: string;
|
|
24
|
+
select(voice: string): boolean;
|
|
25
|
+
flush(): Promise<void>;
|
|
26
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const MIN_VOICE_SPEED = 0.25;
|
|
2
|
+
export declare const MAX_VOICE_SPEED = 5;
|
|
3
|
+
export declare const VOICE_SPEED_STEP = 0.25;
|
|
4
|
+
export declare function isValidVoiceSpeed(value: unknown): value is number;
|
|
5
|
+
export declare function normalizeVoiceSpeed(speed: number): number;
|
|
6
|
+
export declare function formatVoiceSpeed(percent: number): string;
|
|
7
|
+
export declare function createVoiceSpeedController(configuredSpeed: unknown, defaultSpeed: number, storage: {
|
|
8
|
+
store(key: string, options: {
|
|
9
|
+
initial: {
|
|
10
|
+
speed: number | null;
|
|
11
|
+
};
|
|
12
|
+
}): readonly [
|
|
13
|
+
{
|
|
14
|
+
readonly speed: number | null;
|
|
15
|
+
},
|
|
16
|
+
(mutation: (draft: {
|
|
17
|
+
speed: number | null;
|
|
18
|
+
}) => void) => Promise<void>
|
|
19
|
+
];
|
|
20
|
+
}, onSaveError: (error: unknown) => void): {
|
|
21
|
+
readonly speed: number;
|
|
22
|
+
readonly percent: number;
|
|
23
|
+
adjust(direction: -1 | 1): number;
|
|
24
|
+
flush(): Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
export declare function adjustVoiceSpeed(speed: number, direction: -1 | 1): number;
|
|
27
|
+
export declare function scalePauseForSpeed(pauseMs: number, speed: number): number;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PreparedChunk, VoiceConfig } from "./voice-types.js";
|
|
2
|
+
import { type SpeechSanitizerOptions } from "./voice-sanitize.js";
|
|
3
|
+
export declare function prepareSanitizedSpeechText(text: string, maxTextLength: number): string;
|
|
4
|
+
export declare function prepareSpeechText(text: string, maxTextLength: number, options?: SpeechSanitizerOptions): string;
|
|
5
|
+
export declare function drainStreamChunks(text: string, config: VoiceConfig, final?: boolean): {
|
|
6
|
+
chunks: PreparedChunk[];
|
|
7
|
+
rest: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function splitPlaybackText(text: string, config: VoiceConfig): PreparedChunk[];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export type DevicePreference = "auto" | "cpu" | "gpu" | "cuda" | "dml" | "wasm" | "webgpu";
|
|
2
|
+
export type KokoroRuntimeDevice = "cpu" | "wasm" | "webgpu";
|
|
3
|
+
export type KokoroDType = "fp32" | "fp16" | "q4" | "q4f16" | "q8";
|
|
4
|
+
export type VoiceBlock = "reason" | "message" | "idle";
|
|
5
|
+
export type VoicePluginOptions = {
|
|
6
|
+
voice?: unknown;
|
|
7
|
+
speed?: unknown;
|
|
8
|
+
device?: unknown;
|
|
9
|
+
dtype?: unknown;
|
|
10
|
+
model?: unknown;
|
|
11
|
+
cacheDir?: unknown;
|
|
12
|
+
audioPlayer?: unknown;
|
|
13
|
+
audioPlayerArgs?: unknown;
|
|
14
|
+
speakResponses?: unknown;
|
|
15
|
+
speakSubagentResponses?: unknown;
|
|
16
|
+
speakOnIdle?: unknown;
|
|
17
|
+
speakQuestions?: unknown;
|
|
18
|
+
idleAnnouncement?: unknown;
|
|
19
|
+
speechBlocks?: unknown;
|
|
20
|
+
maxSpeechChunkChars?: unknown;
|
|
21
|
+
streamFlushChars?: unknown;
|
|
22
|
+
maxSpeechChars?: unknown;
|
|
23
|
+
fileExtensions?: unknown;
|
|
24
|
+
trimSilenceThreshold?: unknown;
|
|
25
|
+
leadingAudioPadMs?: unknown;
|
|
26
|
+
normalPauseMs?: unknown;
|
|
27
|
+
sentencePauseMs?: unknown;
|
|
28
|
+
ttsServiceCommand?: unknown;
|
|
29
|
+
ttsServiceArgs?: unknown;
|
|
30
|
+
shortcuts?: unknown;
|
|
31
|
+
};
|
|
32
|
+
export type ShortcutConfig = {
|
|
33
|
+
history: string;
|
|
34
|
+
pause: string;
|
|
35
|
+
skipLatest: string;
|
|
36
|
+
toggle: string;
|
|
37
|
+
};
|
|
38
|
+
export type VoiceConfig = {
|
|
39
|
+
voice: string;
|
|
40
|
+
speed: number;
|
|
41
|
+
device: DevicePreference;
|
|
42
|
+
dtype: KokoroDType;
|
|
43
|
+
model: string;
|
|
44
|
+
cacheDir?: string;
|
|
45
|
+
audioPlayer: string;
|
|
46
|
+
audioPlayerArgs: string[];
|
|
47
|
+
speakResponses: boolean;
|
|
48
|
+
speakSubagentResponses: boolean;
|
|
49
|
+
speakOnIdle: boolean;
|
|
50
|
+
speakQuestions: boolean;
|
|
51
|
+
idleAnnouncement: string;
|
|
52
|
+
speechBlocks: VoiceBlock[];
|
|
53
|
+
maxSpeechChunkChars: number;
|
|
54
|
+
streamFlushChars: number;
|
|
55
|
+
maxSpeechChars: number;
|
|
56
|
+
fileExtensions: string[];
|
|
57
|
+
trimSilenceThreshold: number;
|
|
58
|
+
leadingAudioPadMs: number;
|
|
59
|
+
normalPauseMs: number;
|
|
60
|
+
sentencePauseMs: number;
|
|
61
|
+
ttsServiceCommand?: string;
|
|
62
|
+
ttsServiceArgs?: string[];
|
|
63
|
+
shortcuts: ShortcutConfig;
|
|
64
|
+
};
|
|
65
|
+
export type VoiceState = {
|
|
66
|
+
enabled: boolean;
|
|
67
|
+
paused: boolean;
|
|
68
|
+
busy: boolean;
|
|
69
|
+
generating: boolean;
|
|
70
|
+
playing: boolean;
|
|
71
|
+
backend: string;
|
|
72
|
+
device: string;
|
|
73
|
+
error?: string;
|
|
74
|
+
};
|
|
75
|
+
export type SpeechSource = "stream" | "latest" | "history" | "idle" | "question" | "preview";
|
|
76
|
+
export type PreparedChunk = {
|
|
77
|
+
text: string;
|
|
78
|
+
pauseMs: number;
|
|
79
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,74 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scotteza/opencode-spoken-replies",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Local Kokoro text-to-speech for OpenCode assistant replies",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"opencode",
|
|
7
|
+
"opencode-plugin",
|
|
8
|
+
"tts",
|
|
9
|
+
"voice",
|
|
10
|
+
"kokoro",
|
|
11
|
+
"tui",
|
|
12
|
+
"spoken-replies"
|
|
13
|
+
],
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"exports": {
|
|
21
|
+
"./server": {
|
|
22
|
+
"types": "./dist/server-plugin.d.ts",
|
|
23
|
+
"import": "./dist/server-plugin.js"
|
|
24
|
+
},
|
|
25
|
+
"./tui": {
|
|
26
|
+
"types": "./dist/tui-plugin.d.ts",
|
|
27
|
+
"import": "./dist/tui-plugin.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc -p tsconfig.json && bun run ./scripts/build-tui.ts",
|
|
32
|
+
"test": "bun test",
|
|
33
|
+
"test:audio": "bun ./scripts/test-audio.mjs",
|
|
34
|
+
"publish:npm": "npm publish --access public",
|
|
35
|
+
"prepublishOnly": "npm run build && npm test"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=20.9.0",
|
|
42
|
+
"opencode": "^2.3.2"
|
|
43
|
+
},
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "git+https://github.com/scotteza/opencode-spoken-replies.git"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/scotteza/opencode-spoken-replies",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/scotteza/opencode-spoken-replies/issues"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@huggingface/transformers": "^3.5.1",
|
|
55
|
+
"@opencode/client": "2.3.2",
|
|
56
|
+
"@opencode/plugin": "2.3.2",
|
|
57
|
+
"@opencode/theme": "2.3.2",
|
|
58
|
+
"@opentui/core": "0.8.4",
|
|
59
|
+
"@opentui/solid": "0.8.4",
|
|
60
|
+
"kokoro-js": "^1.2.1",
|
|
61
|
+
"solid-js": "1.9.17"
|
|
62
|
+
},
|
|
63
|
+
"overrides": {
|
|
64
|
+
"@huggingface/transformers": {
|
|
65
|
+
"sharp": "0.35.5"
|
|
66
|
+
},
|
|
67
|
+
"glob@>=9 <14.0.2": "14.0.6",
|
|
68
|
+
"minimatch@>=7 <11.0.1": "11.0.9"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@types/node": "^25.6.0",
|
|
72
|
+
"typescript": "^6.0.3"
|
|
73
|
+
}
|
|
74
|
+
}
|