opencode-speaker 1.0.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 +21 -0
- package/README.md +281 -0
- package/dist/api.d.ts +14 -0
- package/dist/api.js +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +1326 -0
- package/package.json +91 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 herquiloide
|
|
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,281 @@
|
|
|
1
|
+
# opencode-speaker
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/opencode-speaker)
|
|
4
|
+
[](https://github.com/herquiloidehele/opencode-speaker/actions/workflows/ci.yml)
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
|
|
7
|
+
A speaker plugin for [opencode](https://opencode.ai) that **speaks agent activity out loud** through pluggable text-to-speech backends.
|
|
8
|
+
|
|
9
|
+
Hear what your agent is doing while you work on something else — session summaries, errors, permission requests, and todo completions, narrated by an LLM and spoken by a TTS model.
|
|
10
|
+
|
|
11
|
+
Supports **OpenAI** (default) and **ElevenLabs** for TTS, with **OpenAI** or **Anthropic** for the LLM narrator. Powered by the [Vercel AI SDK](https://sdk.vercel.ai).
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- **Node.js ≥ 20**
|
|
18
|
+
- An API key for your chosen provider (OpenAI by default; ElevenLabs and/or Anthropic optional)
|
|
19
|
+
- On Linux, a TTS/audio backend — see [Troubleshooting](#troubleshooting)
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
### 1. Add the plugin to `opencode.json`
|
|
26
|
+
|
|
27
|
+
Your global opencode config file is usually located at `~/.config/opencode/opencode.json`.
|
|
28
|
+
If you use a project-local opencode config, add the same plugin entry there instead.
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"$schema": "https://opencode.ai/config.json",
|
|
33
|
+
"plugin": ["opencode-speaker"]
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 2. Set your OpenAI API key
|
|
38
|
+
|
|
39
|
+
For the current terminal session:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
export OPENAI_API_KEY=sk-...
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
To make it available every time you open a terminal, add it to your shell startup file:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# zsh, macOS default
|
|
49
|
+
echo 'export OPENAI_API_KEY=sk-...' >> ~/.zshrc
|
|
50
|
+
|
|
51
|
+
# bash
|
|
52
|
+
echo 'export OPENAI_API_KEY=sk-...' >> ~/.bashrc
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
If you use fish:
|
|
56
|
+
|
|
57
|
+
```fish
|
|
58
|
+
set -Ux OPENAI_API_KEY sk-...
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Restart your terminal after adding the variable, or run `source ~/.zshrc` / `source ~/.bashrc` for the current session.
|
|
62
|
+
|
|
63
|
+
That's it. Start opencode and you'll hear a short greeting confirming the plugin is ready.
|
|
64
|
+
|
|
65
|
+
By default, the plugin uses:
|
|
66
|
+
- TTS model: `openai/gpt-4o-mini-tts`
|
|
67
|
+
- Narrator model: `openai/gpt-4.1-mini`
|
|
68
|
+
|
|
69
|
+
And out of the box, you'll hear:
|
|
70
|
+
- Session starts, idle summaries, errors, and compactions
|
|
71
|
+
- Permission requests and replies
|
|
72
|
+
- Tool starts and finishes
|
|
73
|
+
- File edits and executed commands
|
|
74
|
+
- Reasoning deltas while the assistant is thinking
|
|
75
|
+
- Todo item completions and “all todos complete” summaries
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Using ElevenLabs instead
|
|
80
|
+
|
|
81
|
+
Configure the plugin using the **tuple form** in the `plugin` array (per-plugin config goes as the second tuple element — not as a top-level key):
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"$schema": "https://opencode.ai/config.json",
|
|
86
|
+
"plugin": [
|
|
87
|
+
["opencode-speaker", {
|
|
88
|
+
"tts": {
|
|
89
|
+
"model": "elevenlabs/eleven_turbo_v2_5",
|
|
90
|
+
"voice": "EXAVITQu4vr4xnSDxMaL"
|
|
91
|
+
}
|
|
92
|
+
}]
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Then set your API key:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
export ELEVENLABS_API_KEY=...
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The `voice` field takes an ElevenLabs voice ID.
|
|
104
|
+
|
|
105
|
+
> **Note:** The narrator (LLM summarizer) is separate from TTS. You can mix and match — e.g., narrate with Anthropic, speak with ElevenLabs.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Configuration
|
|
110
|
+
|
|
111
|
+
All options go inside the tuple's second element: `["opencode-speaker", { ... }]`.
|
|
112
|
+
|
|
113
|
+
### Full example
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"plugin": [
|
|
118
|
+
["opencode-speaker", {
|
|
119
|
+
"greeting": "opencode speaker ready",
|
|
120
|
+
"tts": {
|
|
121
|
+
"model": "openai/gpt-4o-mini-tts",
|
|
122
|
+
"voice": "nova",
|
|
123
|
+
"rate": 1.0
|
|
124
|
+
},
|
|
125
|
+
"narrator": {
|
|
126
|
+
"model": "openai/gpt-4.1-mini",
|
|
127
|
+
"timeoutMs": 5000,
|
|
128
|
+
"minIntervalMs": 3000
|
|
129
|
+
},
|
|
130
|
+
"events": {
|
|
131
|
+
"tool.execute.before": { "enabled": true }
|
|
132
|
+
}
|
|
133
|
+
}]
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### TTS providers
|
|
139
|
+
|
|
140
|
+
| Provider | Model slug example | Voices | Env var |
|
|
141
|
+
|---|---|---|---|
|
|
142
|
+
| OpenAI (default) | `openai/gpt-4o-mini-tts`, `openai/tts-1`, `openai/tts-1-hd` | `alloy`, `ash`, `coral`, `echo`, `fable`, `onyx`, `nova`, `sage`, `shimmer` | `OPENAI_API_KEY` |
|
|
143
|
+
| ElevenLabs | `elevenlabs/eleven_turbo_v2_5` | ElevenLabs voice ID | `ELEVENLABS_API_KEY` |
|
|
144
|
+
|
|
145
|
+
### Narrator (LLM) providers
|
|
146
|
+
|
|
147
|
+
| Provider | Model slug example | Env var |
|
|
148
|
+
|---|---|---|
|
|
149
|
+
| OpenAI (default) | `openai/gpt-4.1-mini` | `OPENAI_API_KEY` |
|
|
150
|
+
| Anthropic | `anthropic/claude-haiku-4` | `ANTHROPIC_API_KEY` |
|
|
151
|
+
|
|
152
|
+
The plugin resolves `provider/model` slugs internally — no imports needed.
|
|
153
|
+
|
|
154
|
+
### Events
|
|
155
|
+
|
|
156
|
+
Each event is independently configurable.
|
|
157
|
+
|
|
158
|
+
### Verbosity
|
|
159
|
+
|
|
160
|
+
Use `verbosity` to choose a default event profile, then override individual events as needed.
|
|
161
|
+
|
|
162
|
+
| Value | Behavior |
|
|
163
|
+
|---|---|
|
|
164
|
+
| `minimal` | Speaks only session idle summaries, session errors, permission requests, and all-todos-complete summaries. |
|
|
165
|
+
| `normal` | Current default event profile. |
|
|
166
|
+
| `verbose` | Same as `normal` today; reserved for future high-detail defaults while preserving a stable option name. |
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"plugin": [
|
|
171
|
+
["opencode-speaker", {
|
|
172
|
+
"verbosity": "minimal",
|
|
173
|
+
"events": {
|
|
174
|
+
"tool.execute.before": { "enabled": true }
|
|
175
|
+
}
|
|
176
|
+
}]
|
|
177
|
+
]
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
| Event | Default | Mode |
|
|
182
|
+
|---|---|---|
|
|
183
|
+
| `session.idle` | on | narrate (LLM summary) |
|
|
184
|
+
| `session.error` | on | template, urgent |
|
|
185
|
+
| `session.compacted` | on | template |
|
|
186
|
+
| `session.created` | on | template |
|
|
187
|
+
| `permission.asked` | on | template, urgent |
|
|
188
|
+
| `permission.replied` | on | template |
|
|
189
|
+
| `tool.execute.before` | on | template, chatty |
|
|
190
|
+
| `tool.execute.after` | on | template, chatty |
|
|
191
|
+
| `file.edited` | on | template, chatty |
|
|
192
|
+
| `command.executed` | on | template |
|
|
193
|
+
| `message.reasoning.delta` | on | verbatim, chatty |
|
|
194
|
+
| `message.text.delta` | off | verbatim, chatty |
|
|
195
|
+
| `message.updated` | off | verbatim |
|
|
196
|
+
| `todo.completed.item` | on | template, chatty |
|
|
197
|
+
| `todo.completed.all` | on | narrate |
|
|
198
|
+
|
|
199
|
+
Override per event:
|
|
200
|
+
|
|
201
|
+
```json
|
|
202
|
+
{
|
|
203
|
+
"events": {
|
|
204
|
+
"tool.execute.before": { "enabled": true, "mode": "template" }
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Modes:
|
|
210
|
+
- `template` — fixed phrasing (fast, no LLM)
|
|
211
|
+
- `narrate` — LLM-generated summary (concise but covers what happened, blockers, next steps)
|
|
212
|
+
- `verbatim` — speak the raw text as-is
|
|
213
|
+
|
|
214
|
+
The narrator is rate-limited by `minIntervalMs` and falls back to a template if the call fails or is throttled.
|
|
215
|
+
|
|
216
|
+
### Greeting
|
|
217
|
+
|
|
218
|
+
A short startup line, spoken once when the plugin is ready. Default: `"Welcome to OpenCode Speaker!"`.
|
|
219
|
+
|
|
220
|
+
```json
|
|
221
|
+
{ "greeting": "welcome back" }
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Set to `""` to disable. Skipped automatically when `startMuted: true` or `OPENCODE_VOICE_MUTE=1`.
|
|
225
|
+
|
|
226
|
+
## Custom providers
|
|
227
|
+
|
|
228
|
+
Runtime provider selection is currently built in. TTS slugs route `openai/*` and
|
|
229
|
+
`elevenlabs/*`; narrator slugs route `openai/*` and `anthropic/*`.
|
|
230
|
+
|
|
231
|
+
The `opencode-speaker/api` entrypoint exports provider-related TypeScript types
|
|
232
|
+
for integrations, but it does not register custom providers at runtime. To add a
|
|
233
|
+
provider today, fork the model resolver in `src/ai-sdk/models.ts` or open an
|
|
234
|
+
issue.
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Troubleshooting
|
|
239
|
+
|
|
240
|
+
**No audio on Linux:** install `speech-dispatcher` (`sudo apt install speech-dispatcher`) or `espeak`. For cloud-provider audio playback, install `pulseaudio-utils` (`paplay`), `alsa-utils` (`aplay`), or `ffmpeg` (`ffplay`).
|
|
241
|
+
|
|
242
|
+
**Windows blocked by execution policy:** run PowerShell once with `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`.
|
|
243
|
+
|
|
244
|
+
**Plugin disabled with a toast on startup:** the toast carries a short summary (invalid config, missing API key, TTS init failure). The full structured detail is in opencode's log file — `opencode-speaker` errors are logged at `error` / `warn` level.
|
|
245
|
+
|
|
246
|
+
**`Unrecognized key: voice` schema error:** you put options at the top level. Use the tuple form: `"plugin": [["opencode-speaker", { ... }]]`, not `"voice": { ... }`.
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## Development
|
|
251
|
+
|
|
252
|
+
Six runnable demo scripts exercise each feature without booting opencode (all use `tsx`):
|
|
253
|
+
|
|
254
|
+
| Script | Validates |
|
|
255
|
+
|---|---|
|
|
256
|
+
| `npm run demo:say -- "text"` | Synthesis + playback. Override TTS with `--model=elevenlabs/eleven_turbo_v2_5 --voice=<id>`. |
|
|
257
|
+
| `npm run demo:queue` | Speech queue priority + dedup behavior. |
|
|
258
|
+
| `npm run demo:event -- <event.type>` | Full event-to-audio pipeline. E.g. `session.idle`, `permission.asked --tool=write`. |
|
|
259
|
+
| `npm run demo:narrator -- --assistant-text="..." --tool=bash` | LLM narrator handler. |
|
|
260
|
+
| `npm run demo:config -- '{...}'` or `--file=path.json` | Validate a config block against the Zod schema. |
|
|
261
|
+
| `npm run demo:greet` | Startup greeting via the full plugin. |
|
|
262
|
+
|
|
263
|
+
Standard commands:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
npm test # full unit + integration suite
|
|
267
|
+
npm run typecheck # TypeScript validation
|
|
268
|
+
npm run build # produce dist/
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
To restart opencode against a local build:
|
|
272
|
+
|
|
273
|
+
```bash
|
|
274
|
+
rm -rf ~/.cache/opencode/node_modules/opencode-speaker && npm run build
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## License
|
|
280
|
+
|
|
281
|
+
MIT.
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface SynthesisOptions {
|
|
2
|
+
voice?: string;
|
|
3
|
+
rate?: number;
|
|
4
|
+
}
|
|
5
|
+
interface SynthesisResult {
|
|
6
|
+
audio: Buffer;
|
|
7
|
+
contentType: string;
|
|
8
|
+
}
|
|
9
|
+
interface TTSProvider {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
synthesize(text: string, opts: SynthesisOptions, signal: AbortSignal): Promise<SynthesisResult>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type { SynthesisOptions, SynthesisResult, TTSProvider };
|
package/dist/api.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFtdLAogICJzb3VyY2VzQ29udGVudCI6IFtdLAogICJtYXBwaW5ncyI6ICIiLAogICJuYW1lcyI6IFtdCn0K
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type PluginCtx = {
|
|
2
|
+
client: {
|
|
3
|
+
app: {
|
|
4
|
+
log: (...args: any[]) => Promise<unknown>;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
directory: string;
|
|
8
|
+
worktree?: string;
|
|
9
|
+
project?: unknown;
|
|
10
|
+
$: unknown;
|
|
11
|
+
};
|
|
12
|
+
type PluginOptions = Record<string, unknown> | undefined;
|
|
13
|
+
declare const OpencodeSpeaker: (ctx: PluginCtx, options?: PluginOptions) => Promise<{
|
|
14
|
+
event?: undefined;
|
|
15
|
+
} | {
|
|
16
|
+
event: ({ event, }: {
|
|
17
|
+
event: {
|
|
18
|
+
type: string;
|
|
19
|
+
[k: string]: unknown;
|
|
20
|
+
};
|
|
21
|
+
}) => Promise<void>;
|
|
22
|
+
}>;
|
|
23
|
+
|
|
24
|
+
export { OpencodeSpeaker, OpencodeSpeaker as default };
|