opencode-smart-voice-notify 1.0.7 → 1.0.8
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 +242 -234
- package/example.config.jsonc +2 -2
- package/index.js +30 -3
- package/package.json +3 -2
- package/util/tts.js +43 -7
package/README.md
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
<!-- Dynamic Header -->
|
|
2
|
+
<img width="100%" src="https://capsule-render.vercel.app/api?type=waving&color=0:667eea,100:764ba2&height=120§ion=header"/>
|
|
3
|
+
|
|
4
|
+
# OpenCode Smart Voice Notify
|
|
5
|
+
|
|
6
|
+
> **Disclaimer**: This project is not built by the OpenCode team and is not affiliated with [OpenCode](https://opencode.ai) in any way. It is an independent community plugin.
|
|
7
|
+
|
|
8
|
+
A smart voice notification plugin for [OpenCode](https://opencode.ai) with **multiple TTS engines** and an intelligent reminder system.
|
|
9
|
+
|
|
10
|
+
<img width="1456" height="720" alt="image" src="https://github.com/user-attachments/assets/52ccf357-2548-400b-a346-6362f2fc3180" />
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
### Smart TTS Engine Selection
|
|
16
|
+
The plugin automatically tries multiple TTS engines in order, falling back if one fails:
|
|
17
|
+
|
|
12
18
|
1. **ElevenLabs** (Online) - High-quality, anime-like voices with natural expression
|
|
13
|
-
2. **Edge TTS** (Free) - Microsoft's neural voices, no
|
|
19
|
+
2. **Edge TTS** (Free) - Microsoft's neural voices, native Node.js implementation (no Python required)
|
|
14
20
|
3. **Windows SAPI** (Offline) - Built-in Windows speech synthesis
|
|
15
21
|
4. **Local Sound Files** (Fallback) - Plays bundled MP3 files if all TTS fails
|
|
16
22
|
|
|
@@ -25,185 +31,187 @@ The plugin automatically tries multiple TTS engines in order, falling back if on
|
|
|
25
31
|
- Follow-up reminders with exponential backoff
|
|
26
32
|
- Automatic cancellation when user responds
|
|
27
33
|
- Per-notification type delays (permission requests are more urgent)
|
|
34
|
+
- **Smart Quota Handling**: Automatically falls back to free Edge TTS if ElevenLabs quota is exceeded
|
|
28
35
|
|
|
29
36
|
### System Integration
|
|
37
|
+
- **Native Edge TTS**: No external dependencies (Python/pip) required
|
|
30
38
|
- Wake monitor from sleep before notifying
|
|
31
39
|
- Auto-boost volume if too low
|
|
32
40
|
- TUI toast notifications
|
|
33
41
|
- Cross-platform support (Windows, macOS, Linux)
|
|
34
|
-
|
|
35
|
-
## Installation
|
|
36
|
-
|
|
37
|
-
### Option 1: From npm (Recommended)
|
|
38
|
-
|
|
39
|
-
Add to your OpenCode config file (`~/.config/opencode/opencode.json`):
|
|
40
|
-
|
|
41
|
-
```json
|
|
42
|
-
{
|
|
43
|
-
"$schema": "https://opencode.ai/config.json",
|
|
44
|
-
"plugin": ["opencode-smart-voice-notify@latest"]
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Option 2: From GitHub
|
|
49
|
-
|
|
50
|
-
```json
|
|
51
|
-
{
|
|
52
|
-
"$schema": "https://opencode.ai/config.json",
|
|
53
|
-
"plugin": ["github:MasuRii/opencode-smart-voice-notify"]
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Option 3: Local Development
|
|
58
|
-
|
|
59
|
-
1. Clone the repository:
|
|
60
|
-
```bash
|
|
61
|
-
git clone https://github.com/MasuRii/opencode-smart-voice-notify.git
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
2. Reference the local path in your config:
|
|
65
|
-
```json
|
|
66
|
-
{
|
|
67
|
-
"plugin": ["file:///path/to/opencode-smart-voice-notify"]
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Configuration
|
|
72
|
-
|
|
73
|
-
### Automatic Setup
|
|
74
|
-
|
|
75
|
-
When you first run OpenCode with this plugin installed, it will **automatically create**:
|
|
76
|
-
|
|
77
|
-
1. **`~/.config/opencode/smart-voice-notify.jsonc`** - A comprehensive configuration file with all available options fully documented.
|
|
78
|
-
2. **`~/.config/opencode/assets/*.mp3`** - Bundled notification sound files.
|
|
79
|
-
|
|
80
|
-
The auto-generated configuration includes all advanced settings, message arrays, and engine options, so you don't have to refer back to the documentation for available settings.
|
|
81
|
-
|
|
82
|
-
### Manual Configuration
|
|
83
|
-
|
|
84
|
-
If you prefer to create the config manually, add a `smart-voice-notify.jsonc` file in your OpenCode config directory (`~/.config/opencode/`):
|
|
85
|
-
|
|
86
|
-
```jsonc
|
|
87
|
-
{
|
|
88
|
-
// ============================================================
|
|
89
|
-
// NOTIFICATION MODE SETTINGS (Smart Notification System)
|
|
90
|
-
// ============================================================
|
|
91
|
-
// Controls how notifications are delivered:
|
|
92
|
-
// 'sound-first' - Play sound immediately, TTS reminder after delay (RECOMMENDED)
|
|
93
|
-
// 'tts-first' - Speak TTS immediately, no sound
|
|
94
|
-
// 'both' - Play sound AND speak TTS immediately
|
|
95
|
-
// 'sound-only' - Only play sound, no TTS at all
|
|
96
|
-
"notificationMode": "sound-first",
|
|
97
|
-
|
|
98
|
-
// ============================================================
|
|
99
|
-
// TTS REMINDER SETTINGS (When user doesn't respond to sound)
|
|
100
|
-
// ============================================================
|
|
101
|
-
|
|
102
|
-
// Enable TTS reminder if user doesn't respond after sound notification
|
|
103
|
-
"enableTTSReminder": true,
|
|
104
|
-
|
|
105
|
-
// Delay (in seconds) before TTS reminder fires
|
|
106
|
-
"ttsReminderDelaySeconds": 30, // Global default
|
|
107
|
-
"idleReminderDelaySeconds": 30, // For task completion notifications
|
|
108
|
-
"permissionReminderDelaySeconds": 20, // For permission requests (more urgent)
|
|
109
|
-
|
|
110
|
-
// Follow-up reminders if user STILL doesn't respond after first TTS
|
|
111
|
-
"enableFollowUpReminders": true,
|
|
112
|
-
"maxFollowUpReminders": 3, // Max number of follow-up TTS reminders
|
|
113
|
-
"reminderBackoffMultiplier": 1.5, // Each follow-up waits longer (30s, 45s, 67s...)
|
|
114
|
-
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
### Option 1: From npm (Recommended)
|
|
46
|
+
|
|
47
|
+
Add to your OpenCode config file (`~/.config/opencode/opencode.json`):
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"$schema": "https://opencode.ai/config.json",
|
|
52
|
+
"plugin": ["opencode-smart-voice-notify@latest"]
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Option 2: From GitHub
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"$schema": "https://opencode.ai/config.json",
|
|
61
|
+
"plugin": ["github:MasuRii/opencode-smart-voice-notify"]
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Option 3: Local Development
|
|
66
|
+
|
|
67
|
+
1. Clone the repository:
|
|
68
|
+
```bash
|
|
69
|
+
git clone https://github.com/MasuRii/opencode-smart-voice-notify.git
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
2. Reference the local path in your config:
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"plugin": ["file:///path/to/opencode-smart-voice-notify"]
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Configuration
|
|
80
|
+
|
|
81
|
+
### Automatic Setup
|
|
82
|
+
|
|
83
|
+
When you first run OpenCode with this plugin installed, it will **automatically create**:
|
|
84
|
+
|
|
85
|
+
1. **`~/.config/opencode/smart-voice-notify.jsonc`** - A comprehensive configuration file with all available options fully documented.
|
|
86
|
+
2. **`~/.config/opencode/assets/*.mp3`** - Bundled notification sound files.
|
|
87
|
+
|
|
88
|
+
The auto-generated configuration includes all advanced settings, message arrays, and engine options, so you don't have to refer back to the documentation for available settings.
|
|
89
|
+
|
|
90
|
+
### Manual Configuration
|
|
91
|
+
|
|
92
|
+
If you prefer to create the config manually, add a `smart-voice-notify.jsonc` file in your OpenCode config directory (`~/.config/opencode/`):
|
|
93
|
+
|
|
94
|
+
```jsonc
|
|
95
|
+
{
|
|
96
|
+
// ============================================================
|
|
97
|
+
// NOTIFICATION MODE SETTINGS (Smart Notification System)
|
|
98
|
+
// ============================================================
|
|
99
|
+
// Controls how notifications are delivered:
|
|
100
|
+
// 'sound-first' - Play sound immediately, TTS reminder after delay (RECOMMENDED)
|
|
101
|
+
// 'tts-first' - Speak TTS immediately, no sound
|
|
102
|
+
// 'both' - Play sound AND speak TTS immediately
|
|
103
|
+
// 'sound-only' - Only play sound, no TTS at all
|
|
104
|
+
"notificationMode": "sound-first",
|
|
105
|
+
|
|
106
|
+
// ============================================================
|
|
107
|
+
// TTS REMINDER SETTINGS (When user doesn't respond to sound)
|
|
108
|
+
// ============================================================
|
|
109
|
+
|
|
110
|
+
// Enable TTS reminder if user doesn't respond after sound notification
|
|
111
|
+
"enableTTSReminder": true,
|
|
112
|
+
|
|
113
|
+
// Delay (in seconds) before TTS reminder fires
|
|
114
|
+
"ttsReminderDelaySeconds": 30, // Global default
|
|
115
|
+
"idleReminderDelaySeconds": 30, // For task completion notifications
|
|
116
|
+
"permissionReminderDelaySeconds": 20, // For permission requests (more urgent)
|
|
117
|
+
|
|
118
|
+
// Follow-up reminders if user STILL doesn't respond after first TTS
|
|
119
|
+
"enableFollowUpReminders": true,
|
|
120
|
+
"maxFollowUpReminders": 3, // Max number of follow-up TTS reminders
|
|
121
|
+
"reminderBackoffMultiplier": 1.5, // Each follow-up waits longer (30s, 45s, 67s...)
|
|
122
|
+
|
|
115
123
|
// ============================================================
|
|
116
124
|
// TTS ENGINE SELECTION
|
|
117
125
|
// ============================================================
|
|
118
126
|
// 'elevenlabs' - Best quality, anime-like voices (requires API key)
|
|
119
|
-
// 'edge' - Good quality neural voices (
|
|
127
|
+
// 'edge' - Good quality neural voices (Free, Native Node.js implementation)
|
|
120
128
|
// 'sapi' - Windows built-in voices (free, offline)
|
|
121
129
|
"ttsEngine": "edge",
|
|
122
130
|
"enableTTS": true,
|
|
123
|
-
|
|
124
|
-
// ============================================================
|
|
125
|
-
// ELEVENLABS SETTINGS (Best Quality - Anime-like Voices)
|
|
126
|
-
// ============================================================
|
|
127
|
-
// Get your API key from: https://elevenlabs.io/app/settings/api-keys
|
|
128
|
-
// "elevenLabsApiKey": "YOUR_API_KEY_HERE",
|
|
129
|
-
"elevenLabsVoiceId": "cgSgspJ2msm6clMCkdW9",
|
|
130
|
-
"elevenLabsModel": "eleven_turbo_v2_5",
|
|
131
|
-
"elevenLabsStability": 0.5,
|
|
132
|
-
"elevenLabsSimilarity": 0.75,
|
|
133
|
-
"elevenLabsStyle": 0.5,
|
|
134
|
-
|
|
135
|
-
// ============================================================
|
|
136
|
-
// EDGE TTS SETTINGS (Free Neural Voices - Default Engine)
|
|
137
|
-
// ============================================================
|
|
138
|
-
"edgeVoice": "en-US-AnaNeural",
|
|
139
|
-
"edgePitch": "+50Hz",
|
|
140
|
-
"edgeRate": "+10%",
|
|
141
|
-
|
|
142
|
-
// ============================================================
|
|
143
|
-
// SAPI SETTINGS (Windows Built-in - Last Resort Fallback)
|
|
144
|
-
// ============================================================
|
|
145
|
-
"sapiVoice": "Microsoft Zira Desktop",
|
|
146
|
-
"sapiRate": -1,
|
|
147
|
-
"sapiPitch": "medium",
|
|
148
|
-
"sapiVolume": "loud",
|
|
149
|
-
|
|
150
|
-
// ============================================================
|
|
151
|
-
// INITIAL TTS MESSAGES (Used immediately or after sound)
|
|
152
|
-
// ============================================================
|
|
153
|
-
"idleTTSMessages": [
|
|
154
|
-
"All done! Your task has been completed successfully.",
|
|
155
|
-
"Hey there! I finished working on your request.",
|
|
156
|
-
"Task complete! Ready for your review whenever you are.",
|
|
157
|
-
"Good news! Everything is done and ready for you.",
|
|
158
|
-
"Finished! Let me know if you need anything else."
|
|
159
|
-
],
|
|
160
|
-
"permissionTTSMessages": [
|
|
161
|
-
"Attention please! I need your permission to continue.",
|
|
162
|
-
"Hey! Quick approval needed to proceed with the task.",
|
|
163
|
-
"Heads up! There is a permission request waiting for you.",
|
|
164
|
-
"Excuse me! I need your authorization before I can continue.",
|
|
165
|
-
"Permission required! Please review and approve when ready."
|
|
166
|
-
],
|
|
167
|
-
|
|
168
|
-
// ============================================================
|
|
169
|
-
// TTS REMINDER MESSAGES (Used after delay if no response)
|
|
170
|
-
// ============================================================
|
|
171
|
-
"idleReminderTTSMessages": [
|
|
172
|
-
"Hey, are you still there? Your task has been waiting for review.",
|
|
173
|
-
"Just a gentle reminder - I finished your request a while ago!",
|
|
174
|
-
"Hello? I completed your task. Please take a look when you can.",
|
|
175
|
-
"Still waiting for you! The work is done and ready for review.",
|
|
176
|
-
"Knock knock! Your completed task is patiently waiting for you."
|
|
177
|
-
],
|
|
178
|
-
"permissionReminderTTSMessages": [
|
|
179
|
-
"Hey! I still need your permission to continue. Please respond!",
|
|
180
|
-
"Reminder: There is a pending permission request. I cannot proceed without you.",
|
|
181
|
-
"Hello? I am waiting for your approval. This is getting urgent!",
|
|
182
|
-
"Please check your screen! I really need your permission to move forward.",
|
|
183
|
-
"Still waiting for authorization! The task is on hold until you respond."
|
|
184
|
-
],
|
|
185
|
-
|
|
186
|
-
// ============================================================
|
|
187
|
-
// SOUND FILES (relative to OpenCode config directory)
|
|
188
|
-
// ============================================================
|
|
189
|
-
"idleSound": "assets/Soft-high-tech-notification-sound-effect.mp3",
|
|
190
|
-
"permissionSound": "assets/Machine-alert-beep-sound-effect.mp3",
|
|
191
|
-
|
|
192
|
-
// ============================================================
|
|
193
|
-
// GENERAL SETTINGS
|
|
194
|
-
// ============================================================
|
|
195
|
-
"wakeMonitor": true,
|
|
196
|
-
"forceVolume": true,
|
|
197
|
-
"volumeThreshold": 50,
|
|
198
|
-
"enableToast": true,
|
|
199
|
-
"enableSound": true,
|
|
200
|
-
"idleThresholdSeconds": 60,
|
|
201
|
-
"debugLog": false
|
|
202
|
-
}
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
See `example.config.jsonc` for more details.
|
|
206
|
-
|
|
131
|
+
|
|
132
|
+
// ============================================================
|
|
133
|
+
// ELEVENLABS SETTINGS (Best Quality - Anime-like Voices)
|
|
134
|
+
// ============================================================
|
|
135
|
+
// Get your API key from: https://elevenlabs.io/app/settings/api-keys
|
|
136
|
+
// "elevenLabsApiKey": "YOUR_API_KEY_HERE",
|
|
137
|
+
"elevenLabsVoiceId": "cgSgspJ2msm6clMCkdW9",
|
|
138
|
+
"elevenLabsModel": "eleven_turbo_v2_5",
|
|
139
|
+
"elevenLabsStability": 0.5,
|
|
140
|
+
"elevenLabsSimilarity": 0.75,
|
|
141
|
+
"elevenLabsStyle": 0.5,
|
|
142
|
+
|
|
143
|
+
// ============================================================
|
|
144
|
+
// EDGE TTS SETTINGS (Free Neural Voices - Default Engine)
|
|
145
|
+
// ============================================================
|
|
146
|
+
"edgeVoice": "en-US-AnaNeural",
|
|
147
|
+
"edgePitch": "+50Hz",
|
|
148
|
+
"edgeRate": "+10%",
|
|
149
|
+
|
|
150
|
+
// ============================================================
|
|
151
|
+
// SAPI SETTINGS (Windows Built-in - Last Resort Fallback)
|
|
152
|
+
// ============================================================
|
|
153
|
+
"sapiVoice": "Microsoft Zira Desktop",
|
|
154
|
+
"sapiRate": -1,
|
|
155
|
+
"sapiPitch": "medium",
|
|
156
|
+
"sapiVolume": "loud",
|
|
157
|
+
|
|
158
|
+
// ============================================================
|
|
159
|
+
// INITIAL TTS MESSAGES (Used immediately or after sound)
|
|
160
|
+
// ============================================================
|
|
161
|
+
"idleTTSMessages": [
|
|
162
|
+
"All done! Your task has been completed successfully.",
|
|
163
|
+
"Hey there! I finished working on your request.",
|
|
164
|
+
"Task complete! Ready for your review whenever you are.",
|
|
165
|
+
"Good news! Everything is done and ready for you.",
|
|
166
|
+
"Finished! Let me know if you need anything else."
|
|
167
|
+
],
|
|
168
|
+
"permissionTTSMessages": [
|
|
169
|
+
"Attention please! I need your permission to continue.",
|
|
170
|
+
"Hey! Quick approval needed to proceed with the task.",
|
|
171
|
+
"Heads up! There is a permission request waiting for you.",
|
|
172
|
+
"Excuse me! I need your authorization before I can continue.",
|
|
173
|
+
"Permission required! Please review and approve when ready."
|
|
174
|
+
],
|
|
175
|
+
|
|
176
|
+
// ============================================================
|
|
177
|
+
// TTS REMINDER MESSAGES (Used after delay if no response)
|
|
178
|
+
// ============================================================
|
|
179
|
+
"idleReminderTTSMessages": [
|
|
180
|
+
"Hey, are you still there? Your task has been waiting for review.",
|
|
181
|
+
"Just a gentle reminder - I finished your request a while ago!",
|
|
182
|
+
"Hello? I completed your task. Please take a look when you can.",
|
|
183
|
+
"Still waiting for you! The work is done and ready for review.",
|
|
184
|
+
"Knock knock! Your completed task is patiently waiting for you."
|
|
185
|
+
],
|
|
186
|
+
"permissionReminderTTSMessages": [
|
|
187
|
+
"Hey! I still need your permission to continue. Please respond!",
|
|
188
|
+
"Reminder: There is a pending permission request. I cannot proceed without you.",
|
|
189
|
+
"Hello? I am waiting for your approval. This is getting urgent!",
|
|
190
|
+
"Please check your screen! I really need your permission to move forward.",
|
|
191
|
+
"Still waiting for authorization! The task is on hold until you respond."
|
|
192
|
+
],
|
|
193
|
+
|
|
194
|
+
// ============================================================
|
|
195
|
+
// SOUND FILES (relative to OpenCode config directory)
|
|
196
|
+
// ============================================================
|
|
197
|
+
"idleSound": "assets/Soft-high-tech-notification-sound-effect.mp3",
|
|
198
|
+
"permissionSound": "assets/Machine-alert-beep-sound-effect.mp3",
|
|
199
|
+
|
|
200
|
+
// ============================================================
|
|
201
|
+
// GENERAL SETTINGS
|
|
202
|
+
// ============================================================
|
|
203
|
+
"wakeMonitor": true,
|
|
204
|
+
"forceVolume": true,
|
|
205
|
+
"volumeThreshold": 50,
|
|
206
|
+
"enableToast": true,
|
|
207
|
+
"enableSound": true,
|
|
208
|
+
"idleThresholdSeconds": 60,
|
|
209
|
+
"debugLog": false
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
See `example.config.jsonc` for more details.
|
|
214
|
+
|
|
207
215
|
## Requirements
|
|
208
216
|
|
|
209
217
|
### For ElevenLabs TTS
|
|
@@ -211,64 +219,64 @@ See `example.config.jsonc` for more details.
|
|
|
211
219
|
- Internet connection
|
|
212
220
|
|
|
213
221
|
### For Edge TTS
|
|
214
|
-
-
|
|
215
|
-
```bash
|
|
216
|
-
pip install edge-tts
|
|
217
|
-
```
|
|
222
|
+
- Internet connection (No external dependencies required)
|
|
218
223
|
|
|
219
224
|
### For Windows SAPI
|
|
220
225
|
- Windows OS (uses built-in System.Speech)
|
|
221
226
|
|
|
222
227
|
### For Sound Playback
|
|
223
|
-
- **Windows**: Built-in (uses Windows Media Player)
|
|
224
|
-
- **macOS**: Built-in (`afplay`)
|
|
225
|
-
- **Linux**: `paplay` or `aplay`
|
|
226
|
-
|
|
227
|
-
## Events Handled
|
|
228
|
-
|
|
229
|
-
| Event | Action |
|
|
230
|
-
|-------|--------|
|
|
231
|
-
| `session.idle` | Agent finished working - notify user |
|
|
232
|
-
| `permission.updated` | Permission request - alert user |
|
|
233
|
-
| `permission.replied` | User responded - cancel pending reminders |
|
|
234
|
-
| `message.updated` | New user message - cancel pending reminders |
|
|
235
|
-
| `session.created` | New session - reset state |
|
|
236
|
-
|
|
237
|
-
## Development
|
|
238
|
-
|
|
239
|
-
To develop on this plugin locally:
|
|
240
|
-
|
|
241
|
-
1. Clone the repository:
|
|
242
|
-
```bash
|
|
243
|
-
git clone https://github.com/MasuRii/opencode-smart-voice-notify.git
|
|
244
|
-
cd opencode-smart-voice-notify
|
|
245
|
-
bun install # or npm install
|
|
246
|
-
```
|
|
247
|
-
|
|
248
|
-
2. Link to your OpenCode config:
|
|
249
|
-
```json
|
|
250
|
-
{
|
|
251
|
-
"plugin": ["file:///absolute/path/to/opencode-smart-voice-notify"]
|
|
252
|
-
}
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
## Updating
|
|
256
|
-
|
|
257
|
-
OpenCode does not automatically update plugins. To update to the latest version:
|
|
258
|
-
|
|
259
|
-
```bash
|
|
260
|
-
# Clear the cached plugin
|
|
261
|
-
rm -rf ~/.cache/opencode/node_modules/opencode-smart-voice-notify
|
|
262
|
-
|
|
263
|
-
# Run OpenCode to trigger a fresh install
|
|
264
|
-
opencode
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
## License
|
|
268
|
-
|
|
269
|
-
MIT
|
|
270
|
-
|
|
271
|
-
## Support
|
|
272
|
-
|
|
273
|
-
- Open an issue on [GitHub](https://github.com/MasuRii/opencode-smart-voice-notify/issues)
|
|
274
|
-
- Check the [OpenCode docs](https://opencode.ai/docs/plugins)
|
|
228
|
+
- **Windows**: Built-in (uses Windows Media Player)
|
|
229
|
+
- **macOS**: Built-in (`afplay`)
|
|
230
|
+
- **Linux**: `paplay` or `aplay`
|
|
231
|
+
|
|
232
|
+
## Events Handled
|
|
233
|
+
|
|
234
|
+
| Event | Action |
|
|
235
|
+
|-------|--------|
|
|
236
|
+
| `session.idle` | Agent finished working - notify user |
|
|
237
|
+
| `permission.updated` | Permission request - alert user |
|
|
238
|
+
| `permission.replied` | User responded - cancel pending reminders |
|
|
239
|
+
| `message.updated` | New user message - cancel pending reminders |
|
|
240
|
+
| `session.created` | New session - reset state |
|
|
241
|
+
|
|
242
|
+
## Development
|
|
243
|
+
|
|
244
|
+
To develop on this plugin locally:
|
|
245
|
+
|
|
246
|
+
1. Clone the repository:
|
|
247
|
+
```bash
|
|
248
|
+
git clone https://github.com/MasuRii/opencode-smart-voice-notify.git
|
|
249
|
+
cd opencode-smart-voice-notify
|
|
250
|
+
bun install # or npm install
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
2. Link to your OpenCode config:
|
|
254
|
+
```json
|
|
255
|
+
{
|
|
256
|
+
"plugin": ["file:///absolute/path/to/opencode-smart-voice-notify"]
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Updating
|
|
261
|
+
|
|
262
|
+
OpenCode does not automatically update plugins. To update to the latest version:
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
# Clear the cached plugin
|
|
266
|
+
rm -rf ~/.cache/opencode/node_modules/opencode-smart-voice-notify
|
|
267
|
+
|
|
268
|
+
# Run OpenCode to trigger a fresh install
|
|
269
|
+
opencode
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
MIT
|
|
275
|
+
|
|
276
|
+
## Support
|
|
277
|
+
|
|
278
|
+
- Open an issue on [GitHub](https://github.com/MasuRii/opencode-smart-voice-notify/issues)
|
|
279
|
+
- Check the [OpenCode docs](https://opencode.ai/docs/plugins)
|
|
280
|
+
|
|
281
|
+
<!-- Dynamic Header -->
|
|
282
|
+
<img width="100%" src="https://capsule-render.vercel.app/api?type=waving&color=0:667eea,100:764ba2&height=120§ion=header"/>
|
package/example.config.jsonc
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
// TTS ENGINE SELECTION
|
|
49
49
|
// ============================================================
|
|
50
50
|
// 'elevenlabs' - Best quality, anime-like voices (requires API key, free tier: 10k chars/month)
|
|
51
|
-
// 'edge' - Good quality neural voices (
|
|
51
|
+
// 'edge' - Good quality neural voices (Free, Native Node.js implementation)
|
|
52
52
|
// 'sapi' - Windows built-in voices (free, offline, robotic)
|
|
53
53
|
"ttsEngine": "elevenlabs",
|
|
54
54
|
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
// ============================================================
|
|
82
82
|
// EDGE TTS SETTINGS (Free Neural Voices - Fallback)
|
|
83
83
|
// ============================================================
|
|
84
|
-
//
|
|
84
|
+
// Native Node.js implementation (No external dependencies)
|
|
85
85
|
|
|
86
86
|
// Voice options (run 'edge-tts --list-voices' to see all):
|
|
87
87
|
// 'en-US-AnaNeural' - Young, cute, cartoon-like (RECOMMENDED)
|
package/index.js
CHANGED
|
@@ -198,6 +198,12 @@ export default async function SmartVoiceNotifyPlugin({ project, client, $, direc
|
|
|
198
198
|
fallbackSound: options.fallbackSound
|
|
199
199
|
});
|
|
200
200
|
|
|
201
|
+
// CRITICAL FIX: Check if cancelled during playback (user responded while TTS was speaking)
|
|
202
|
+
if (!pendingReminders.has(type)) {
|
|
203
|
+
debugLog(`scheduleTTSReminder: ${type} cancelled during playback - aborting follow-up`);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
201
207
|
// Clean up
|
|
202
208
|
pendingReminders.delete(type);
|
|
203
209
|
|
|
@@ -270,6 +276,18 @@ export default async function SmartVoiceNotifyPlugin({ project, client, $, direc
|
|
|
270
276
|
await playSound(soundFile, soundLoops);
|
|
271
277
|
}
|
|
272
278
|
|
|
279
|
+
// CRITICAL FIX: Check if user responded during sound playback
|
|
280
|
+
// For idle notifications: check if there was new activity after the idle start
|
|
281
|
+
if (type === 'idle' && lastUserActivityTime > lastSessionIdleTime) {
|
|
282
|
+
debugLog(`smartNotify: user active during sound - aborting idle reminder`);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
// For permission notifications: check if the permission was already handled
|
|
286
|
+
if (type === 'permission' && !activePermissionId) {
|
|
287
|
+
debugLog(`smartNotify: permission handled during sound - aborting reminder`);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
273
291
|
// Step 2: Schedule TTS reminder if user doesn't respond
|
|
274
292
|
if (config.enableTTSReminder && ttsMessage) {
|
|
275
293
|
scheduleTTSReminder(type, ttsMessage, { fallbackSound });
|
|
@@ -347,9 +365,12 @@ export default async function SmartVoiceNotifyPlugin({ project, client, $, direc
|
|
|
347
365
|
// CRITICAL: Clear activePermissionId FIRST to prevent race condition
|
|
348
366
|
// where permission.updated handler is still running async operations
|
|
349
367
|
const repliedPermissionId = event.properties?.permissionID;
|
|
350
|
-
|
|
368
|
+
|
|
369
|
+
// Match if IDs are equal, or if we have an active permission with unknown ID (undefined)
|
|
370
|
+
// (This happens if permission.updated received an event without permissionID)
|
|
371
|
+
if (activePermissionId === repliedPermissionId || activePermissionId === undefined) {
|
|
351
372
|
activePermissionId = null;
|
|
352
|
-
debugLog(`Permission replied: cleared activePermissionId ${repliedPermissionId}`);
|
|
373
|
+
debugLog(`Permission replied: cleared activePermissionId ${repliedPermissionId || '(unknown)'}`);
|
|
353
374
|
}
|
|
354
375
|
lastUserActivityTime = Date.now();
|
|
355
376
|
cancelPendingReminder('permission'); // Cancel permission-specific reminder
|
|
@@ -402,7 +423,13 @@ export default async function SmartVoiceNotifyPlugin({ project, client, $, direc
|
|
|
402
423
|
if (event.type === "permission.updated") {
|
|
403
424
|
// CRITICAL: Capture permissionID IMMEDIATELY (before any async work)
|
|
404
425
|
// This prevents race condition where user responds before we finish notifying
|
|
405
|
-
|
|
426
|
+
// NOTE: In permission.updated, the property is 'id', but in permission.replied it is 'permissionID'
|
|
427
|
+
const permissionId = event.properties?.id;
|
|
428
|
+
|
|
429
|
+
if (!permissionId) {
|
|
430
|
+
debugLog('permission.updated: permission ID missing. properties keys: ' + Object.keys(event.properties || {}).join(', '));
|
|
431
|
+
}
|
|
432
|
+
|
|
406
433
|
activePermissionId = permissionId;
|
|
407
434
|
|
|
408
435
|
debugLog(`permission.updated: notifying (permissionId=${permissionId})`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-smart-voice-notify",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Smart voice notification plugin for OpenCode with multiple TTS engines (ElevenLabs, Edge TTS, Windows SAPI) and intelligent reminder system",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
"node": ">=18.0.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@elevenlabs/elevenlabs-js": "^2.28.0"
|
|
41
|
+
"@elevenlabs/elevenlabs-js": "^2.28.0",
|
|
42
|
+
"msedge-tts": "^2.0.3"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
45
|
"@opencode-ai/plugin": "^1.0.0"
|
package/util/tts.js
CHANGED
|
@@ -110,6 +110,8 @@ export const getTTSConfig = () => {
|
|
|
110
110
|
});
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
+
let elevenLabsQuotaExceeded = false;
|
|
114
|
+
|
|
113
115
|
/**
|
|
114
116
|
* Creates a TTS utility instance
|
|
115
117
|
* @param {object} params - { $, client }
|
|
@@ -119,6 +121,21 @@ export const createTTS = ({ $, client }) => {
|
|
|
119
121
|
const config = getTTSConfig();
|
|
120
122
|
const logFile = path.join(configDir, 'smart-voice-notify-debug.log');
|
|
121
123
|
|
|
124
|
+
const showToast = async (message, variant = 'info') => {
|
|
125
|
+
if (!config.enableToast) return;
|
|
126
|
+
try {
|
|
127
|
+
if (typeof client?.tui?.showToast === 'function') {
|
|
128
|
+
await client.tui.showToast({
|
|
129
|
+
body: {
|
|
130
|
+
message: message,
|
|
131
|
+
variant: variant,
|
|
132
|
+
duration: 6000
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
} catch (e) {}
|
|
137
|
+
};
|
|
138
|
+
|
|
122
139
|
const debugLog = (message) => {
|
|
123
140
|
if (!config.debugLog) return;
|
|
124
141
|
try {
|
|
@@ -174,6 +191,8 @@ export const createTTS = ({ $, client }) => {
|
|
|
174
191
|
* ElevenLabs Engine (Online, High Quality, Anime-like voices)
|
|
175
192
|
*/
|
|
176
193
|
const speakWithElevenLabs = async (text) => {
|
|
194
|
+
if (elevenLabsQuotaExceeded) return false;
|
|
195
|
+
|
|
177
196
|
if (!config.elevenLabsApiKey) {
|
|
178
197
|
debugLog('speakWithElevenLabs: No API key configured');
|
|
179
198
|
return false;
|
|
@@ -204,6 +223,19 @@ export const createTTS = ({ $, client }) => {
|
|
|
204
223
|
return true;
|
|
205
224
|
} catch (e) {
|
|
206
225
|
debugLog(`speakWithElevenLabs error: ${e.message}`);
|
|
226
|
+
|
|
227
|
+
// Handle quota exceeded (401 specifically, or specific error message)
|
|
228
|
+
const isQuotaError =
|
|
229
|
+
e.statusCode === 401 ||
|
|
230
|
+
e.message?.includes('401') ||
|
|
231
|
+
e.message?.toLowerCase().includes('quota_exceeded') ||
|
|
232
|
+
e.message?.toLowerCase().includes('quota exceeded');
|
|
233
|
+
|
|
234
|
+
if (isQuotaError) {
|
|
235
|
+
elevenLabsQuotaExceeded = true;
|
|
236
|
+
await showToast("⚠️ ElevenLabs quota exceeded! Switching to Edge TTS for this session.", "error");
|
|
237
|
+
}
|
|
238
|
+
|
|
207
239
|
return false;
|
|
208
240
|
}
|
|
209
241
|
};
|
|
@@ -212,16 +244,20 @@ export const createTTS = ({ $, client }) => {
|
|
|
212
244
|
* Edge TTS Engine (Free, Neural voices)
|
|
213
245
|
*/
|
|
214
246
|
const speakWithEdgeTTS = async (text) => {
|
|
215
|
-
if (!$) return false;
|
|
216
247
|
try {
|
|
217
|
-
const
|
|
248
|
+
const { MsEdgeTTS, OUTPUT_FORMAT } = await import('msedge-tts');
|
|
249
|
+
const tts = new MsEdgeTTS();
|
|
250
|
+
const voice = config.edgeVoice || 'en-US-JennyNeural';
|
|
218
251
|
const pitch = config.edgePitch || '+0Hz';
|
|
219
|
-
const rate = config.edgeRate || '+
|
|
220
|
-
const
|
|
252
|
+
const rate = config.edgeRate || '+10%';
|
|
253
|
+
const volume = config.edgeVolume || '+0%';
|
|
221
254
|
|
|
222
|
-
await
|
|
223
|
-
|
|
224
|
-
|
|
255
|
+
await tts.setMetadata(voice, OUTPUT_FORMAT.AUDIO_24KHZ_48KBITRATE_MONO_MP3);
|
|
256
|
+
|
|
257
|
+
const { audioFilePath } = await tts.toFile(os.tmpdir(), text, { pitch, rate, volume });
|
|
258
|
+
|
|
259
|
+
await playAudioFile(audioFilePath);
|
|
260
|
+
try { fs.unlinkSync(audioFilePath); } catch (e) {}
|
|
225
261
|
return true;
|
|
226
262
|
} catch (e) {
|
|
227
263
|
debugLog(`speakWithEdgeTTS error: ${e.message}`);
|