opencode-voice-dictation 0.0.0-stage → 0.2.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 +272 -2
- package/dist/gui-experimental.cjs +192 -0
- package/package.json +53 -4
- package/src/gui/contract.ts +87 -0
- package/src/gui/definition.ts +204 -0
- package/src/gui/engines/sapi-speech.ts +151 -0
- package/src/gui/engines/script.ts +125 -0
- package/src/gui/engines/speak-script.ts +66 -0
- package/src/gui/engines/system-speech.ts +202 -0
- package/src/gui/engines/win-h.ts +80 -0
- package/src/gui/main.ts +150 -0
- package/src/gui/settings.tsx +297 -0
- package/src/gui/speak.ts +260 -0
- package/src/gui/window.tsx +289 -0
- package/src/gui.tsx +6 -0
- package/src/index.ts +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fran Carlos
|
|
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
CHANGED
|
@@ -1,3 +1,273 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Dictado por voz para OpenCode Desktop
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Plugin de [OpenCode](https://opencode.ai) V2 que añade voz a la app de
|
|
4
|
+
escritorio:
|
|
5
|
+
|
|
6
|
+
- **Dictado**: pulsas la píldora y se abre el dictado de Windows 11 (Win+H),
|
|
7
|
+
que escribe en el prompt con su motor neuronal. También puedes usar el motor
|
|
8
|
+
offline `System.Speech` desde Ajustes.
|
|
9
|
+
- **Lectura**: pulsa «Leer» y reproduce en voz alta la última respuesta.
|
|
10
|
+
|
|
11
|
+
- **Dictado preciso**: por defecto delega en Windows Voice Typing (Win+H).
|
|
12
|
+
- **Modo offline**: `System.Speech` sigue disponible como alternativa sin
|
|
13
|
+
conexión y sin depender del dictado de Windows.
|
|
14
|
+
- **Sin portapapeles**: la lectura usa `composer.insert()` en la posición del
|
|
15
|
+
cursor, sin robar el foco ni simular `Ctrl+V`.
|
|
16
|
+
- **Lectura local**: voces del sistema (`speechSynthesis`), con respaldo a
|
|
17
|
+
`System.Speech.Synthesis` si Electron no expone voces.
|
|
18
|
+
- **Solo Windows**: la app declara `os: ["windows"]`; en otros sistemas aparece
|
|
19
|
+
como no disponible en vez de fallar.
|
|
20
|
+
|
|
21
|
+
## Instalación rápida
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
opencode plugin add opencode-voice-dictation
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Reinicia OpenCode Desktop. El plugin queda registrado en el `opencode.json`
|
|
28
|
+
global del entorno donde ejecutes el comando.
|
|
29
|
+
|
|
30
|
+
Actualizar:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
opencode plugin update opencode-voice-dictation
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
También puedes instalarlo directamente desde el repositorio (el bundle `dist/`
|
|
37
|
+
está commiteado):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
opencode plugin add github:evious/opencode-voice-dictation
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Compatibilidad
|
|
44
|
+
|
|
45
|
+
Probado con OpenCode Desktop **2.2.6** en Windows 11. La API de plugins GUI es
|
|
46
|
+
experimental (`gui-experimental`) y puede cambiar entre versiones de OpenCode.
|
|
47
|
+
|
|
48
|
+
## Cómo funciona
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
┌─ Ventana (Solid) ─────────────────────────────┐
|
|
52
|
+
│ ComposerPill 🎤 → ctx.main(Dictation).start │
|
|
53
|
+
│ ↑ │
|
|
54
|
+
│ evento "final" → composer.insert(texto) │
|
|
55
|
+
└───────────────┬───────────────────────────────┘
|
|
56
|
+
│ Ipc (proceso main de Electron)
|
|
57
|
+
┌───────────────▼───────────────────────────────┐
|
|
58
|
+
│ powershell.exe -File dictation-<hash>.ps1 │
|
|
59
|
+
│ System.Speech + DictationGrammar │
|
|
60
|
+
│ una línea JSON por frase reconocida │
|
|
61
|
+
└───────────────────────────────────────────────┘
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
El motor vive en el proceso `main` de Electron porque necesita
|
|
65
|
+
`node:child_process`. La ventana solo pinta el estado y escribe el texto.
|
|
66
|
+
|
|
67
|
+
Con el motor por defecto (`Windows Voice Typing`) el flujo es más corto: la
|
|
68
|
+
píldora enfoca el composer, el proceso `main` envía `Win+H` con `keybd_event`, y
|
|
69
|
+
Windows escribe directamente en el campo. El plugin no transcribe ni toca el
|
|
70
|
+
texto.
|
|
71
|
+
|
|
72
|
+
## Requisitos
|
|
73
|
+
|
|
74
|
+
- OpenCode Desktop en **Windows 10/11**.
|
|
75
|
+
- Node.js 22 o superior para compilar (solo en desarrollo).
|
|
76
|
+
- Un **paquete de idioma de reconocimiento de voz** instalado:
|
|
77
|
+
Configuración → Hora e idioma → Idioma y región → (idioma) → Opciones →
|
|
78
|
+
Reconocimiento de voz. No basta con el paquete de visualización.
|
|
79
|
+
- Micrófono predeterminado configurado.
|
|
80
|
+
|
|
81
|
+
Comprobación rápida en PowerShell:
|
|
82
|
+
|
|
83
|
+
```powershell
|
|
84
|
+
Add-Type -AssemblyName System.Speech
|
|
85
|
+
[System.Speech.Recognition.SpeechRecognitionEngine]::InstalledRecognizers() |
|
|
86
|
+
ForEach-Object { $_.Culture.Name }
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Compilar
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
npm install
|
|
93
|
+
npm run build
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Genera `dist/gui-experimental.cjs`. Para desarrollo, `npm run dev` reconstruye
|
|
97
|
+
en cada cambio y OpenCode Desktop recarga el plugin solo.
|
|
98
|
+
|
|
99
|
+
## Instalación manual (desarrollo)
|
|
100
|
+
|
|
101
|
+
1. Copia al lado de Windows una carpeta con:
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
voice-dictation/
|
|
105
|
+
├── package.json
|
|
106
|
+
├── dist/gui-experimental.cjs
|
|
107
|
+
└── src/index.ts
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`node_modules` no hace falta: la parte servidor solo importa tipos y el
|
|
111
|
+
bundle usa los módulos que la app ya proporciona.
|
|
112
|
+
|
|
113
|
+
2. Añade la carpeta al `opencode.json` **global** de la app de escritorio
|
|
114
|
+
(`C:\Users\<usuario>\.config\opencode\opencode.json`):
|
|
115
|
+
|
|
116
|
+
```jsonc
|
|
117
|
+
{
|
|
118
|
+
"plugins": ["C:\\Users\\<usuario>\\opencode-plugins\\voice-dictation"]
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
La app de escritorio solo lee plugins GUI del `opencode.json` global, no de
|
|
123
|
+
`cli.json`.
|
|
124
|
+
|
|
125
|
+
3. Abre **Ajustes → Extensiones → Plugins** y comprueba que aparece
|
|
126
|
+
`voice-dictation`. Si no aparece, revisa la ruta y los logs de la app.
|
|
127
|
+
|
|
128
|
+
> Si compilas en WSL, copia la carpeta a una ruta de Windows. La app no puede
|
|
129
|
+
> cargar el bundle desde una ruta de Linux.
|
|
130
|
+
|
|
131
|
+
## Uso
|
|
132
|
+
|
|
133
|
+
| Acción | Cómo |
|
|
134
|
+
|---|---|
|
|
135
|
+
| Empezar / parar dictado | Clic en la píldora 🎤 sobre el composer |
|
|
136
|
+
| Atajo de dictado | `Ctrl+Shift+M` (configurable en Ajustes → Atajos) |
|
|
137
|
+
| Comando de dictado | `/dictado` en el prompt |
|
|
138
|
+
| Leer el último mensaje | Clic en la píldora «Leer», o `Ctrl+Shift+L` |
|
|
139
|
+
| Comando de lectura | `/leer` en el prompt |
|
|
140
|
+
| Ajustes | Ajustes → Dictado por voz, o paleta: "Ajustes de dictado por voz" |
|
|
141
|
+
|
|
142
|
+
La píldora del micrófono muestra el estado: `Dictar`, `Iniciando…`,
|
|
143
|
+
`Escuchando…` (System.Speech), `Dictando…` (Win+H) y `Reintentar dictado` si
|
|
144
|
+
algo falla.
|
|
145
|
+
|
|
146
|
+
La píldora «Leer» cambia a `Leyendo…`; un segundo clic detiene la lectura.
|
|
147
|
+
Dictar detiene la lectura y leer detiene el dictado, para que el micrófono no
|
|
148
|
+
capture la voz del altavoz.
|
|
149
|
+
|
|
150
|
+
El texto se inserta en la posición del cursor. Si ya hay texto y no termina en
|
|
151
|
+
espacio, se añade uno de separación (configurable).
|
|
152
|
+
|
|
153
|
+
## Ajustes
|
|
154
|
+
|
|
155
|
+
| Ajuste | Por defecto | Qué hace |
|
|
156
|
+
|---|---|---|
|
|
157
|
+
| Motor de dictado | Windows Voice Typing (Win+H) | Usa el dictado de Windows 11, más preciso. `System.Speech` es la alternativa offline. |
|
|
158
|
+
| Probar Win+H | — | Envía el atajo y comprueba que Windows abre su barra de dictado. |
|
|
159
|
+
| Idioma | `es-ES` | Solo para `System.Speech`. Reconocedor instalado en Windows. Si no existe el exacto, usa el mismo idioma base. |
|
|
160
|
+
| Confianza mínima | 0,4 | Solo para `System.Speech`. Descarta resultados con menor confianza. |
|
|
161
|
+
| Espacio antes del texto | Sí | Solo para `System.Speech`. Separa el dictado de lo que ya hay escrito. |
|
|
162
|
+
| Enfocar el prompt al terminar | Sí | Solo para `System.Speech`. Mueve el cursor al prompt tras cada frase. |
|
|
163
|
+
| Probar micrófono | — | Solo para `System.Speech`. Lista los idiomas instalados y comprueba el micrófono. |
|
|
164
|
+
|
|
165
|
+
### Lectura en voz alta
|
|
166
|
+
|
|
167
|
+
| Ajuste | Por defecto | Qué hace |
|
|
168
|
+
|---|---|---|
|
|
169
|
+
| Voz | Automática | Voz del sistema; automática elige una en el idioma de la app. |
|
|
170
|
+
| Velocidad | 1× | 0,8×, 1×, 1,2× o 1,5×. |
|
|
171
|
+
| Ignorar bloques de código | Sí | Lee solo la prosa; omite código, rutas y comandos. |
|
|
172
|
+
| Probar voz | — | Lee una frase corta con la configuración actual. |
|
|
173
|
+
|
|
174
|
+
La lectura limpia el Markdown antes de hablar: quita fences, backticks,
|
|
175
|
+
negritas, encabezados, viñetas y convierte `[texto](url)` en `texto`. Trocea el
|
|
176
|
+
texto por frases para poder detenerse rápido.
|
|
177
|
+
|
|
178
|
+
## Permisos
|
|
179
|
+
|
|
180
|
+
El plugin es local y no hace peticiones de red. Para funcionar:
|
|
181
|
+
|
|
182
|
+
- Escribe un script `dictation-<hash>.ps1` o `speak-<hash>.ps1` en
|
|
183
|
+
`%TEMP%\opencode-voice-dictation`.
|
|
184
|
+
- Ejecuta `powershell.exe` con ese script.
|
|
185
|
+
- El script abre el micrófono (`System.Speech`) y, al leer, el altavoz.
|
|
186
|
+
|
|
187
|
+
Por eso Windows y antivirus como Kaspersky pueden pedir permiso la primera vez:
|
|
188
|
+
es esperado. Elige **Permitir ahora** y marca **Recordar mi elección**. Si
|
|
189
|
+
bloqueas el micrófono, verás el aviso «No hay ningún micrófono disponible».
|
|
190
|
+
|
|
191
|
+
## Solución de problemas
|
|
192
|
+
|
|
193
|
+
| Síntoma | Causa / solución |
|
|
194
|
+
|---|---|
|
|
195
|
+
| Al pulsar «Dictar» no aparece la barra de Windows | Abre Ajustes → Dictado por voz → **Probar Win+H**. Si tampoco aparece, revisa Configuración → Accesibilidad → Dictado por voz, y que Kaspersky no esté bloqueando la combinación sintética. |
|
|
196
|
+
| Win+H se abre pero no escribe en el prompt | Haz clic en el cuadro de texto antes de dictar; el plugin enfoca el composer, pero otra ventana pudo robar el foco. |
|
|
197
|
+
| Quiero dictado sin Win+H | Cambia **Motor de dictado** a `System.Speech (offline)`. |
|
|
198
|
+
| «El idioma de reconocimiento es-ES no está instalado» | Solo afecta a `System.Speech`. Instala el paquete de **reconocimiento** de voz, no solo el de visualización. |
|
|
199
|
+
| «Windows no tiene ningún reconocedor de voz instalado» | Mismo caso: no hay ningún idioma de voz instalado. |
|
|
200
|
+
| «No hay ningún micrófono disponible» | Revisa Configuración → Sistema → Sonido → Entrada y el micrófono predeterminado. |
|
|
201
|
+
| El motor se detiene inesperadamente | Otro proceso puede estar usando el micrófono en modo exclusivo. Ejecuta la prueba de micrófono en Ajustes. |
|
|
202
|
+
| La píldora no aparece | Comprueba que el plugin está en el `opencode.json` global, que la app corre en Windows y que el plugin figura como cargado en Ajustes → Extensiones → Plugins. |
|
|
203
|
+
| No transcribe nada | Sube el nivel de entrada del micrófono y baja la confianza mínima a 0,2. |
|
|
204
|
+
| «Windows no tiene voces instaladas para la lectura» | Instala una voz en Configuración → Hora e idioma → Voz, o revisa que `System.Speech` esté disponible. El plugin usa primero las voces de Chromium y cae a SAPI si no hay. |
|
|
205
|
+
| La lectura se corta o no suena | Prueba «Probar voz» en Ajustes; si suena ahí, el problema es el dispositivo de salida de la app. |
|
|
206
|
+
| «Abre una conversación para leer su último mensaje» | En Home o en un chat nuevo sin mensajes no hay respuesta que leer. |
|
|
207
|
+
|
|
208
|
+
Los errores del plugin se registran en el log de OpenCode Desktop; los `toast`
|
|
209
|
+
de la app muestran los más importantes.
|
|
210
|
+
|
|
211
|
+
## Limitaciones
|
|
212
|
+
|
|
213
|
+
- La API de plugins GUI es **experimental** (`gui-experimental`) y puede
|
|
214
|
+
cambiar entre versiones de OpenCode.
|
|
215
|
+
- `System.Speech` no añade puntuación ni mayúsculas automáticamente y su
|
|
216
|
+
precisión es inferior a Whisper o al dictado nativo de Windows 11.
|
|
217
|
+
- El modo Win+H envía la combinación con `keybd_event`. Kaspersky o la
|
|
218
|
+
protección UIPI de Windows pueden bloquearla; en ese caso usa `System.Speech`.
|
|
219
|
+
- Con Win+H el texto lo escribe Windows en el campo enfocado: el plugin no
|
|
220
|
+
puede descartarlo si cambias de sesión ni limpiarlo.
|
|
221
|
+
- No hay resultados parciales con `System.Speech`: el texto aparece al terminar
|
|
222
|
+
cada frase.
|
|
223
|
+
- La lectura usa las voces del sistema; si Electron no las expone, el respaldo
|
|
224
|
+
por PowerShell usa las voces SAPI, con una latencia de arranque de ~0,5 s.
|
|
225
|
+
- La lectura empieza con el mensaje tal como esté en ese momento: si el agente
|
|
226
|
+
sigue escribiendo, leerá la versión parcial.
|
|
227
|
+
- Una sola dictación a la vez (hay un micrófono). Si empiezas en otra ventana,
|
|
228
|
+
la anterior se detiene.
|
|
229
|
+
- Si cambias de sesión durante el dictado, el texto se descarta con un aviso
|
|
230
|
+
para no escribirlo en la sesión equivocada.
|
|
231
|
+
|
|
232
|
+
El motor está aislado en `src/gui/engines/`: para cambiar a Whisper local o a
|
|
233
|
+
una API en la nube basta con respetar el mismo contrato (`startEngine` y los
|
|
234
|
+
eventos `ready` / `final` / `error`).
|
|
235
|
+
|
|
236
|
+
## Desarrollo
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
src/
|
|
240
|
+
├── index.ts Parte servidor: fija el id "voice-dictation"
|
|
241
|
+
├── gui.tsx Entrada ./gui-experimental
|
|
242
|
+
└── gui/
|
|
243
|
+
├── definition.ts os, stores, i18n es/en
|
|
244
|
+
├── contract.ts Ipc: dictado y lectura
|
|
245
|
+
├── window.tsx Píldoras, comandos e inserción de texto
|
|
246
|
+
├── main.ts Dictado y voz de respaldo
|
|
247
|
+
├── speak.ts Limpieza de Markdown, troceado y speechSynthesis
|
|
248
|
+
├── settings.tsx Página de ajustes
|
|
249
|
+
└── engines/
|
|
250
|
+
├── script.ts Script de PowerShell para el dictado
|
|
251
|
+
├── system-speech.ts Spawn, parseo de JSON, diagnose, taskkill
|
|
252
|
+
├── speak-script.ts Script de PowerShell para la lectura
|
|
253
|
+
└── sapi-speech.ts Voz de respaldo y listado de voces SAPI
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
`npm run typecheck` valida los tipos, `npm run build` genera el bundle CJS y
|
|
257
|
+
`npm test` ejecuta el smoke test (`test/smoke.cjs`): simula el host de la app,
|
|
258
|
+
un `powershell.exe` falso y la API de voz del navegador para comprobar dictado,
|
|
259
|
+
lectura, limpieza de Markdown, cancelación, fallback y errores.
|
|
260
|
+
|
|
261
|
+
## Publicar
|
|
262
|
+
|
|
263
|
+
Mantenedores:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
npm login
|
|
267
|
+
npm version patch # o minor / major
|
|
268
|
+
npm publish
|
|
269
|
+
git push --tags
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
El workflow de release publica en npm al empujar un tag `v*`. Configura el
|
|
273
|
+
secreto `NPM_TOKEN` en GitHub, o usa Trusted Publishing con OIDC.
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const w=require("@opencode/plugin/gui"),c=require("effect"),R=require("node:child_process"),_=require("node:crypto"),k=require("node:fs"),W=require("node:os"),I=require("node:path"),g=require("solid-js/web"),C=require("solid-js"),X=w.Plugin.define({os:["windows"],stores:{prefs:w.Store.global(c.Schema.Struct({locale:c.Schema.String,minConfidence:c.Schema.Number,trailingSpace:c.Schema.Boolean,autoFocus:c.Schema.Boolean}),{locale:"es-ES",minConfidence:.4,trailingSpace:!0,autoFocus:!0}),speech:w.Store.global(c.Schema.Struct({voiceURI:c.Schema.String,rate:c.Schema.Number,skipCode:c.Schema.Boolean}),{voiceURI:"",rate:1,skipCode:!0}),engine:w.Store.global(c.Schema.Struct({mode:c.Schema.String}),{mode:"windows"})},i18n:{en:{"pill.idle":"Dictate","pill.starting":"Starting…","pill.listening":"Listening…","pill.dictating":"Dictating…","pill.error":"Retry dictation","pill.title":"Voice dictation","pill.winH":"Open Windows voice typing (Win+H)","pill.stop":"Stop dictation","command.toggle":"Toggle voice dictation","command.toggle.description":"Dictate into the prompt with the selected engine","command.configure":"Voice dictation settings","error.title":"Voice dictation","error.language":"The speech language {locale} is not installed. Available: {available}.","error.none":"Windows has no speech recognizer installed. Settings › Time & language › Language › Speech.","error.mic":"No microphone is available for speech recognition.","error.system":"System.Speech is not available in this Windows installation.","error.exit":"The dictation engine stopped unexpectedly.","error.unknown":"Dictation failed ({code}).","toast.discarded":"Dictation discarded: the active session changed.","settings.title":"Voice dictation","settings.description":"Offline dictation with the Windows speech recognizer. The text is inserted into the prompt; it is never sent automatically.","settings.section":"Dictation","settings.engine":"Dictation engine","settings.engine.description":"Windows uses Windows 11 voice typing (Win+H), which is more accurate. System.Speech works offline but is less precise.","engine.windows":"Windows Voice Typing (Win+H)","engine.system":"System.Speech (offline)","settings.winh":"Test Win+H","settings.winh.description":"Sends the Windows voice typing shortcut. If the floating bar appears, it works.","settings.winh.run":"Test Win+H","settings.winh.sent":"Win+H sent. If the Windows dictation bar did not appear, check Settings › Accessibility › Voice typing.","error.winh":"Windows voice typing could not be triggered.","settings.language":"Language","settings.language.description":"A speech recognizer installed in Windows. Accents and punctuation depend on it.","settings.confidence":"Minimum confidence","settings.confidence.description":"Results below this threshold are ignored to avoid noise.","confidence.low":"Low (0.2)","confidence.normal":"Normal (0.4)","confidence.high":"High (0.6)","settings.space":"Add a space before the text","settings.space.description":"Separates the dictation from what is already in the prompt.","settings.focus":"Focus the prompt after dictating","settings.focus.description":"Moves the cursor to the prompt so you can review or send it.","settings.test.section":"Diagnostics","settings.test":"Test microphone","settings.test.description":"Checks installed recognizers and the default microphone.","settings.test.run":"Run test","settings.test.success":"Speech recognition ready: {locale}","settings.test.failed":"Not ready: {reason}","common.reason.no-recognizers":"no speech language installed","common.reason.no-microphone":"no microphone available","read.idle":"Read","read.speaking":"Reading…","read.stop":"Stop reading","read.title":"Read the last message aloud","command.read":"Read the last message aloud","command.read.description":"Speaks the last reply with a system voice","read.noSession":"Open a conversation to read its last message.","read.empty":"The last message has no text to read.","read.error":"The last message could not be read.","read.noVoices":"Windows has no voices installed for reading.","speech.section":"Read aloud","speech.voice":"Voice","speech.voice.description":"A system voice. Automatic picks one in the app language.","speech.voice.auto":"Automatic","speech.rate":"Speed","speech.rate.description":"How fast the text is spoken.","speech.rate.slow":"0.8×","speech.rate.normal":"1×","speech.rate.fast":"1.2×","speech.rate.faster":"1.5×","speech.skipCode":"Skip code blocks","speech.skipCode.description":"Read only the prose; code, paths and commands are left out.","speech.preview":"Test voice","speech.preview.description":"Speaks a short sample with the current voice and speed.","speech.preview.text":"Hello, this is a reading test."},es:{"pill.idle":"Dictar","pill.starting":"Iniciando…","pill.listening":"Escuchando…","pill.dictating":"Dictando…","pill.error":"Reintentar dictado","pill.title":"Dictado por voz","pill.winH":"Abrir el dictado de Windows (Win+H)","pill.stop":"Detener dictado","command.toggle":"Alternar dictado por voz","command.toggle.description":"Dicta en el prompt con el motor elegido","command.configure":"Ajustes de dictado por voz","error.title":"Dictado por voz","error.language":"El idioma de reconocimiento {locale} no está instalado. Disponibles: {available}.","error.none":"Windows no tiene ningún reconocedor de voz instalado. Configuración › Hora e idioma › Idioma › Voz.","error.mic":"No hay ningún micrófono disponible para el reconocimiento de voz.","error.system":"System.Speech no está disponible en esta instalación de Windows.","error.exit":"El motor de dictado se detuvo inesperadamente.","error.unknown":"El dictado falló ({code}).","toast.discarded":"Dictado descartado: la sesión activa cambió.","settings.title":"Dictado por voz","settings.description":"Dictado offline con el reconocedor de voz de Windows. El texto se inserta en el prompt; nunca se envía solo.","settings.section":"Dictado","settings.engine":"Motor de dictado","settings.engine.description":"Windows usa el dictado de Windows 11 (Win+H), más preciso. System.Speech funciona sin Windows 11 pero es menos exacto.","engine.windows":"Windows Voice Typing (Win+H)","engine.system":"System.Speech (offline)","settings.winh":"Probar Win+H","settings.winh.description":"Envía el atajo del dictado de Windows. Si aparece la barra flotante, funciona.","settings.winh.run":"Probar Win+H","settings.winh.sent":"Win+H enviado. Si no apareció la barra, revisa Configuración › Accesibilidad › Dictado por voz.","settings.language":"Idioma","settings.language.description":"Un reconocedor instalado en Windows. Los acentos y la puntuación dependen de él.","settings.confidence":"Confianza mínima","settings.confidence.description":"Los resultados por debajo de este umbral se ignoran para evitar ruido.","confidence.low":"Baja (0,2)","confidence.normal":"Normal (0,4)","confidence.high":"Alta (0,6)","settings.space":"Añadir un espacio antes del texto","settings.space.description":"Separa el dictado de lo que ya hay en el prompt.","settings.focus":"Enfocar el prompt al terminar","settings.focus.description":"Mueve el cursor al prompt para revisar o enviar el texto.","settings.test.section":"Diagnóstico","settings.test":"Probar micrófono","settings.test.description":"Comprueba los reconocedores instalados y el micrófono predeterminado.","settings.test.run":"Ejecutar prueba","settings.test.success":"Reconocimiento de voz listo: {locale}","settings.test.failed":"No está listo: {reason}","common.reason.no-recognizers":"no hay ningún idioma de voz instalado","common.reason.no-microphone":"no hay micrófono disponible","read.idle":"Leer","read.speaking":"Leyendo…","read.stop":"Detener lectura","read.title":"Leer en voz alta el último mensaje","command.read":"Leer en voz alta el último mensaje","command.read.description":"Reproduce la última respuesta con una voz del sistema","read.noSession":"Abre una conversación para leer su último mensaje.","read.empty":"El último mensaje no tiene texto para leer.","read.error":"No se pudo leer el último mensaje.","read.noVoices":"Windows no tiene voces instaladas para la lectura.","speech.section":"Lectura en voz alta","speech.voice":"Voz","speech.voice.description":"Una voz del sistema. Automática elige una en el idioma de la app.","speech.voice.auto":"Automática","speech.rate":"Velocidad","speech.rate.description":"A qué ritmo se lee el texto.","speech.rate.slow":"0,8×","speech.rate.normal":"1×","speech.rate.fast":"1,2×","speech.rate.faster":"1,5×","speech.skipCode":"Ignorar bloques de código","speech.skipCode.description":"Lee solo la prosa; omite código, rutas y comandos.","speech.preview":"Probar voz","speech.preview.description":"Lee una frase corta con la voz y velocidad actuales.","speech.preview.text":"Hola, esta es una prueba de lectura."}}}),z=w.Ipc.define({id:"voice-dictation.dictation",state:c.Schema.Struct({status:c.Schema.Literals(["idle","starting","listening","error"]),error:c.Schema.String,locale:c.Schema.String}),methods:{start:{input:c.Schema.Struct({locale:c.Schema.String,minConfidence:c.Schema.Number})},stop:{},diagnose:{output:c.Schema.Struct({locales:c.Schema.Array(c.Schema.String),microphone:c.Schema.Boolean,selected:c.Schema.String,error:c.Schema.String})}},events:{final:c.Schema.Struct({text:c.Schema.String,confidence:c.Schema.Number}),error:c.Schema.Struct({code:c.Schema.String,detail:c.Schema.String,available:c.Schema.Array(c.Schema.String)})}}),U=w.Ipc.define({id:"voice-dictation.speech",methods:{speak:{input:c.Schema.Struct({text:c.Schema.String,rate:c.Schema.Number,voice:c.Schema.String})},stop:{},voices:{output:c.Schema.Array(c.Schema.String)}},events:{done:c.Schema.Struct({ok:c.Schema.Boolean})}}),O=w.Ipc.define({id:"voice-dictation.voice-typing",methods:{toggle:{}}}),F=String.raw`param(
|
|
2
|
+
[string]$Culture = "es-ES",
|
|
3
|
+
[double]$MinConfidence = 0.4,
|
|
4
|
+
[switch]$Diagnose
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
$ErrorActionPreference = "Stop"
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
$utf8 = New-Object System.Text.UTF8Encoding($false)
|
|
11
|
+
[Console]::OutputEncoding = $utf8
|
|
12
|
+
} catch { }
|
|
13
|
+
|
|
14
|
+
function Emit {
|
|
15
|
+
param([hashtable]$Payload)
|
|
16
|
+
[Console]::Out.WriteLine(($Payload | ConvertTo-Json -Compress))
|
|
17
|
+
[Console]::Out.Flush()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
Add-Type -AssemblyName System.Speech
|
|
22
|
+
} catch {
|
|
23
|
+
Emit @{ type = "error"; code = "SYSTEM_SPEECH_UNAVAILABLE"; detail = "$($_.Exception.Message)"; available = @() }
|
|
24
|
+
exit 2
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
$installed = @()
|
|
28
|
+
try {
|
|
29
|
+
foreach ($entry in [System.Speech.Recognition.SpeechRecognitionEngine]::InstalledRecognizers()) {
|
|
30
|
+
$installed += $entry.Culture.Name
|
|
31
|
+
}
|
|
32
|
+
} catch { }
|
|
33
|
+
|
|
34
|
+
$selected = ""
|
|
35
|
+
foreach ($name in $installed) {
|
|
36
|
+
if ($name -eq $Culture) { $selected = $name; break }
|
|
37
|
+
}
|
|
38
|
+
if ($selected -eq "") {
|
|
39
|
+
$base = ($Culture -split "-")[0]
|
|
40
|
+
foreach ($name in $installed) {
|
|
41
|
+
if (($name -split "-")[0] -eq $base) { $selected = $name; break }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if ($Diagnose) {
|
|
46
|
+
$microphone = $false
|
|
47
|
+
$problem = ""
|
|
48
|
+
if ($installed.Count -gt 0) {
|
|
49
|
+
try {
|
|
50
|
+
$probeCulture = New-Object System.Globalization.CultureInfo($installed[0])
|
|
51
|
+
$probe = New-Object System.Speech.Recognition.SpeechRecognitionEngine($probeCulture)
|
|
52
|
+
$probe.SetInputToDefaultAudioDevice()
|
|
53
|
+
$microphone = $true
|
|
54
|
+
$probe.Dispose()
|
|
55
|
+
} catch {
|
|
56
|
+
$problem = "$($_.Exception.Message)"
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
$problem = "NO_RECOGNIZERS"
|
|
60
|
+
}
|
|
61
|
+
Emit @{ type = "diagnose"; locales = @($installed); microphone = $microphone; selected = $selected; error = $problem }
|
|
62
|
+
exit 0
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if ($installed.Count -eq 0) {
|
|
66
|
+
Emit @{ type = "error"; code = "NO_RECOGNIZERS"; detail = ""; available = @() }
|
|
67
|
+
exit 3
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if ($selected -eq "") {
|
|
71
|
+
Emit @{ type = "error"; code = "LANGUAGE_NOT_AVAILABLE"; detail = $Culture; available = @($installed) }
|
|
72
|
+
exit 4
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
$cultureInfo = New-Object System.Globalization.CultureInfo($selected)
|
|
77
|
+
$recognizer = New-Object System.Speech.Recognition.SpeechRecognitionEngine($cultureInfo)
|
|
78
|
+
$recognizer.LoadGrammar((New-Object System.Speech.Recognition.DictationGrammar))
|
|
79
|
+
$recognizer.InitialSilenceTimeout = [TimeSpan]::FromSeconds(10)
|
|
80
|
+
$recognizer.BabbleTimeout = [TimeSpan]::FromSeconds(5)
|
|
81
|
+
$recognizer.EndSilenceTimeout = [TimeSpan]::FromSeconds(0.6)
|
|
82
|
+
$recognizer.EndSilenceTimeoutAmbiguous = [TimeSpan]::FromSeconds(1.2)
|
|
83
|
+
$recognizer.SetInputToDefaultAudioDevice()
|
|
84
|
+
} catch {
|
|
85
|
+
Emit @{ type = "error"; code = "MICROPHONE_UNAVAILABLE"; detail = "$($_.Exception.Message)"; available = @($installed) }
|
|
86
|
+
exit 5
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
Emit @{ type = "ready"; locale = $selected; requested = $Culture }
|
|
90
|
+
|
|
91
|
+
$failures = 0
|
|
92
|
+
while ($true) {
|
|
93
|
+
try {
|
|
94
|
+
$result = $recognizer.Recognize([TimeSpan]::FromSeconds(5))
|
|
95
|
+
$failures = 0
|
|
96
|
+
if ($result -ne $null -and $result.Text -ne "" -and $result.Confidence -ge $MinConfidence) {
|
|
97
|
+
Emit @{ type = "final"; text = $result.Text; confidence = [math]::Round($result.Confidence, 3); locale = $selected }
|
|
98
|
+
}
|
|
99
|
+
} catch {
|
|
100
|
+
$failures++
|
|
101
|
+
if ($failures -ge 5) {
|
|
102
|
+
Emit @{ type = "error"; code = "RECOGNITION_FAILED"; detail = "$($_.Exception.Message)"; available = @() }
|
|
103
|
+
exit 6
|
|
104
|
+
}
|
|
105
|
+
Start-Sleep -Milliseconds 250
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
`,Y="powershell.exe";function B(){const e=I.join(W.tmpdir(),"opencode-voice-dictation");k.mkdirSync(e,{recursive:!0});const t=_.createHash("sha1").update(F).digest("hex").slice(0,12),i=I.join(e,`dictation-${t}.ps1`);return k.writeFileSync(i,F,"utf8"),i}function j(e){return R.spawn(Y,e,{windowsHide:!0,stdio:["ignore","pipe","pipe"]})}function M(e){const t=e.pid;if(t===void 0){e.kill();return}R.spawn("taskkill",["/PID",String(t),"/T","/F"],{windowsHide:!0,stdio:"ignore"}).on("error",()=>e.kill())}function J(e,t){const i=j(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",B(),"-Culture",e.locale,"-MinConfidence",String(e.minConfidence)]);let l=!1,o="",s="";const p=r=>{switch(r.type){case"ready":t.onReady(r.locale??e.locale);break;case"final":r.text&&t.onFinal(r.text,r.confidence??0);break;case"error":t.onError(r.code??"UNKNOWN",r.detail??"",r.available??[]);break}};return i.stdout?.setEncoding("utf8"),i.stdout?.on("data",r=>{s+=r;let a=s.indexOf(`
|
|
109
|
+
`);for(;a>=0;){const d=s.slice(0,a).replace(/\r$/,"").trim();if(s=s.slice(a+1),d)try{p(JSON.parse(d))}catch{}a=s.indexOf(`
|
|
110
|
+
`)}}),i.stderr?.setEncoding("utf8"),i.stderr?.on("data",r=>{o=(o+r).slice(-2e3)}),i.on("error",r=>{l||t.onError("ENGINE_START_FAILED",r.message,[])}),i.on("close",r=>{l||t.onExit(r,o.trim().slice(-500))}),{stop(){l=!0,M(i)}}}function Q(){return new Promise((e,t)=>{const i=j(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",B(),"-Diagnose"]);let l="",o="",s=!1;const p=(a,d)=>{s||(s=!0,clearTimeout(r),a?t(a):e(d))},r=setTimeout(()=>{M(i),p(new Error("diagnose timed out"))},2e4);i.stdout?.setEncoding("utf8"),i.stdout?.on("data",a=>{l+=a}),i.stderr?.setEncoding("utf8"),i.stderr?.on("data",a=>{o+=a}),i.on("error",a=>p(a)),i.on("close",()=>{const a=l.split(/\r?\n/).map(d=>d.trim()).filter(d=>d.startsWith("{")).at(-1);if(!a){p(new Error(o.trim()||"no output from PowerShell"));return}try{const d=JSON.parse(a);p(void 0,{locales:d.locales??[],microphone:d.microphone===!0,selected:d.selected??"",error:d.error??""})}catch(d){p(d instanceof Error?d:new Error(String(d)))}})})}const D=String.raw`param(
|
|
111
|
+
[string]$TextFile = "",
|
|
112
|
+
[int]$Rate = 0,
|
|
113
|
+
[string]$Voice = "",
|
|
114
|
+
[switch]$ListVoices
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
$ErrorActionPreference = "Stop"
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
$utf8 = New-Object System.Text.UTF8Encoding($false)
|
|
121
|
+
[Console]::OutputEncoding = $utf8
|
|
122
|
+
} catch { }
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
Add-Type -AssemblyName System.Speech
|
|
126
|
+
} catch {
|
|
127
|
+
exit 2
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
$synth = New-Object System.Speech.Synthesis.SpeechSynthesizer
|
|
132
|
+
} catch {
|
|
133
|
+
exit 3
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if ($ListVoices) {
|
|
137
|
+
try {
|
|
138
|
+
foreach ($entry in $synth.GetInstalledVoices()) {
|
|
139
|
+
if ($entry.Enabled) {
|
|
140
|
+
[Console]::Out.WriteLine($entry.VoiceInfo.Name)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
} catch { }
|
|
144
|
+
$synth.Dispose()
|
|
145
|
+
exit 0
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if ($Rate -lt -10) { $Rate = -10 }
|
|
149
|
+
if ($Rate -gt 10) { $Rate = 10 }
|
|
150
|
+
|
|
151
|
+
try { $synth.Rate = $Rate } catch { }
|
|
152
|
+
|
|
153
|
+
if ($Voice -ne "") {
|
|
154
|
+
try { $synth.SelectVoice($Voice) } catch { }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
$text = [System.IO.File]::ReadAllText($TextFile, [System.Text.Encoding]::UTF8)
|
|
159
|
+
$synth.Speak($text)
|
|
160
|
+
} catch { }
|
|
161
|
+
|
|
162
|
+
$synth.Dispose()
|
|
163
|
+
`,x="powershell.exe";function G(){const e=I.join(W.tmpdir(),"opencode-voice-dictation");return k.mkdirSync(e,{recursive:!0}),e}function q(){const e=_.createHash("sha1").update(D).digest("hex").slice(0,12),t=I.join(G(),`speak-${e}.ps1`);return k.writeFileSync(t,D,"utf8"),t}function ee(e){const t=I.join(G(),`speech-${_.randomUUID()}.txt`);return k.writeFileSync(t,e,"utf8"),t}function K(e){return R.spawn(x,e,{windowsHide:!0,stdio:["ignore","pipe","pipe"]})}function Z(e){const t=e.pid;if(t===void 0){e.kill();return}R.spawn("taskkill",["/PID",String(t),"/T","/F"],{windowsHide:!0,stdio:"ignore"}).on("error",()=>e.kill())}function te(e){return Math.max(-10,Math.min(10,Math.round((e-1)*5)))}function ie(e,t){const i=ee(e.text),l=K(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",q(),"-TextFile",i,"-Rate",String(te(e.rate)),"-Voice",e.voice]);let o=!1;const s=()=>{try{k.rmSync(i,{force:!0})}catch{}};return l.on("error",()=>{s(),o||t(!1)}),l.on("close",p=>{s(),o||t(p===0)}),{stop(){o=!0,Z(l),s()}}}function ne(){return new Promise(e=>{const t=K(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",q(),"-ListVoices"]);let i="",l=!1;const o=p=>{l||(l=!0,clearTimeout(s),e(p))},s=setTimeout(()=>{Z(t),o([])},1e4);t.stdout?.setEncoding("utf8"),t.stdout?.on("data",p=>{i+=p}),t.on("error",()=>o([])),t.on("close",()=>{const p=i.split(/\r?\n/).map(r=>r.trim()).filter(r=>r.length>0);o(p)})})}const H=String.raw`$ErrorActionPreference = "Stop"
|
|
164
|
+
|
|
165
|
+
Add-Type @"
|
|
166
|
+
using System;
|
|
167
|
+
using System.Runtime.InteropServices;
|
|
168
|
+
|
|
169
|
+
public static class WinH {
|
|
170
|
+
[DllImport("user32.dll", SetLastError = true)]
|
|
171
|
+
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
|
|
172
|
+
|
|
173
|
+
private const byte VK_LWIN = 0x5B;
|
|
174
|
+
private const byte VK_H = 0x48;
|
|
175
|
+
private const uint KEYUP = 0x0002;
|
|
176
|
+
|
|
177
|
+
public static void Send() {
|
|
178
|
+
keybd_event(VK_LWIN, 0, 0, UIntPtr.Zero);
|
|
179
|
+
System.Threading.Thread.Sleep(60);
|
|
180
|
+
keybd_event(VK_H, 0, 0, UIntPtr.Zero);
|
|
181
|
+
System.Threading.Thread.Sleep(60);
|
|
182
|
+
keybd_event(VK_H, 0, KEYUP, UIntPtr.Zero);
|
|
183
|
+
System.Threading.Thread.Sleep(60);
|
|
184
|
+
keybd_event(VK_LWIN, 0, KEYUP, UIntPtr.Zero);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
"@
|
|
188
|
+
|
|
189
|
+
[WinH]::Send()
|
|
190
|
+
`,oe="powershell.exe";function re(){const e=I.join(W.tmpdir(),"opencode-voice-dictation");k.mkdirSync(e,{recursive:!0});const t=_.createHash("sha1").update(H).digest("hex").slice(0,12),i=I.join(e,`win-h-${t}.ps1`);return k.writeFileSync(i,H,"utf8"),i}function se(e){return R.spawn(oe,e,{windowsHide:!0,stdio:"ignore"})}function ae(){return new Promise((e,t)=>{const i=se(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",re()]);i.on("error",l=>t(l)),i.on("close",l=>{l===0?e():t(new Error(`Win+H helper exited with code ${l??"unknown"}`))})})}const ce=e=>{let t="idle",i="",l="",o,s=!1;const p=()=>{o=void 0,s=!1},r=e.provide(z,{state:()=>({status:t,error:i,locale:l}),start(b,y){o&&(s=!0,o.stop(),p()),t="starting",i="",l=b.locale,r.changed();const E=y.window;try{o=J({locale:b.locale,minConfidence:b.minConfidence},{onReady(S){t="listening",l=S,r.changed()},onFinal(S,v){r.emit("final",{text:S,confidence:v},E)},onError(S,v,$){t="error",i=S,r.changed(),r.emit("error",{code:S,detail:v,available:$},E)},onExit(S,v){if(s){p(),t="idle",i="",l="",r.changed();return}p(),t!=="error"&&(t="error",i=S===null?"ENGINE_EXIT":`ENGINE_EXIT_${S}`,r.changed(),r.emit("error",{code:"ENGINE_EXIT",detail:v||(S===null?"":String(S)),available:[]},E))}})}catch(S){throw t="error",i="ENGINE_START_FAILED",r.changed(),S}},stop(){o&&(s=!0,o.stop(),p()),t="idle",i="",l="",r.changed()},diagnose(){return Q()}});let a;const d=e.provide(U,{speak(b){a?.stop(),a=ie(b,y=>{a=void 0,d.emit("done",{ok:y})})},stop(){a&&(a.stop(),a=void 0),d.emit("done",{ok:!0})},voices(){return ne()}});e.provide(O,{toggle(){return ae()}}),e.onCleanup(()=>{o&&(s=!0,o.stop(),p()),a?.stop(),a=void 0})},le=250;function de(e,t){let i=e.replace(/\r\n/g,`
|
|
191
|
+
`);return t?i=i.replace(/```[\s\S]*?```/g," "):i=i.replace(/```[^\n]*\n([\s\S]*?)```/g,"$1"),i=i.replace(/`([^`]+)`/g,"$1"),i=i.replace(/!\[[^\]]*\]\([^)]*\)/g," "),i=i.replace(/\[([^\]]+)\]\([^)]*\)/g,"$1"),i=i.replace(/^\s*#{1,6}\s+/gm,""),i=i.replace(/^\s*>\s?/gm,""),i=i.replace(/^\s*[-*+]\s+/gm,""),i=i.replace(/^\s*\d+\.\s+/gm,""),i=i.replace(/(\*\*|__)(.*?)\1/g,"$2"),i=i.replace(/(\*|_)(.*?)\1/g,"$2"),i=i.replace(/^\s*\|.*\|\s*$/gm," "),i=i.replace(/\n{2,}/g,". "),i=i.replace(/\n/g," "),i=i.replace(/\s+/g," "),i=i.replace(/\s+([.,;:!?])/g,"$1"),i=i.replace(/([.,;:!?]){2,}/g,"$1"),i.trim()}function pe(e,t=le){const i=e.trim();if(!i)return[];const l=i.split(new RegExp("(?<=[.!?…])\\s+")),o=[];let s="";const p=r=>{let a="";for(const d of r.split(/\s+/))d&&(a&&a.length+1+d.length>t?(o.push(a),a=d):a=a?`${a} ${d}`:d);return a};for(const r of l){if(r.length>t){s&&(o.push(s),s=""),s=p(r);continue}s&&s.length+1+r.length>t?(o.push(s),s=r):s=s?`${s} ${r}`:r}return s&&o.push(s),o}function ue(e,t){const i=e.stores.speech,[l,o]=C.createSignal(!1),[s,p]=C.createSignal([]),[r,a]=C.createSignal("none");let d=0,b=[];const y=()=>typeof globalThis.speechSynthesis<"u"?globalThis.speechSynthesis:void 0,E=()=>{const m=y()?.getVoices()??[];if(m.length===0)return;const f=i.value.voiceURI;if(f){const h=m.find(A=>A.voiceURI===f);if(h)return h}const n=e.locale.locale().split("-")[0]?.toLowerCase()??"es";return m.find(h=>h.lang.toLowerCase().startsWith(n))??m[0]},S=async()=>{const m=y()?.getVoices()??[];if(m.length>0){p(m.map(f=>({id:f.voiceURI,label:`${f.name} — ${f.lang}`}))),a("web");return}try{const f=await t.voices();if(f.length>0){p(f.map(n=>({id:n,label:n}))),a("sapi");return}}catch{}a("none")},v=()=>{d++,b=[],y()?.cancel(),o(!1),t.stop().catch(()=>{})},$=async m=>{const f=de(m,i.value.skipCode);if(!f)return!1;if(v(),await S(),r()==="web"){const n=y();if(!n)return!1;const h=E(),A=i.value.rate,L=d;b=pe(f),o(!0);const P=()=>{if(L!==d)return;const V=b.shift();if(!V){o(!1);return}const T=new SpeechSynthesisUtterance(V);h&&(T.voice=h),h?.lang&&(T.lang=h.lang),T.rate=A,T.onend=P,T.onerror=P,n.speak(T)};return P(),!0}if(r()==="sapi"){o(!0);try{await t.speak({text:f,rate:i.value.rate,voice:i.value.voiceURI})}catch(n){throw o(!1),n}return!0}throw o(!1),new Error(e.t("read.noVoices"))},N=async()=>{const m=e.sessions.current();if(!m)return"";const n=(await m.server.client.message.list({sessionID:m.id,type:"assistant",order:"desc",limit:1})).data[0];return!n||n.type!=="assistant"?"":n.content.filter(h=>h.type==="text").map(h=>h.text).join(`
|
|
192
|
+
`)};return t.on("done",()=>o(!1)),y()?.addEventListener?.("voiceschanged",()=>{S()}),S(),{speaking:l,backend:r,voices:s,refreshVoices:S,lastAssistantText:N,speak:$,cancel:v,preview:()=>$(e.t("speech.preview.text"))}}const ge=["es-ES","es-MX","es-AR","es-CO","pt-BR","pt-PT","en-US","en-GB","fr-FR","de-DE","it-IT"];function he(e){const t=w.usePlugin(),i=t.ui,l=t.stores.prefs,o=t.stores.speech,s=t.stores.engine,p=t.main(z),r=t.main(O),[a,d]=C.createSignal([]),[b,y]=C.createSignal(!1);C.onMount(()=>{p.diagnose().then(n=>{n.locales.length>0&&d(n.locales)}).catch(()=>{}),e.speaker.refreshVoices()});const E=()=>{const n=a(),h=l.value.locale;return(n.includes(h)?n:[h,...n]).map(L=>({value:L,label:L}))},S=()=>[{value:"",label:t.t("speech.voice.auto")},...e.speaker.voices().map(n=>({value:n.id,label:n.label}))],v=n=>{l.update(h=>{n.locale!==void 0&&(h.locale=n.locale),n.minConfidence!==void 0&&(h.minConfidence=n.minConfidence),n.trailingSpace!==void 0&&(h.trailingSpace=n.trailingSpace),n.autoFocus!==void 0&&(h.autoFocus=n.autoFocus)})},$=n=>{o.update(h=>{n.voiceURI!==void 0&&(h.voiceURI=n.voiceURI),n.rate!==void 0&&(h.rate=n.rate),n.skipCode!==void 0&&(h.skipCode=n.skipCode)})},N=n=>{s.update(h=>{h.mode=n})},u=async()=>{try{await r.toggle(),t.toast.show({variant:"default",title:t.t("settings.winh"),description:t.t("settings.winh.sent")})}catch(n){t.toast.show({variant:"error",title:t.t("pill.title"),description:n instanceof Error?n.message:t.t("error.winh")})}},m=async()=>{try{await e.speaker.preview()}catch(n){t.toast.show({variant:"error",title:t.t("read.title"),description:n instanceof Error?n.message:t.t("read.error")})}},f=async()=>{y(!0);try{const n=await p.diagnose();if(n.locales.length===0){t.toast.show({variant:"error",title:t.t("error.title"),description:t.t("settings.test.failed",{reason:t.t("common.reason.no-recognizers")}),persistent:!0});return}if(!n.microphone){t.toast.show({variant:"error",title:t.t("error.title"),description:t.t("settings.test.failed",{reason:t.t("common.reason.no-microphone")}),persistent:!0});return}n.locales.length>0&&!a().length&&d(n.locales),t.toast.show({variant:"success",title:t.t("error.title"),description:t.t("settings.test.success",{locale:n.selected||n.locales[0]||l.value.locale})})}catch(n){t.toast.show({variant:"error",title:t.t("error.title"),description:n instanceof Error?n.message:String(n)})}finally{y(!1)}};return g.createComponent(i.SettingsLayout,{get title(){return t.t("settings.title")},get description(){return t.t("settings.description")},get children(){return[g.createComponent(i.SettingsSection,{get title(){return t.t("settings.section")},get children(){return[g.createComponent(i.SettingsRow,{id:"engine",get title(){return t.t("settings.engine")},get description(){return t.t("settings.engine.description")},get children(){return g.createComponent(i.Select,{get label(){return t.t("settings.engine")},get value(){return s.value.mode},get options(){return[{value:"windows",label:t.t("engine.windows")},{value:"system",label:t.t("engine.system")}]},onChange:n=>N(n)})}}),g.createComponent(C.Show,{get when(){return s.value.mode==="windows"},get children(){return g.createComponent(i.SettingsRow,{id:"winh",get title(){return t.t("settings.winh")},get description(){return t.t("settings.winh.description")},get children(){return g.createComponent(i.Button,{onClick:()=>{u()},get children(){return t.t("settings.winh.run")}})}})}}),g.createComponent(C.Show,{get when(){return s.value.mode==="system"},get children(){return[g.createComponent(i.SettingsRow,{id:"language",get title(){return t.t("settings.language")},get description(){return t.t("settings.language.description")},get children(){return g.createComponent(i.Select,{get label(){return t.t("settings.language")},get value(){return l.value.locale},get options(){return g.memo(()=>E().length>0)()?E():ge.map(n=>({value:n,label:n}))},onChange:n=>v({locale:n})})}}),g.createComponent(i.SettingsRow,{id:"confidence",get title(){return t.t("settings.confidence")},get description(){return t.t("settings.confidence.description")},get children(){return g.createComponent(i.Select,{get label(){return t.t("settings.confidence")},get value(){return String(l.value.minConfidence)},get options(){return[{value:"0.2",label:t.t("confidence.low")},{value:"0.4",label:t.t("confidence.normal")},{value:"0.6",label:t.t("confidence.high")}]},onChange:n=>v({minConfidence:Number(n)||.4})})}}),g.createComponent(i.SettingsRow,{id:"space",get title(){return t.t("settings.space")},get description(){return t.t("settings.space.description")},get children(){return g.createComponent(i.Switch,{get label(){return t.t("settings.space")},hideLabel:!0,get checked(){return l.value.trailingSpace},onChange:n=>v({trailingSpace:n})})}}),g.createComponent(i.SettingsRow,{id:"focus",get title(){return t.t("settings.focus")},get description(){return t.t("settings.focus.description")},get children(){return g.createComponent(i.Switch,{get label(){return t.t("settings.focus")},hideLabel:!0,get checked(){return l.value.autoFocus},onChange:n=>v({autoFocus:n})})}})]}})]}}),g.createComponent(i.SettingsSection,{get title(){return t.t("speech.section")},get children(){return[g.createComponent(i.SettingsRow,{id:"voice",get title(){return t.t("speech.voice")},get description(){return t.t("speech.voice.description")},get children(){return g.createComponent(i.Select,{get label(){return t.t("speech.voice")},get value(){return o.value.voiceURI},get options(){return S()},onChange:n=>$({voiceURI:n})})}}),g.createComponent(i.SettingsRow,{id:"rate",get title(){return t.t("speech.rate")},get description(){return t.t("speech.rate.description")},get children(){return g.createComponent(i.Select,{get label(){return t.t("speech.rate")},get value(){return String(o.value.rate)},get options(){return[{value:"0.8",label:t.t("speech.rate.slow")},{value:"1",label:t.t("speech.rate.normal")},{value:"1.2",label:t.t("speech.rate.fast")},{value:"1.5",label:t.t("speech.rate.faster")}]},onChange:n=>$({rate:Number(n)||1})})}}),g.createComponent(i.SettingsRow,{id:"skip-code",get title(){return t.t("speech.skipCode")},get description(){return t.t("speech.skipCode.description")},get children(){return g.createComponent(i.Switch,{get label(){return t.t("speech.skipCode")},hideLabel:!0,get checked(){return o.value.skipCode},onChange:n=>$({skipCode:n})})}}),g.createComponent(i.SettingsRow,{id:"preview",get title(){return t.t("speech.preview")},get description(){return t.t("speech.preview.description")},get children(){return g.createComponent(i.Button,{onClick:()=>{m()},get children(){return t.t("read.idle")}})}})]}}),g.createComponent(i.SettingsSection,{get title(){return t.t("settings.test.section")},get children(){return g.createComponent(i.SettingsRow,{id:"test",get title(){return t.t("settings.test")},get description(){return t.t("settings.test.description")},get children(){return g.createComponent(i.Button,{get busy(){return b()},onClick:()=>{f()},get children(){return t.t("settings.test.run")}})}})}})]}})}const me=e=>{const t=e.main(z),i=e.main(U),l=e.main(O),o=ue(e,i),s=e.stores.prefs,p=e.stores.engine,[r,a]=C.createSignal(!1);let d;const b=(u,m,f)=>{switch(u){case"LANGUAGE_NOT_AVAILABLE":return e.t("error.language",{locale:m||s.value.locale,available:f.length>0?f.join(", "):"—"});case"NO_RECOGNIZERS":return e.t("error.none");case"MICROPHONE_UNAVAILABLE":return e.t("error.mic");case"SYSTEM_SPEECH_UNAVAILABLE":return e.t("error.system");case"ENGINE_EXIT":return e.t("error.exit");default:return e.t("error.unknown",{code:u})}},y=()=>{r()&&(a(!1),l.toggle().catch(()=>{})),o.cancel(),d=e.sessions.current()?.key,t.start({locale:s.value.locale,minConfidence:s.value.minConfidence}).catch(u=>{e.toast.show({variant:"error",title:e.t("error.title"),description:u instanceof Error?u.message:String(u)})})},E=()=>{t.stop().catch(()=>{})},S=()=>{o.cancel(),e.screen.current()?.composer.focus(),l.toggle().then(()=>a(u=>!u)).catch(u=>{a(!1),e.toast.show({variant:"error",title:e.t("pill.title"),description:u instanceof Error?`${e.t("error.winh")} ${u.message}`:e.t("error.winh")})})},v=()=>{if(p.value.mode==="windows"){S();return}const u=t.state()?.status??"idle";u==="starting"||u==="listening"?E():y()},$=()=>{if(o.speaking()){o.cancel();return}if(!e.sessions.current()){e.toast.show({variant:"error",title:e.t("read.title"),description:e.t("read.noSession")});return}const u=t.state()?.status??"idle";(u==="starting"||u==="listening")&&t.stop().catch(()=>{}),(async()=>{try{const m=await o.lastAssistantText();if(!m.trim()){e.toast.show({variant:"default",title:e.t("read.title"),description:e.t("read.empty")});return}await o.speak(m)||e.toast.show({variant:"default",title:e.t("read.title"),description:e.t("read.empty")})}catch(m){e.toast.show({variant:"error",title:e.t("read.title"),description:m instanceof Error?m.message:e.t("read.error")})}})()};t.on("final",u=>{const m=e.sessions.current()?.key;if(d&&m&&m!==d){e.toast.show({variant:"error",title:e.t("error.title"),description:e.t("toast.discarded")});return}const f=e.screen.current()?.composer;if(!f)return;const n=f.text(),h=s.value.trailingSpace&&n.length>0&&!/\s$/.test(n)?" ":"";f.insert(h+u.text),s.value.autoFocus&&f.focus()}),t.on("error",u=>{e.toast.show({variant:"error",title:e.t("error.title"),description:b(u.code,u.detail,u.available),persistent:u.code==="LANGUAGE_NOT_AVAILABLE"||u.code==="NO_RECOGNIZERS",duration:8e3})});const N=()=>{if(e.app.platform!=="desktop")return;if(p.value.mode==="windows")return r()?{label:e.t("pill.dictating"),icon:"outline-wave-audio",tone:"danger",title:e.t("pill.stop"),run:v}:{label:e.t("pill.idle"),icon:"outline-wave-audio",title:e.t("pill.winH"),run:v};const u=t.state()?.status??"idle";return u==="starting"?{label:e.t("pill.starting"),icon:"outline-wave-audio",title:e.t("pill.title"),run:v}:u==="listening"?{label:e.t("pill.listening"),icon:"outline-wave-audio",tone:"danger",title:e.t("pill.stop"),run:v}:u==="error"?{label:e.t("pill.error"),icon:"outline-wave-audio",tone:"warning",title:e.t("pill.title"),run:v}:{label:e.t("pill.idle"),icon:"outline-wave-audio",title:e.t("pill.title"),run:v}};e.add(w.ComposerPill,()=>({id:"dictate",show:()=>N()})),e.add(w.ComposerPill,()=>({id:"read",order:1,show:()=>{if(e.app.platform==="desktop")return o.speaking()?{label:e.t("read.speaking"),icon:"outline-audio",tone:"success",title:e.t("read.stop"),run:$}:{label:e.t("read.idle"),icon:"outline-audio",title:e.t("read.title"),run:$}}})),e.add(w.Command,()=>({id:"toggle",title:e.t("command.toggle"),description:e.t("command.toggle.description"),keywords:"voice dictation microphone speech dictado voz microfono",group:e.t("pill.title"),section:"prompt",bind:"mod+shift+m",slash:{name:"dictado"},editable:!0,enabled:e.app.platform==="desktop",run:v})),e.add(w.Command,()=>({id:"configure",title:e.t("command.configure"),keywords:"voice dictation microphone speech dictado voz microfono",group:e.t("pill.title"),enabled:e.app.platform==="desktop",run:()=>e.layout.settings(e.id)})),e.add(w.Command,()=>({id:"read",title:e.t("command.read"),description:e.t("command.read.description"),keywords:"read aloud speech voice leer voz altavoz lectura",group:e.t("pill.title"),section:"prompt",bind:"mod+shift+l",slash:{name:"leer"},editable:!0,enabled:e.app.platform==="desktop",run:$})),e.add(w.SettingsPage,{id:e.id,icon:"outline-audio",get title(){return e.t("settings.title")},get entries(){return[{id:"engine",title:e.t("settings.engine"),keywords:"engine motor dictation dictado winh voz"},{id:"winh",title:e.t("settings.winh"),keywords:"winh windows voice typing dictado"},{id:"language",title:e.t("settings.language"),keywords:"voice language idioma voz"},{id:"confidence",title:e.t("settings.confidence"),keywords:"voice confidence confianza"},{id:"test",title:e.t("settings.test"),keywords:"voice microphone microphone test microfono"},{id:"voice",title:e.t("speech.voice"),keywords:"read aloud voice voz lectura altavoz"},{id:"rate",title:e.t("speech.rate"),keywords:"read aloud speed velocidad lectura"},{id:"skip-code",title:e.t("speech.skipCode"),keywords:"read aloud code codigo lectura"},{id:"preview",title:e.t("speech.preview"),keywords:"read aloud test voice probar voz"}]},render:()=>g.createComponent(he,{speaker:o})})},fe=w.Plugin.define({...X,setup:me,main:ce});exports.default=fe;
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-voice-dictation",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Offline voice dictation and read-aloud for OpenCode Desktop on Windows",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Fran Carlos <francarlos803@gmail.com>",
|
|
7
|
+
"homepage": "https://github.com/evious/opencode-voice-dictation#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/evious/opencode-voice-dictation.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/evious/opencode-voice-dictation/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"opencode",
|
|
17
|
+
"opencode-plugin",
|
|
18
|
+
"voice",
|
|
19
|
+
"dictation",
|
|
20
|
+
"speech-to-text",
|
|
21
|
+
"text-to-speech",
|
|
22
|
+
"windows",
|
|
23
|
+
"offline"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./src/index.ts",
|
|
28
|
+
"./gui-experimental": "./dist/gui-experimental.cjs"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"src",
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
],
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "vite build",
|
|
41
|
+
"dev": "vite build --watch",
|
|
42
|
+
"test": "node test/smoke.cjs",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
44
|
+
"prepublishOnly": "npm run typecheck && npm run build && npm test"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@opencode/plugin": "2.2.6",
|
|
48
|
+
"effect": "4.1.0",
|
|
49
|
+
"@types/node": "^24.0.0",
|
|
50
|
+
"solid-js": "^1.9.17",
|
|
51
|
+
"typescript": "^5.9.0",
|
|
52
|
+
"vite": "^7.3.0",
|
|
53
|
+
"vite-plugin-solid": "^2.11.0"
|
|
54
|
+
}
|
|
55
|
+
}
|