opencode-voice-dictation 0.1.0 → 0.3.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/README.md +39 -14
- package/dist/gui-experimental.cjs +34 -7
- package/package.json +5 -2
- package/src/gui/contract.ts +12 -2
- package/src/gui/definition.ts +39 -2
- package/src/gui/engines/win-h.ts +80 -0
- package/src/gui/main.ts +8 -1
- package/src/gui/settings.tsx +93 -40
- package/src/gui/speak.ts +47 -1
- package/src/gui/window.tsx +98 -17
package/README.md
CHANGED
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
Plugin de [OpenCode](https://opencode.ai) V2 que añade voz a la app de
|
|
4
4
|
escritorio:
|
|
5
5
|
|
|
6
|
-
- **Dictado**: pulsas la píldora
|
|
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.
|
|
7
9
|
- **Lectura**: pulsa «Leer» y reproduce en voz alta la última respuesta.
|
|
8
10
|
|
|
9
|
-
- **Dictado
|
|
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
|
|
11
15
|
cursor, sin robar el foco ni simular `Ctrl+V`.
|
|
12
16
|
- **Lectura local**: voces del sistema (`speechSynthesis`), con respaldo a
|
|
13
17
|
`System.Speech.Synthesis` si Electron no expone voces.
|
|
@@ -60,6 +64,11 @@ experimental (`gui-experimental`) y puede cambiar entre versiones de OpenCode.
|
|
|
60
64
|
El motor vive en el proceso `main` de Electron porque necesita
|
|
61
65
|
`node:child_process`. La ventana solo pinta el estado y escribe el texto.
|
|
62
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
|
+
|
|
63
72
|
## Requisitos
|
|
64
73
|
|
|
65
74
|
- OpenCode Desktop en **Windows 10/11**.
|
|
@@ -131,11 +140,13 @@ en cada cambio y OpenCode Desktop recarga el plugin solo.
|
|
|
131
140
|
| Ajustes | Ajustes → Dictado por voz, o paleta: "Ajustes de dictado por voz" |
|
|
132
141
|
|
|
133
142
|
La píldora del micrófono muestra el estado: `Dictar`, `Iniciando…`,
|
|
134
|
-
`Escuchando…` (
|
|
143
|
+
`Escuchando…` (System.Speech), `Dictando…` (Win+H) y `Reintentar dictado` si
|
|
144
|
+
algo falla.
|
|
135
145
|
|
|
136
|
-
La píldora «Leer» cambia a `Leyendo
|
|
137
|
-
|
|
138
|
-
|
|
146
|
+
La píldora «Leer» cambia a `Leyendo…`. Mientras lee, al pulsarla se abre un
|
|
147
|
+
menú con **Pausar / Reanudar**, **Leer de nuevo** y **Detener**. La pausa
|
|
148
|
+
continúa exactamente donde se quedó. Dictar detiene la lectura y leer detiene el
|
|
149
|
+
dictado, para que el micrófono no capture la voz del altavoz.
|
|
139
150
|
|
|
140
151
|
El texto se inserta en la posición del cursor. Si ya hay texto y no termina en
|
|
141
152
|
espacio, se añade uno de separación (configurable).
|
|
@@ -144,11 +155,13 @@ espacio, se añade uno de separación (configurable).
|
|
|
144
155
|
|
|
145
156
|
| Ajuste | Por defecto | Qué hace |
|
|
146
157
|
|---|---|---|
|
|
147
|
-
|
|
|
148
|
-
|
|
|
149
|
-
|
|
|
150
|
-
|
|
|
151
|
-
|
|
|
158
|
+
| Motor de dictado | Windows Voice Typing (Win+H) | Usa el dictado de Windows 11, más preciso. `System.Speech` es la alternativa offline. |
|
|
159
|
+
| Probar Win+H | — | Envía el atajo y comprueba que Windows abre su barra de dictado. |
|
|
160
|
+
| Idioma | `es-ES` | Solo para `System.Speech`. Reconocedor instalado en Windows. Si no existe el exacto, usa el mismo idioma base. |
|
|
161
|
+
| Confianza mínima | 0,4 | Solo para `System.Speech`. Descarta resultados con menor confianza. |
|
|
162
|
+
| Espacio antes del texto | Sí | Solo para `System.Speech`. Separa el dictado de lo que ya hay escrito. |
|
|
163
|
+
| Enfocar el prompt al terminar | Sí | Solo para `System.Speech`. Mueve el cursor al prompt tras cada frase. |
|
|
164
|
+
| Probar micrófono | — | Solo para `System.Speech`. Lista los idiomas instalados y comprueba el micrófono. |
|
|
152
165
|
|
|
153
166
|
### Lectura en voz alta
|
|
154
167
|
|
|
@@ -163,6 +176,10 @@ La lectura limpia el Markdown antes de hablar: quita fences, backticks,
|
|
|
163
176
|
negritas, encabezados, viñetas y convierte `[texto](url)` en `texto`. Trocea el
|
|
164
177
|
texto por frases para poder detenerse rápido.
|
|
165
178
|
|
|
179
|
+
La pausa usa `speechSynthesis.pause()` / `resume()`. Con el motor de respaldo de
|
|
180
|
+
PowerShell (SAPI) no hay pausa real: el menú muestra solo «Leer de nuevo» y
|
|
181
|
+
«Detener».
|
|
182
|
+
|
|
166
183
|
## Permisos
|
|
167
184
|
|
|
168
185
|
El plugin es local y no hace peticiones de red. Para funcionar:
|
|
@@ -180,7 +197,10 @@ bloqueas el micrófono, verás el aviso «No hay ningún micrófono disponible»
|
|
|
180
197
|
|
|
181
198
|
| Síntoma | Causa / solución |
|
|
182
199
|
|---|---|
|
|
183
|
-
| «
|
|
200
|
+
| 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. |
|
|
201
|
+
| 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. |
|
|
202
|
+
| Quiero dictado sin Win+H | Cambia **Motor de dictado** a `System.Speech (offline)`. |
|
|
203
|
+
| «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. |
|
|
184
204
|
| «Windows no tiene ningún reconocedor de voz instalado» | Mismo caso: no hay ningún idioma de voz instalado. |
|
|
185
205
|
| «No hay ningún micrófono disponible» | Revisa Configuración → Sistema → Sonido → Entrada y el micrófono predeterminado. |
|
|
186
206
|
| El motor se detiene inesperadamente | Otro proceso puede estar usando el micrófono en modo exclusivo. Ejecuta la prueba de micrófono en Ajustes. |
|
|
@@ -199,7 +219,12 @@ de la app muestran los más importantes.
|
|
|
199
219
|
cambiar entre versiones de OpenCode.
|
|
200
220
|
- `System.Speech` no añade puntuación ni mayúsculas automáticamente y su
|
|
201
221
|
precisión es inferior a Whisper o al dictado nativo de Windows 11.
|
|
202
|
-
-
|
|
222
|
+
- El modo Win+H envía la combinación con `keybd_event`. Kaspersky o la
|
|
223
|
+
protección UIPI de Windows pueden bloquearla; en ese caso usa `System.Speech`.
|
|
224
|
+
- Con Win+H el texto lo escribe Windows en el campo enfocado: el plugin no
|
|
225
|
+
puede descartarlo si cambias de sesión ni limpiarlo.
|
|
226
|
+
- No hay resultados parciales con `System.Speech`: el texto aparece al terminar
|
|
227
|
+
cada frase.
|
|
203
228
|
- La lectura usa las voces del sistema; si Electron no las expone, el respaldo
|
|
204
229
|
por PowerShell usa las voces SAPI, con una latencia de arranque de ~0,5 s.
|
|
205
230
|
- La lectura empieza con el mensaje tal como esté en ese momento: si el agente
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const b=require("@opencode/plugin/gui"),d=require("effect"),A=require("node:child_process"),z=require("node:crypto"),R=require("node:fs"),D=require("node:os"),T=require("node:path"),m=require("solid-js/web"),N=require("solid-js"),X=b.Plugin.define({os:["windows"],stores:{prefs:b.Store.global(d.Schema.Struct({locale:d.Schema.String,minConfidence:d.Schema.Number,trailingSpace:d.Schema.Boolean,autoFocus:d.Schema.Boolean}),{locale:"es-ES",minConfidence:.4,trailingSpace:!0,autoFocus:!0}),speech:b.Store.global(d.Schema.Struct({voiceURI:d.Schema.String,rate:d.Schema.Number,skipCode:d.Schema.Boolean}),{voiceURI:"",rate:1,skipCode:!0})},i18n:{en:{"pill.idle":"Dictate","pill.starting":"Starting…","pill.listening":"Listening…","pill.error":"Retry dictation","pill.title":"Voice dictation","pill.stop":"Stop dictation","command.toggle":"Toggle voice dictation","command.toggle.description":"Transcribe what you say into the prompt","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.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.error":"Reintentar dictado","pill.title":"Dictado por voz","pill.stop":"Detener dictado","command.toggle":"Alternar dictado por voz","command.toggle.description":"Transcribe lo que dices en el prompt","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.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."}}}),O=b.Ipc.define({id:"voice-dictation.dictation",state:d.Schema.Struct({status:d.Schema.Literals(["idle","starting","listening","error"]),error:d.Schema.String,locale:d.Schema.String}),methods:{start:{input:d.Schema.Struct({locale:d.Schema.String,minConfidence:d.Schema.Number})},stop:{},diagnose:{output:d.Schema.Struct({locales:d.Schema.Array(d.Schema.String),microphone:d.Schema.Boolean,selected:d.Schema.String,error:d.Schema.String})}},events:{final:d.Schema.Struct({text:d.Schema.String,confidence:d.Schema.Number}),error:d.Schema.Struct({code:d.Schema.String,detail:d.Schema.String,available:d.Schema.Array(d.Schema.String)})}}),V=b.Ipc.define({id:"voice-dictation.speech",methods:{speak:{input:d.Schema.Struct({text:d.Schema.String,rate:d.Schema.Number,voice:d.Schema.String})},stop:{},voices:{output:d.Schema.Array(d.Schema.String)}},events:{done:d.Schema.Struct({ok:d.Schema.Boolean})}}),F=String.raw`param(
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const v=require("@opencode/plugin/gui"),l=require("effect"),W=require("node:child_process"),z=require("node:crypto"),A=require("node:fs"),F=require("node:os"),P=require("node:path"),g=require("solid-js/web"),R=require("solid-js"),ie=v.Plugin.define({os:["windows"],stores:{prefs:v.Store.global(l.Schema.Struct({locale:l.Schema.String,minConfidence:l.Schema.Number,trailingSpace:l.Schema.Boolean,autoFocus:l.Schema.Boolean}),{locale:"es-ES",minConfidence:.4,trailingSpace:!0,autoFocus:!0}),speech:v.Store.global(l.Schema.Struct({voiceURI:l.Schema.String,rate:l.Schema.Number,skipCode:l.Schema.Boolean}),{voiceURI:"",rate:1,skipCode:!0}),engine:v.Store.global(l.Schema.Struct({mode:l.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.paused":"Paused","read.pause":"Pause","read.resume":"Resume","read.restart":"Read again","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.paused":"Pausado","read.pause":"Pausar","read.resume":"Reanudar","read.restart":"Leer de nuevo","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."}}}),D=v.Ipc.define({id:"voice-dictation.dictation",state:l.Schema.Struct({status:l.Schema.Literals(["idle","starting","listening","error"]),error:l.Schema.String,locale:l.Schema.String}),methods:{start:{input:l.Schema.Struct({locale:l.Schema.String,minConfidence:l.Schema.Number})},stop:{},diagnose:{output:l.Schema.Struct({locales:l.Schema.Array(l.Schema.String),microphone:l.Schema.Boolean,selected:l.Schema.String,error:l.Schema.String})}},events:{final:l.Schema.Struct({text:l.Schema.String,confidence:l.Schema.Number}),error:l.Schema.Struct({code:l.Schema.String,detail:l.Schema.String,available:l.Schema.Array(l.Schema.String)})}}),q=v.Ipc.define({id:"voice-dictation.speech",methods:{speak:{input:l.Schema.Struct({text:l.Schema.String,rate:l.Schema.Number,voice:l.Schema.String})},stop:{},voices:{output:l.Schema.Array(l.Schema.String)}},events:{done:l.Schema.Struct({ok:l.Schema.Boolean})}}),H=v.Ipc.define({id:"voice-dictation.voice-typing",methods:{toggle:{}}}),j=String.raw`param(
|
|
2
2
|
[string]$Culture = "es-ES",
|
|
3
3
|
[double]$MinConfidence = 0.4,
|
|
4
4
|
[switch]$Diagnose
|
|
@@ -105,9 +105,9 @@ while ($true) {
|
|
|
105
105
|
Start-Sleep -Milliseconds 250
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
`,
|
|
109
|
-
`);for(;a>=0;){const
|
|
110
|
-
`)}}),i.stderr?.setEncoding("utf8"),i.stderr?.on("data",
|
|
108
|
+
`,ne="powershell.exe";function K(){const e=P.join(F.tmpdir(),"opencode-voice-dictation");A.mkdirSync(e,{recursive:!0});const t=z.createHash("sha1").update(j).digest("hex").slice(0,12),i=P.join(e,`dictation-${t}.ps1`);return A.writeFileSync(i,j,"utf8"),i}function Z(e){return W.spawn(ne,e,{windowsHide:!0,stdio:["ignore","pipe","pipe"]})}function X(e){const t=e.pid;if(t===void 0){e.kill();return}W.spawn("taskkill",["/PID",String(t),"/T","/F"],{windowsHide:!0,stdio:"ignore"}).on("error",()=>e.kill())}function oe(e,t){const i=Z(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",K(),"-Culture",e.locale,"-MinConfidence",String(e.minConfidence)]);let c=!1,o="",r="";const p=s=>{switch(s.type){case"ready":t.onReady(s.locale??e.locale);break;case"final":s.text&&t.onFinal(s.text,s.confidence??0);break;case"error":t.onError(s.code??"UNKNOWN",s.detail??"",s.available??[]);break}};return i.stdout?.setEncoding("utf8"),i.stdout?.on("data",s=>{r+=s;let a=r.indexOf(`
|
|
109
|
+
`);for(;a>=0;){const d=r.slice(0,a).replace(/\r$/,"").trim();if(r=r.slice(a+1),d)try{p(JSON.parse(d))}catch{}a=r.indexOf(`
|
|
110
|
+
`)}}),i.stderr?.setEncoding("utf8"),i.stderr?.on("data",s=>{o=(o+s).slice(-2e3)}),i.on("error",s=>{c||t.onError("ENGINE_START_FAILED",s.message,[])}),i.on("close",s=>{c||t.onExit(s,o.trim().slice(-500))}),{stop(){c=!0,X(i)}}}function re(){return new Promise((e,t)=>{const i=Z(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",K(),"-Diagnose"]);let c="",o="",r=!1;const p=(a,d)=>{r||(r=!0,clearTimeout(s),a?t(a):e(d))},s=setTimeout(()=>{X(i),p(new Error("diagnose timed out"))},2e4);i.stdout?.setEncoding("utf8"),i.stdout?.on("data",a=>{c+=a}),i.stderr?.setEncoding("utf8"),i.stderr?.on("data",a=>{o+=a}),i.on("error",a=>p(a)),i.on("close",()=>{const a=c.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 M=String.raw`param(
|
|
111
111
|
[string]$TextFile = "",
|
|
112
112
|
[int]$Rate = 0,
|
|
113
113
|
[string]$Voice = "",
|
|
@@ -160,6 +160,33 @@ try {
|
|
|
160
160
|
} catch { }
|
|
161
161
|
|
|
162
162
|
$synth.Dispose()
|
|
163
|
-
`,
|
|
164
|
-
|
|
165
|
-
`)};return t.on("done",()=>r(!1)),w()?.addEventListener?.("voiceschanged",()=>{u()}),u(),{speaking:c,backend:o,voices:s,refreshVoices:u,lastAssistantText:n,speak:C,cancel:h,preview:()=>C(e.t("speech.preview.text"))}}const ae=["es-ES","es-MX","es-AR","es-CO","pt-BR","pt-PT","en-US","en-GB","fr-FR","de-DE","it-IT"];function ce(e){const t=b.usePlugin(),i=t.ui,c=t.stores.prefs,r=t.stores.speech,s=t.main(O),[g,o]=N.createSignal([]),[a,l]=N.createSignal(!1);N.onMount(()=>{s.diagnose().then(n=>{n.locales.length>0&&o(n.locales)}).catch(()=>{}),e.speaker.refreshVoices()});const S=()=>{const n=g(),E=c.value.locale;return(n.includes(E)?n:[E,...n]).map(f=>({value:f,label:f}))},w=()=>[{value:"",label:t.t("speech.voice.auto")},...e.speaker.voices().map(n=>({value:n.id,label:n.label}))],p=n=>{c.update(E=>{n.locale!==void 0&&(E.locale=n.locale),n.minConfidence!==void 0&&(E.minConfidence=n.minConfidence),n.trailingSpace!==void 0&&(E.trailingSpace=n.trailingSpace),n.autoFocus!==void 0&&(E.autoFocus=n.autoFocus)})},u=n=>{r.update(E=>{n.voiceURI!==void 0&&(E.voiceURI=n.voiceURI),n.rate!==void 0&&(E.rate=n.rate),n.skipCode!==void 0&&(E.skipCode=n.skipCode)})},h=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")})}},C=async()=>{l(!0);try{const n=await s.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&&!g().length&&o(n.locales),t.toast.show({variant:"success",title:t.t("error.title"),description:t.t("settings.test.success",{locale:n.selected||n.locales[0]||c.value.locale})})}catch(n){t.toast.show({variant:"error",title:t.t("error.title"),description:n instanceof Error?n.message:String(n)})}finally{l(!1)}};return m.createComponent(i.SettingsLayout,{get title(){return t.t("settings.title")},get description(){return t.t("settings.description")},get children(){return[m.createComponent(i.SettingsSection,{get title(){return t.t("settings.section")},get children(){return[m.createComponent(i.SettingsRow,{id:"language",get title(){return t.t("settings.language")},get description(){return t.t("settings.language.description")},get children(){return m.createComponent(i.Select,{get label(){return t.t("settings.language")},get value(){return c.value.locale},get options(){return m.memo(()=>S().length>0)()?S():ae.map(n=>({value:n,label:n}))},onChange:n=>p({locale:n})})}}),m.createComponent(i.SettingsRow,{id:"confidence",get title(){return t.t("settings.confidence")},get description(){return t.t("settings.confidence.description")},get children(){return m.createComponent(i.Select,{get label(){return t.t("settings.confidence")},get value(){return String(c.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=>p({minConfidence:Number(n)||.4})})}}),m.createComponent(i.SettingsRow,{id:"space",get title(){return t.t("settings.space")},get description(){return t.t("settings.space.description")},get children(){return m.createComponent(i.Switch,{get label(){return t.t("settings.space")},hideLabel:!0,get checked(){return c.value.trailingSpace},onChange:n=>p({trailingSpace:n})})}}),m.createComponent(i.SettingsRow,{id:"focus",get title(){return t.t("settings.focus")},get description(){return t.t("settings.focus.description")},get children(){return m.createComponent(i.Switch,{get label(){return t.t("settings.focus")},hideLabel:!0,get checked(){return c.value.autoFocus},onChange:n=>p({autoFocus:n})})}})]}}),m.createComponent(i.SettingsSection,{get title(){return t.t("speech.section")},get children(){return[m.createComponent(i.SettingsRow,{id:"voice",get title(){return t.t("speech.voice")},get description(){return t.t("speech.voice.description")},get children(){return m.createComponent(i.Select,{get label(){return t.t("speech.voice")},get value(){return r.value.voiceURI},get options(){return w()},onChange:n=>u({voiceURI:n})})}}),m.createComponent(i.SettingsRow,{id:"rate",get title(){return t.t("speech.rate")},get description(){return t.t("speech.rate.description")},get children(){return m.createComponent(i.Select,{get label(){return t.t("speech.rate")},get value(){return String(r.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=>u({rate:Number(n)||1})})}}),m.createComponent(i.SettingsRow,{id:"skip-code",get title(){return t.t("speech.skipCode")},get description(){return t.t("speech.skipCode.description")},get children(){return m.createComponent(i.Switch,{get label(){return t.t("speech.skipCode")},hideLabel:!0,get checked(){return r.value.skipCode},onChange:n=>u({skipCode:n})})}}),m.createComponent(i.SettingsRow,{id:"preview",get title(){return t.t("speech.preview")},get description(){return t.t("speech.preview.description")},get children(){return m.createComponent(i.Button,{onClick:()=>{h()},get children(){return t.t("read.idle")}})}})]}}),m.createComponent(i.SettingsSection,{get title(){return t.t("settings.test.section")},get children(){return m.createComponent(i.SettingsRow,{id:"test",get title(){return t.t("settings.test")},get description(){return t.t("settings.test.description")},get children(){return m.createComponent(i.Button,{get busy(){return a()},onClick:()=>{C()},get children(){return t.t("settings.test.run")}})}})}})]}})}const le=e=>{const t=e.main(O),i=e.main(V),c=se(e,i),r=e.stores.prefs;let s;const g=(p,u,h)=>{switch(p){case"LANGUAGE_NOT_AVAILABLE":return e.t("error.language",{locale:u||r.value.locale,available:h.length>0?h.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:p})}},o=()=>{c.cancel(),s=e.sessions.current()?.key,t.start({locale:r.value.locale,minConfidence:r.value.minConfidence}).catch(p=>{e.toast.show({variant:"error",title:e.t("error.title"),description:p instanceof Error?p.message:String(p)})})},a=()=>{t.stop().catch(()=>{})},l=()=>{const p=t.state()?.status??"idle";p==="starting"||p==="listening"?a():o()},S=()=>{if(c.speaking()){c.cancel();return}if(!e.sessions.current()){e.toast.show({variant:"error",title:e.t("read.title"),description:e.t("read.noSession")});return}const p=t.state()?.status??"idle";(p==="starting"||p==="listening")&&t.stop().catch(()=>{}),(async()=>{try{const u=await c.lastAssistantText();if(!u.trim()){e.toast.show({variant:"default",title:e.t("read.title"),description:e.t("read.empty")});return}await c.speak(u)||e.toast.show({variant:"default",title:e.t("read.title"),description:e.t("read.empty")})}catch(u){e.toast.show({variant:"error",title:e.t("read.title"),description:u instanceof Error?u.message:e.t("read.error")})}})()};t.on("final",p=>{const u=e.sessions.current()?.key;if(s&&u&&u!==s){e.toast.show({variant:"error",title:e.t("error.title"),description:e.t("toast.discarded")});return}const h=e.screen.current()?.composer;if(!h)return;const C=h.text(),n=r.value.trailingSpace&&C.length>0&&!/\s$/.test(C)?" ":"";h.insert(n+p.text),r.value.autoFocus&&h.focus()}),t.on("error",p=>{e.toast.show({variant:"error",title:e.t("error.title"),description:g(p.code,p.detail,p.available),persistent:p.code==="LANGUAGE_NOT_AVAILABLE"||p.code==="NO_RECOGNIZERS",duration:8e3})});const w=()=>{if(e.app.platform!=="desktop")return;const p=t.state()?.status??"idle";return p==="starting"?{label:e.t("pill.starting"),icon:"outline-wave-audio",title:e.t("pill.title"),run:l}:p==="listening"?{label:e.t("pill.listening"),icon:"outline-wave-audio",tone:"danger",title:e.t("pill.stop"),run:l}:p==="error"?{label:e.t("pill.error"),icon:"outline-wave-audio",tone:"warning",title:e.t("pill.title"),run:l}:{label:e.t("pill.idle"),icon:"outline-wave-audio",title:e.t("pill.title"),run:l}};e.add(b.ComposerPill,()=>({id:"dictate",show:()=>w()})),e.add(b.ComposerPill,()=>({id:"read",order:1,show:()=>{if(e.app.platform==="desktop")return c.speaking()?{label:e.t("read.speaking"),icon:"outline-audio",tone:"success",title:e.t("read.stop"),run:S}:{label:e.t("read.idle"),icon:"outline-audio",title:e.t("read.title"),run:S}}})),e.add(b.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:l})),e.add(b.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(b.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:S})),e.add(b.SettingsPage,{id:e.id,icon:"outline-audio",get title(){return e.t("settings.title")},get entries(){return[{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:()=>m.createComponent(ce,{speaker:c})})},de=b.Plugin.define({...X,setup:le,main:ie});exports.default=de;
|
|
163
|
+
`,se="powershell.exe";function Y(){const e=P.join(F.tmpdir(),"opencode-voice-dictation");return A.mkdirSync(e,{recursive:!0}),e}function J(){const e=z.createHash("sha1").update(M).digest("hex").slice(0,12),t=P.join(Y(),`speak-${e}.ps1`);return A.writeFileSync(t,M,"utf8"),t}function ae(e){const t=P.join(Y(),`speech-${z.randomUUID()}.txt`);return A.writeFileSync(t,e,"utf8"),t}function Q(e){return W.spawn(se,e,{windowsHide:!0,stdio:["ignore","pipe","pipe"]})}function x(e){const t=e.pid;if(t===void 0){e.kill();return}W.spawn("taskkill",["/PID",String(t),"/T","/F"],{windowsHide:!0,stdio:"ignore"}).on("error",()=>e.kill())}function ce(e){return Math.max(-10,Math.min(10,Math.round((e-1)*5)))}function le(e,t){const i=ae(e.text),c=Q(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",J(),"-TextFile",i,"-Rate",String(ce(e.rate)),"-Voice",e.voice]);let o=!1;const r=()=>{try{A.rmSync(i,{force:!0})}catch{}};return c.on("error",()=>{r(),o||t(!1)}),c.on("close",p=>{r(),o||t(p===0)}),{stop(){o=!0,x(c),r()}}}function de(){return new Promise(e=>{const t=Q(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",J(),"-ListVoices"]);let i="",c=!1;const o=p=>{c||(c=!0,clearTimeout(r),e(p))},r=setTimeout(()=>{x(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(s=>s.trim()).filter(s=>s.length>0);o(p)})})}const G=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
|
+
`,pe="powershell.exe";function ue(){const e=P.join(F.tmpdir(),"opencode-voice-dictation");A.mkdirSync(e,{recursive:!0});const t=z.createHash("sha1").update(G).digest("hex").slice(0,12),i=P.join(e,`win-h-${t}.ps1`);return A.writeFileSync(i,G,"utf8"),i}function ge(e){return W.spawn(pe,e,{windowsHide:!0,stdio:"ignore"})}function me(){return new Promise((e,t)=>{const i=ge(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",ue()]);i.on("error",c=>t(c)),i.on("close",c=>{c===0?e():t(new Error(`Win+H helper exited with code ${c??"unknown"}`))})})}const he=e=>{let t="idle",i="",c="",o,r=!1;const p=()=>{o=void 0,r=!1},s=e.provide(D,{state:()=>({status:t,error:i,locale:c}),start(b,k){o&&(r=!0,o.stop(),p()),t="starting",i="",c=b.locale,s.changed();const I=k.window;try{o=oe({locale:b.locale,minConfidence:b.minConfidence},{onReady(h){t="listening",c=h,s.changed()},onFinal(h,m){s.emit("final",{text:h,confidence:m},I)},onError(h,m,T){t="error",i=h,s.changed(),s.emit("error",{code:h,detail:m,available:T},I)},onExit(h,m){if(r){p(),t="idle",i="",c="",s.changed();return}p(),t!=="error"&&(t="error",i=h===null?"ENGINE_EXIT":`ENGINE_EXIT_${h}`,s.changed(),s.emit("error",{code:"ENGINE_EXIT",detail:m||(h===null?"":String(h)),available:[]},I))}})}catch(h){throw t="error",i="ENGINE_START_FAILED",s.changed(),h}},stop(){o&&(r=!0,o.stop(),p()),t="idle",i="",c="",s.changed()},diagnose(){return re()}});let a;const d=e.provide(q,{speak(b){a?.stop(),a=le(b,k=>{a=void 0,d.emit("done",{ok:k})})},stop(){a&&(a.stop(),a=void 0),d.emit("done",{ok:!0})},voices(){return de()}});e.provide(H,{toggle(){return me()}}),e.onCleanup(()=>{o&&(r=!0,o.stop(),p()),a?.stop(),a=void 0})},fe=250;function Se(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 ve(e,t=fe){const i=e.trim();if(!i)return[];const c=i.split(new RegExp("(?<=[.!?…])\\s+")),o=[];let r="";const p=s=>{let a="";for(const d of s.split(/\s+/))d&&(a&&a.length+1+d.length>t?(o.push(a),a=d):a=a?`${a} ${d}`:d);return a};for(const s of c){if(s.length>t){r&&(o.push(r),r=""),r=p(s);continue}r&&r.length+1+s.length>t?(o.push(r),r=s):r=r?`${r} ${s}`:s}return r&&o.push(r),o}function we(e,t){const i=e.stores.speech,[c,o]=R.createSignal(!1),[r,p]=R.createSignal(!1),[s,a]=R.createSignal([]),[d,b]=R.createSignal("none");let k=0,I=[],h="";const m=()=>typeof globalThis.speechSynthesis<"u"?globalThis.speechSynthesis:void 0,T=()=>{const w=m()?.getVoices()??[];if(w.length===0)return;const y=i.value.voiceURI;if(y){const C=w.find(O=>O.voiceURI===y);if(C)return C}const E=e.locale.locale().split("-")[0]?.toLowerCase()??"es";return w.find(C=>C.lang.toLowerCase().startsWith(E))??w[0]},N=async()=>{const w=m()?.getVoices()??[];if(w.length>0){a(w.map(y=>({id:y.voiceURI,label:`${y.name} — ${y.lang}`}))),b("web");return}try{const y=await t.voices();if(y.length>0){a(y.map(E=>({id:E,label:E}))),b("sapi");return}}catch{}b("none")},u=()=>{k++,I=[],m()?.cancel(),p(!1),o(!1),t.stop().catch(()=>{})},f=()=>d()==="web",$=()=>{!c()||r()||!f()||(m()?.pause(),p(!0))},n=()=>{!c()||!r()||!f()||(m()?.resume(),p(!1))},S=()=>{r()?n():$()},U=()=>h?L(h):Promise.resolve(!1),L=async w=>{h=w;const y=Se(w,i.value.skipCode);if(!y)return!1;if(u(),await N(),d()==="web"){const E=m();if(!E)return!1;const C=T(),O=i.value.rate,te=k;I=ve(y),o(!0),p(!1);const V=()=>{if(te!==k)return;const B=I.shift();if(!B){p(!1),o(!1);return}const _=new SpeechSynthesisUtterance(B);C&&(_.voice=C),C?.lang&&(_.lang=C.lang),_.rate=O,_.onend=V,_.onerror=V,E.speak(_)};return V(),!0}if(d()==="sapi"){o(!0),p(!1);try{await t.speak({text:y,rate:i.value.rate,voice:i.value.voiceURI})}catch(E){throw o(!1),E}return!0}throw o(!1),new Error(e.t("read.noVoices"))},ee=async()=>{const w=e.sessions.current();if(!w)return"";const E=(await w.server.client.message.list({sessionID:w.id,type:"assistant",order:"desc",limit:1})).data[0];return!E||E.type!=="assistant"?"":E.content.filter(C=>C.type==="text").map(C=>C.text).join(`
|
|
192
|
+
`)};return t.on("done",()=>{p(!1),o(!1)}),m()?.addEventListener?.("voiceschanged",()=>{N()}),N(),{speaking:c,paused:r,backend:d,canPause:f,voices:s,refreshVoices:N,lastAssistantText:ee,speak:L,cancel:u,pause:$,resume:n,togglePause:S,restart:U,preview:()=>L(e.t("speech.preview.text"))}}const ye=["es-ES","es-MX","es-AR","es-CO","pt-BR","pt-PT","en-US","en-GB","fr-FR","de-DE","it-IT"];function be(e){const t=v.usePlugin(),i=t.ui,c=t.stores.prefs,o=t.stores.speech,r=t.stores.engine,p=t.main(D),s=t.main(H),[a,d]=R.createSignal([]),[b,k]=R.createSignal(!1);R.onMount(()=>{p.diagnose().then(n=>{n.locales.length>0&&d(n.locales)}).catch(()=>{}),e.speaker.refreshVoices()});const I=()=>{const n=a(),S=c.value.locale;return(n.includes(S)?n:[S,...n]).map(L=>({value:L,label:L}))},h=()=>[{value:"",label:t.t("speech.voice.auto")},...e.speaker.voices().map(n=>({value:n.id,label:n.label}))],m=n=>{c.update(S=>{n.locale!==void 0&&(S.locale=n.locale),n.minConfidence!==void 0&&(S.minConfidence=n.minConfidence),n.trailingSpace!==void 0&&(S.trailingSpace=n.trailingSpace),n.autoFocus!==void 0&&(S.autoFocus=n.autoFocus)})},T=n=>{o.update(S=>{n.voiceURI!==void 0&&(S.voiceURI=n.voiceURI),n.rate!==void 0&&(S.rate=n.rate),n.skipCode!==void 0&&(S.skipCode=n.skipCode)})},N=n=>{r.update(S=>{S.mode=n})},u=async()=>{try{await s.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")})}},f=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")})}},$=async()=>{k(!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]||c.value.locale})})}catch(n){t.toast.show({variant:"error",title:t.t("error.title"),description:n instanceof Error?n.message:String(n)})}finally{k(!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 r.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(R.Show,{get when(){return r.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(R.Show,{get when(){return r.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 c.value.locale},get options(){return g.memo(()=>I().length>0)()?I():ye.map(n=>({value:n,label:n}))},onChange:n=>m({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(c.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=>m({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 c.value.trailingSpace},onChange:n=>m({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 c.value.autoFocus},onChange:n=>m({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 h()},onChange:n=>T({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=>T({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=>T({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:()=>{f()},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:()=>{$()},get children(){return t.t("settings.test.run")}})}})}})]}})}const $e=e=>{const t=e.main(D),i=e.main(q),c=e.main(H),o=we(e,i),r=e.stores.prefs,p=e.stores.engine,[s,a]=R.createSignal(!1);let d;const b=(u,f,$)=>{switch(u){case"LANGUAGE_NOT_AVAILABLE":return e.t("error.language",{locale:f||r.value.locale,available:$.length>0?$.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})}},k=()=>{s()&&(a(!1),c.toggle().catch(()=>{})),o.cancel(),d=e.sessions.current()?.key,t.start({locale:r.value.locale,minConfidence:r.value.minConfidence}).catch(u=>{e.toast.show({variant:"error",title:e.t("error.title"),description:u instanceof Error?u.message:String(u)})})},I=()=>{t.stop().catch(()=>{})},h=()=>{o.cancel(),e.screen.current()?.composer.focus(),c.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")})})},m=()=>{if(p.value.mode==="windows"){h();return}const u=t.state()?.status??"idle";u==="starting"||u==="listening"?I():k()},T=()=>{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 f=await o.lastAssistantText();if(!f.trim()){e.toast.show({variant:"default",title:e.t("read.title"),description:e.t("read.empty")});return}await o.speak(f)||e.toast.show({variant:"default",title:e.t("read.title"),description:e.t("read.empty")})}catch(f){e.toast.show({variant:"error",title:e.t("read.title"),description:f instanceof Error?f.message:e.t("read.error")})}})()};t.on("final",u=>{const f=e.sessions.current()?.key;if(d&&f&&f!==d){e.toast.show({variant:"error",title:e.t("error.title"),description:e.t("toast.discarded")});return}const $=e.screen.current()?.composer;if(!$)return;const n=$.text(),S=r.value.trailingSpace&&n.length>0&&!/\s$/.test(n)?" ":"";$.insert(S+u.text),r.value.autoFocus&&$.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 s()?{label:e.t("pill.dictating"),icon:"outline-wave-audio",tone:"danger",title:e.t("pill.stop"),run:m}:{label:e.t("pill.idle"),icon:"outline-wave-audio",title:e.t("pill.winH"),run:m};const u=t.state()?.status??"idle";return u==="starting"?{label:e.t("pill.starting"),icon:"outline-wave-audio",title:e.t("pill.title"),run:m}:u==="listening"?{label:e.t("pill.listening"),icon:"outline-wave-audio",tone:"danger",title:e.t("pill.stop"),run:m}:u==="error"?{label:e.t("pill.error"),icon:"outline-wave-audio",tone:"warning",title:e.t("pill.title"),run:m}:{label:e.t("pill.idle"),icon:"outline-wave-audio",title:e.t("pill.title"),run:m}};e.add(v.ComposerPill,()=>({id:"dictate",show:()=>N()})),e.add(v.ComposerPill,()=>({id:"read",order:1,show:()=>{if(e.app.platform!=="desktop")return;if(!o.speaking())return{label:e.t("read.idle"),icon:"outline-audio",title:e.t("read.title"),run:T};const u=o.paused(),f=[];return o.canPause()&&f.push({id:"pause",label:u?e.t("read.resume"):e.t("read.pause"),icon:"outline-audio",run:()=>o.togglePause()}),f.push({id:"restart",label:e.t("read.restart"),icon:"outline-reset",run:()=>{o.restart()}}),f.push({id:"stop",label:e.t("read.stop"),icon:"xmark-small",tone:"danger",run:()=>o.cancel()}),{label:u?e.t("read.paused"):e.t("read.speaking"),icon:"outline-audio",tone:"success",title:e.t("read.title"),rows:f}}})),e.add(v.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:m})),e.add(v.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(v.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:T})),e.add(v.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(be,{speaker:o})})},Ee=v.Plugin.define({...ie,setup:$e,main:he});exports.default=Ee;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-voice-dictation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Offline voice dictation and read-aloud for OpenCode Desktop on Windows",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Fran Carlos <francarlos803@gmail.com>",
|
|
@@ -45,11 +45,14 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@opencode/plugin": "2.2.6",
|
|
48
|
-
"effect": "4.1.0",
|
|
49
48
|
"@types/node": "^24.0.0",
|
|
49
|
+
"effect": "4.1.0",
|
|
50
50
|
"solid-js": "^1.9.17",
|
|
51
51
|
"typescript": "^5.9.0",
|
|
52
52
|
"vite": "^7.3.0",
|
|
53
53
|
"vite-plugin-solid": "^2.11.0"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"opencode-voice-dictation": "^0.2.0"
|
|
54
57
|
}
|
|
55
58
|
}
|
package/src/gui/contract.ts
CHANGED
|
@@ -55,8 +55,7 @@ export interface DiagnoseResult {
|
|
|
55
55
|
* Text-to-speech bridge. The window speaks with `speechSynthesis` when the
|
|
56
56
|
* Electron build exposes voices, and falls back to this main-process engine
|
|
57
57
|
* (`System.Speech.Synthesis`) when it does not.
|
|
58
|
-
*/
|
|
59
|
-
export const Speech = Ipc.define({
|
|
58
|
+
*/export const Speech = Ipc.define({
|
|
60
59
|
id: "voice-dictation.speech",
|
|
61
60
|
methods: {
|
|
62
61
|
speak: {
|
|
@@ -75,3 +74,14 @@ export const Speech = Ipc.define({
|
|
|
75
74
|
done: Schema.Struct({ ok: Schema.Boolean }),
|
|
76
75
|
},
|
|
77
76
|
})
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Windows 11 voice typing. The window focuses the composer and asks main to
|
|
80
|
+
* press Win+H; Windows writes the text straight into the focused field.
|
|
81
|
+
*/
|
|
82
|
+
export const VoiceTyping = Ipc.define({
|
|
83
|
+
id: "voice-dictation.voice-typing",
|
|
84
|
+
methods: {
|
|
85
|
+
toggle: {},
|
|
86
|
+
},
|
|
87
|
+
})
|
package/src/gui/definition.ts
CHANGED
|
@@ -37,17 +37,27 @@ export const definition = Plugin.define({
|
|
|
37
37
|
skipCode: true,
|
|
38
38
|
},
|
|
39
39
|
),
|
|
40
|
+
engine: Store.global(
|
|
41
|
+
Schema.Struct({
|
|
42
|
+
mode: Schema.String,
|
|
43
|
+
}),
|
|
44
|
+
{
|
|
45
|
+
mode: "windows",
|
|
46
|
+
},
|
|
47
|
+
),
|
|
40
48
|
},
|
|
41
49
|
i18n: {
|
|
42
50
|
en: {
|
|
43
51
|
"pill.idle": "Dictate",
|
|
44
52
|
"pill.starting": "Starting…",
|
|
45
53
|
"pill.listening": "Listening…",
|
|
54
|
+
"pill.dictating": "Dictating…",
|
|
46
55
|
"pill.error": "Retry dictation",
|
|
47
56
|
"pill.title": "Voice dictation",
|
|
57
|
+
"pill.winH": "Open Windows voice typing (Win+H)",
|
|
48
58
|
"pill.stop": "Stop dictation",
|
|
49
59
|
"command.toggle": "Toggle voice dictation",
|
|
50
|
-
"command.toggle.description": "
|
|
60
|
+
"command.toggle.description": "Dictate into the prompt with the selected engine",
|
|
51
61
|
"command.configure": "Voice dictation settings",
|
|
52
62
|
"error.title": "Voice dictation",
|
|
53
63
|
"error.language": "The speech language {locale} is not installed. Available: {available}.",
|
|
@@ -60,6 +70,15 @@ export const definition = Plugin.define({
|
|
|
60
70
|
"settings.title": "Voice dictation",
|
|
61
71
|
"settings.description": "Offline dictation with the Windows speech recognizer. The text is inserted into the prompt; it is never sent automatically.",
|
|
62
72
|
"settings.section": "Dictation",
|
|
73
|
+
"settings.engine": "Dictation engine",
|
|
74
|
+
"settings.engine.description": "Windows uses Windows 11 voice typing (Win+H), which is more accurate. System.Speech works offline but is less precise.",
|
|
75
|
+
"engine.windows": "Windows Voice Typing (Win+H)",
|
|
76
|
+
"engine.system": "System.Speech (offline)",
|
|
77
|
+
"settings.winh": "Test Win+H",
|
|
78
|
+
"settings.winh.description": "Sends the Windows voice typing shortcut. If the floating bar appears, it works.",
|
|
79
|
+
"settings.winh.run": "Test Win+H",
|
|
80
|
+
"settings.winh.sent": "Win+H sent. If the Windows dictation bar did not appear, check Settings › Accessibility › Voice typing.",
|
|
81
|
+
"error.winh": "Windows voice typing could not be triggered.",
|
|
63
82
|
"settings.language": "Language",
|
|
64
83
|
"settings.language.description": "A speech recognizer installed in Windows. Accents and punctuation depend on it.",
|
|
65
84
|
"settings.confidence": "Minimum confidence",
|
|
@@ -81,6 +100,10 @@ export const definition = Plugin.define({
|
|
|
81
100
|
"common.reason.no-microphone": "no microphone available",
|
|
82
101
|
"read.idle": "Read",
|
|
83
102
|
"read.speaking": "Reading…",
|
|
103
|
+
"read.paused": "Paused",
|
|
104
|
+
"read.pause": "Pause",
|
|
105
|
+
"read.resume": "Resume",
|
|
106
|
+
"read.restart": "Read again",
|
|
84
107
|
"read.stop": "Stop reading",
|
|
85
108
|
"read.title": "Read the last message aloud",
|
|
86
109
|
"command.read": "Read the last message aloud",
|
|
@@ -109,11 +132,13 @@ export const definition = Plugin.define({
|
|
|
109
132
|
"pill.idle": "Dictar",
|
|
110
133
|
"pill.starting": "Iniciando…",
|
|
111
134
|
"pill.listening": "Escuchando…",
|
|
135
|
+
"pill.dictating": "Dictando…",
|
|
112
136
|
"pill.error": "Reintentar dictado",
|
|
113
137
|
"pill.title": "Dictado por voz",
|
|
138
|
+
"pill.winH": "Abrir el dictado de Windows (Win+H)",
|
|
114
139
|
"pill.stop": "Detener dictado",
|
|
115
140
|
"command.toggle": "Alternar dictado por voz",
|
|
116
|
-
"command.toggle.description": "
|
|
141
|
+
"command.toggle.description": "Dicta en el prompt con el motor elegido",
|
|
117
142
|
"command.configure": "Ajustes de dictado por voz",
|
|
118
143
|
"error.title": "Dictado por voz",
|
|
119
144
|
"error.language": "El idioma de reconocimiento {locale} no está instalado. Disponibles: {available}.",
|
|
@@ -126,6 +151,14 @@ export const definition = Plugin.define({
|
|
|
126
151
|
"settings.title": "Dictado por voz",
|
|
127
152
|
"settings.description": "Dictado offline con el reconocedor de voz de Windows. El texto se inserta en el prompt; nunca se envía solo.",
|
|
128
153
|
"settings.section": "Dictado",
|
|
154
|
+
"settings.engine": "Motor de dictado",
|
|
155
|
+
"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.",
|
|
156
|
+
"engine.windows": "Windows Voice Typing (Win+H)",
|
|
157
|
+
"engine.system": "System.Speech (offline)",
|
|
158
|
+
"settings.winh": "Probar Win+H",
|
|
159
|
+
"settings.winh.description": "Envía el atajo del dictado de Windows. Si aparece la barra flotante, funciona.",
|
|
160
|
+
"settings.winh.run": "Probar Win+H",
|
|
161
|
+
"settings.winh.sent": "Win+H enviado. Si no apareció la barra, revisa Configuración › Accesibilidad › Dictado por voz.",
|
|
129
162
|
"settings.language": "Idioma",
|
|
130
163
|
"settings.language.description": "Un reconocedor instalado en Windows. Los acentos y la puntuación dependen de él.",
|
|
131
164
|
"settings.confidence": "Confianza mínima",
|
|
@@ -147,6 +180,10 @@ export const definition = Plugin.define({
|
|
|
147
180
|
"common.reason.no-microphone": "no hay micrófono disponible",
|
|
148
181
|
"read.idle": "Leer",
|
|
149
182
|
"read.speaking": "Leyendo…",
|
|
183
|
+
"read.paused": "Pausado",
|
|
184
|
+
"read.pause": "Pausar",
|
|
185
|
+
"read.resume": "Reanudar",
|
|
186
|
+
"read.restart": "Leer de nuevo",
|
|
150
187
|
"read.stop": "Detener lectura",
|
|
151
188
|
"read.title": "Leer en voz alta el último mensaje",
|
|
152
189
|
"command.read": "Leer en voz alta el último mensaje",
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { spawn, type ChildProcess } from "node:child_process"
|
|
2
|
+
import { createHash } from "node:crypto"
|
|
3
|
+
import { mkdirSync, writeFileSync } from "node:fs"
|
|
4
|
+
import { tmpdir } from "node:os"
|
|
5
|
+
import { join } from "node:path"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Sends the Windows voice typing shortcut (Win+H).
|
|
9
|
+
*
|
|
10
|
+
* `SendKeys` cannot press the Windows key, so this uses `keybd_event` from
|
|
11
|
+
* user32.dll through an inline C# type compiled by `Add-Type`.
|
|
12
|
+
*
|
|
13
|
+
* Keep the script ASCII-only: Windows PowerShell 5.1 reads a BOM-less script
|
|
14
|
+
* as ANSI.
|
|
15
|
+
*/
|
|
16
|
+
export const WIN_H_SCRIPT = String.raw`$ErrorActionPreference = "Stop"
|
|
17
|
+
|
|
18
|
+
Add-Type @"
|
|
19
|
+
using System;
|
|
20
|
+
using System.Runtime.InteropServices;
|
|
21
|
+
|
|
22
|
+
public static class WinH {
|
|
23
|
+
[DllImport("user32.dll", SetLastError = true)]
|
|
24
|
+
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
|
|
25
|
+
|
|
26
|
+
private const byte VK_LWIN = 0x5B;
|
|
27
|
+
private const byte VK_H = 0x48;
|
|
28
|
+
private const uint KEYUP = 0x0002;
|
|
29
|
+
|
|
30
|
+
public static void Send() {
|
|
31
|
+
keybd_event(VK_LWIN, 0, 0, UIntPtr.Zero);
|
|
32
|
+
System.Threading.Thread.Sleep(60);
|
|
33
|
+
keybd_event(VK_H, 0, 0, UIntPtr.Zero);
|
|
34
|
+
System.Threading.Thread.Sleep(60);
|
|
35
|
+
keybd_event(VK_H, 0, KEYUP, UIntPtr.Zero);
|
|
36
|
+
System.Threading.Thread.Sleep(60);
|
|
37
|
+
keybd_event(VK_LWIN, 0, KEYUP, UIntPtr.Zero);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
"@
|
|
41
|
+
|
|
42
|
+
[WinH]::Send()
|
|
43
|
+
`
|
|
44
|
+
|
|
45
|
+
const POWERSHELL = "powershell.exe"
|
|
46
|
+
|
|
47
|
+
function scriptFile(): string {
|
|
48
|
+
const dir = join(tmpdir(), "opencode-voice-dictation")
|
|
49
|
+
mkdirSync(dir, { recursive: true })
|
|
50
|
+
const hash = createHash("sha1").update(WIN_H_SCRIPT).digest("hex").slice(0, 12)
|
|
51
|
+
const file = join(dir, `win-h-${hash}.ps1`)
|
|
52
|
+
writeFileSync(file, WIN_H_SCRIPT, "utf8")
|
|
53
|
+
return file
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function spawnPowershell(args: string[]): ChildProcess {
|
|
57
|
+
return spawn(POWERSHELL, args, {
|
|
58
|
+
windowsHide: true,
|
|
59
|
+
stdio: "ignore",
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function sendVoiceTypingShortcut(): Promise<void> {
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
const child = spawnPowershell([
|
|
66
|
+
"-NoProfile",
|
|
67
|
+
"-NonInteractive",
|
|
68
|
+
"-ExecutionPolicy",
|
|
69
|
+
"Bypass",
|
|
70
|
+
"-File",
|
|
71
|
+
scriptFile(),
|
|
72
|
+
])
|
|
73
|
+
|
|
74
|
+
child.on("error", (cause) => reject(cause))
|
|
75
|
+
child.on("close", (code) => {
|
|
76
|
+
if (code === 0) resolve()
|
|
77
|
+
else reject(new Error(`Win+H helper exited with code ${code ?? "unknown"}`))
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
}
|
package/src/gui/main.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Plugin } from "@opencode/plugin/gui"
|
|
2
|
-
import { Dictation, Speech } from "./contract"
|
|
2
|
+
import { Dictation, Speech, VoiceTyping } from "./contract"
|
|
3
3
|
import { diagnose, startEngine, type EngineHandle } from "./engines/system-speech"
|
|
4
4
|
import { listSapiVoices, speakSapi, type SpeakHandle } from "./engines/sapi-speech"
|
|
5
|
+
import { sendVoiceTypingShortcut } from "./engines/win-h"
|
|
5
6
|
|
|
6
7
|
type Status = "idle" | "starting" | "listening" | "error"
|
|
7
8
|
|
|
@@ -131,6 +132,12 @@ export const main: Plugin.MainSetup = (ctx) => {
|
|
|
131
132
|
},
|
|
132
133
|
})
|
|
133
134
|
|
|
135
|
+
ctx.provide(VoiceTyping, {
|
|
136
|
+
toggle() {
|
|
137
|
+
return sendVoiceTypingShortcut()
|
|
138
|
+
},
|
|
139
|
+
})
|
|
140
|
+
|
|
134
141
|
ctx.onCleanup(() => {
|
|
135
142
|
if (handle) {
|
|
136
143
|
stopping = true
|
package/src/gui/settings.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createSignal, onMount } from "solid-js"
|
|
1
|
+
import { createSignal, onMount, Show } from "solid-js"
|
|
2
2
|
import { usePlugin } from "@opencode/plugin/gui"
|
|
3
|
-
import { Dictation } from "./contract"
|
|
3
|
+
import { Dictation, VoiceTyping } from "./contract"
|
|
4
4
|
import type { definition } from "./definition"
|
|
5
5
|
import type { Speaker } from "./speak"
|
|
6
6
|
|
|
@@ -27,7 +27,9 @@ export function VoiceSettings(props: { speaker: Speaker }) {
|
|
|
27
27
|
const ui = ctx.ui
|
|
28
28
|
const prefs = ctx.stores.prefs
|
|
29
29
|
const speechPrefs = ctx.stores.speech
|
|
30
|
+
const enginePrefs = ctx.stores.engine
|
|
30
31
|
const dictation = ctx.main(Dictation)
|
|
32
|
+
const voiceTyping = ctx.main(VoiceTyping)
|
|
31
33
|
|
|
32
34
|
const [locales, setLocales] = createSignal<readonly string[]>([])
|
|
33
35
|
const [busy, setBusy] = createSignal(false)
|
|
@@ -71,6 +73,29 @@ export function VoiceSettings(props: { speaker: Speaker }) {
|
|
|
71
73
|
})
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
const patchEngine = (mode: string) => {
|
|
77
|
+
enginePrefs.update((draft) => {
|
|
78
|
+
draft.mode = mode
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const testWinH = async () => {
|
|
83
|
+
try {
|
|
84
|
+
await voiceTyping.toggle()
|
|
85
|
+
ctx.toast.show({
|
|
86
|
+
variant: "default",
|
|
87
|
+
title: ctx.t("settings.winh"),
|
|
88
|
+
description: ctx.t("settings.winh.sent"),
|
|
89
|
+
})
|
|
90
|
+
} catch (cause) {
|
|
91
|
+
ctx.toast.show({
|
|
92
|
+
variant: "error",
|
|
93
|
+
title: ctx.t("pill.title"),
|
|
94
|
+
description: cause instanceof Error ? cause.message : ctx.t("error.winh"),
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
74
99
|
const preview = async () => {
|
|
75
100
|
try {
|
|
76
101
|
await props.speaker.preview()
|
|
@@ -130,52 +155,80 @@ export function VoiceSettings(props: { speaker: Speaker }) {
|
|
|
130
155
|
<ui.SettingsLayout title={ctx.t("settings.title")} description={ctx.t("settings.description")}>
|
|
131
156
|
<ui.SettingsSection title={ctx.t("settings.section")}>
|
|
132
157
|
<ui.SettingsRow
|
|
133
|
-
id="
|
|
134
|
-
title={ctx.t("settings.
|
|
135
|
-
description={ctx.t("settings.
|
|
136
|
-
>
|
|
137
|
-
<ui.Select
|
|
138
|
-
label={ctx.t("settings.language")}
|
|
139
|
-
value={prefs.value.locale}
|
|
140
|
-
options={localeOptions().length > 0 ? localeOptions() : FALLBACK_LOCALES.map((value) => ({ value, label: value }))}
|
|
141
|
-
onChange={(value) => patch({ locale: value })}
|
|
142
|
-
/>
|
|
143
|
-
</ui.SettingsRow>
|
|
144
|
-
|
|
145
|
-
<ui.SettingsRow
|
|
146
|
-
id="confidence"
|
|
147
|
-
title={ctx.t("settings.confidence")}
|
|
148
|
-
description={ctx.t("settings.confidence.description")}
|
|
158
|
+
id="engine"
|
|
159
|
+
title={ctx.t("settings.engine")}
|
|
160
|
+
description={ctx.t("settings.engine.description")}
|
|
149
161
|
>
|
|
150
162
|
<ui.Select
|
|
151
|
-
label={ctx.t("settings.
|
|
152
|
-
value={
|
|
163
|
+
label={ctx.t("settings.engine")}
|
|
164
|
+
value={enginePrefs.value.mode}
|
|
153
165
|
options={[
|
|
154
|
-
{ value: "
|
|
155
|
-
{ value: "
|
|
156
|
-
{ value: "0.6", label: ctx.t("confidence.high") },
|
|
166
|
+
{ value: "windows", label: ctx.t("engine.windows") },
|
|
167
|
+
{ value: "system", label: ctx.t("engine.system") },
|
|
157
168
|
]}
|
|
158
|
-
onChange={(value) =>
|
|
169
|
+
onChange={(value) => patchEngine(value)}
|
|
159
170
|
/>
|
|
160
171
|
</ui.SettingsRow>
|
|
161
172
|
|
|
162
|
-
<
|
|
163
|
-
<ui.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
173
|
+
<Show when={enginePrefs.value.mode === "windows"}>
|
|
174
|
+
<ui.SettingsRow
|
|
175
|
+
id="winh"
|
|
176
|
+
title={ctx.t("settings.winh")}
|
|
177
|
+
description={ctx.t("settings.winh.description")}
|
|
178
|
+
>
|
|
179
|
+
<ui.Button onClick={() => void testWinH()}>{ctx.t("settings.winh.run")}</ui.Button>
|
|
180
|
+
</ui.SettingsRow>
|
|
181
|
+
</Show>
|
|
170
182
|
|
|
171
|
-
<
|
|
172
|
-
<ui.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
183
|
+
<Show when={enginePrefs.value.mode === "system"}>
|
|
184
|
+
<ui.SettingsRow
|
|
185
|
+
id="language"
|
|
186
|
+
title={ctx.t("settings.language")}
|
|
187
|
+
description={ctx.t("settings.language.description")}
|
|
188
|
+
>
|
|
189
|
+
<ui.Select
|
|
190
|
+
label={ctx.t("settings.language")}
|
|
191
|
+
value={prefs.value.locale}
|
|
192
|
+
options={localeOptions().length > 0 ? localeOptions() : FALLBACK_LOCALES.map((value) => ({ value, label: value }))}
|
|
193
|
+
onChange={(value) => patch({ locale: value })}
|
|
194
|
+
/>
|
|
195
|
+
</ui.SettingsRow>
|
|
196
|
+
|
|
197
|
+
<ui.SettingsRow
|
|
198
|
+
id="confidence"
|
|
199
|
+
title={ctx.t("settings.confidence")}
|
|
200
|
+
description={ctx.t("settings.confidence.description")}
|
|
201
|
+
>
|
|
202
|
+
<ui.Select
|
|
203
|
+
label={ctx.t("settings.confidence")}
|
|
204
|
+
value={String(prefs.value.minConfidence)}
|
|
205
|
+
options={[
|
|
206
|
+
{ value: "0.2", label: ctx.t("confidence.low") },
|
|
207
|
+
{ value: "0.4", label: ctx.t("confidence.normal") },
|
|
208
|
+
{ value: "0.6", label: ctx.t("confidence.high") },
|
|
209
|
+
]}
|
|
210
|
+
onChange={(value) => patch({ minConfidence: Number(value) || 0.4 })}
|
|
211
|
+
/>
|
|
212
|
+
</ui.SettingsRow>
|
|
213
|
+
|
|
214
|
+
<ui.SettingsRow id="space" title={ctx.t("settings.space")} description={ctx.t("settings.space.description")}>
|
|
215
|
+
<ui.Switch
|
|
216
|
+
label={ctx.t("settings.space")}
|
|
217
|
+
hideLabel
|
|
218
|
+
checked={prefs.value.trailingSpace}
|
|
219
|
+
onChange={(checked) => patch({ trailingSpace: checked })}
|
|
220
|
+
/>
|
|
221
|
+
</ui.SettingsRow>
|
|
222
|
+
|
|
223
|
+
<ui.SettingsRow id="focus" title={ctx.t("settings.focus")} description={ctx.t("settings.focus.description")}>
|
|
224
|
+
<ui.Switch
|
|
225
|
+
label={ctx.t("settings.focus")}
|
|
226
|
+
hideLabel
|
|
227
|
+
checked={prefs.value.autoFocus}
|
|
228
|
+
onChange={(checked) => patch({ autoFocus: checked })}
|
|
229
|
+
/>
|
|
230
|
+
</ui.SettingsRow>
|
|
231
|
+
</Show>
|
|
179
232
|
</ui.SettingsSection>
|
|
180
233
|
|
|
181
234
|
<ui.SettingsSection title={ctx.t("speech.section")}>
|
package/src/gui/speak.ts
CHANGED
|
@@ -10,12 +10,18 @@ export interface VoiceOption {
|
|
|
10
10
|
|
|
11
11
|
export interface Speaker {
|
|
12
12
|
speaking(): boolean
|
|
13
|
+
paused(): boolean
|
|
13
14
|
backend(): "web" | "sapi" | "none"
|
|
15
|
+
canPause(): boolean
|
|
14
16
|
voices(): VoiceOption[]
|
|
15
17
|
refreshVoices(): Promise<void>
|
|
16
18
|
lastAssistantText(): Promise<string>
|
|
17
19
|
speak(text: string): Promise<boolean>
|
|
18
20
|
cancel(): void
|
|
21
|
+
pause(): void
|
|
22
|
+
resume(): void
|
|
23
|
+
togglePause(): void
|
|
24
|
+
restart(): Promise<boolean>
|
|
19
25
|
preview(): Promise<boolean>
|
|
20
26
|
}
|
|
21
27
|
|
|
@@ -102,11 +108,13 @@ export function createSpeaker(
|
|
|
102
108
|
const prefs = ctx.stores.speech
|
|
103
109
|
|
|
104
110
|
const [speaking, setSpeaking] = createSignal(false)
|
|
111
|
+
const [paused, setPaused] = createSignal(false)
|
|
105
112
|
const [voices, setVoices] = createSignal<VoiceOption[]>([])
|
|
106
113
|
const [backend, setBackend] = createSignal<"web" | "sapi" | "none">("none")
|
|
107
114
|
|
|
108
115
|
let generation = 0
|
|
109
116
|
let queue: string[] = []
|
|
117
|
+
let lastText = ""
|
|
110
118
|
|
|
111
119
|
const synth = () =>
|
|
112
120
|
typeof globalThis.speechSynthesis !== "undefined" ? globalThis.speechSynthesis : undefined
|
|
@@ -157,11 +165,37 @@ export function createSpeaker(
|
|
|
157
165
|
generation++
|
|
158
166
|
queue = []
|
|
159
167
|
synth()?.cancel()
|
|
168
|
+
setPaused(false)
|
|
160
169
|
setSpeaking(false)
|
|
161
170
|
void speech.stop().catch(() => {})
|
|
162
171
|
}
|
|
163
172
|
|
|
173
|
+
const canPause = () => backend() === "web"
|
|
174
|
+
|
|
175
|
+
const pause = () => {
|
|
176
|
+
if (!speaking() || paused() || !canPause()) return
|
|
177
|
+
synth()?.pause()
|
|
178
|
+
setPaused(true)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const resume = () => {
|
|
182
|
+
if (!speaking() || !paused() || !canPause()) return
|
|
183
|
+
synth()?.resume()
|
|
184
|
+
setPaused(false)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const togglePause = () => {
|
|
188
|
+
if (paused()) resume()
|
|
189
|
+
else pause()
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const restart = () => {
|
|
193
|
+
if (!lastText) return Promise.resolve(false)
|
|
194
|
+
return speak(lastText)
|
|
195
|
+
}
|
|
196
|
+
|
|
164
197
|
const speak = async (text: string) => {
|
|
198
|
+
lastText = text
|
|
165
199
|
const cleaned = cleanForSpeech(text, prefs.value.skipCode)
|
|
166
200
|
if (!cleaned) return false
|
|
167
201
|
|
|
@@ -177,11 +211,13 @@ export function createSpeaker(
|
|
|
177
211
|
const gen = generation
|
|
178
212
|
queue = chunkForSpeech(cleaned)
|
|
179
213
|
setSpeaking(true)
|
|
214
|
+
setPaused(false)
|
|
180
215
|
|
|
181
216
|
const pump = () => {
|
|
182
217
|
if (gen !== generation) return
|
|
183
218
|
const next = queue.shift()
|
|
184
219
|
if (!next) {
|
|
220
|
+
setPaused(false)
|
|
185
221
|
setSpeaking(false)
|
|
186
222
|
return
|
|
187
223
|
}
|
|
@@ -201,6 +237,7 @@ export function createSpeaker(
|
|
|
201
237
|
|
|
202
238
|
if (backend() === "sapi") {
|
|
203
239
|
setSpeaking(true)
|
|
240
|
+
setPaused(false)
|
|
204
241
|
try {
|
|
205
242
|
await speech.speak({
|
|
206
243
|
text: cleaned,
|
|
@@ -241,7 +278,10 @@ export function createSpeaker(
|
|
|
241
278
|
.join("\n")
|
|
242
279
|
}
|
|
243
280
|
|
|
244
|
-
speech.on("done", () =>
|
|
281
|
+
speech.on("done", () => {
|
|
282
|
+
setPaused(false)
|
|
283
|
+
setSpeaking(false)
|
|
284
|
+
})
|
|
245
285
|
|
|
246
286
|
const engine = synth()
|
|
247
287
|
engine?.addEventListener?.("voiceschanged", () => void refreshVoices())
|
|
@@ -249,12 +289,18 @@ export function createSpeaker(
|
|
|
249
289
|
|
|
250
290
|
return {
|
|
251
291
|
speaking,
|
|
292
|
+
paused,
|
|
252
293
|
backend,
|
|
294
|
+
canPause,
|
|
253
295
|
voices,
|
|
254
296
|
refreshVoices,
|
|
255
297
|
lastAssistantText,
|
|
256
298
|
speak,
|
|
257
299
|
cancel,
|
|
300
|
+
pause,
|
|
301
|
+
resume,
|
|
302
|
+
togglePause,
|
|
303
|
+
restart,
|
|
258
304
|
preview: () => speak(ctx.t("speech.preview.text")),
|
|
259
305
|
}
|
|
260
306
|
}
|
package/src/gui/window.tsx
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createSignal } from "solid-js"
|
|
2
|
+
import {
|
|
3
|
+
Command,
|
|
4
|
+
ComposerPill,
|
|
5
|
+
SettingsPage,
|
|
6
|
+
type ComposerPillRow,
|
|
7
|
+
type ComposerPillView,
|
|
8
|
+
type Plugin,
|
|
9
|
+
} from "@opencode/plugin/gui"
|
|
10
|
+
import { Dictation, Speech, VoiceTyping } from "./contract"
|
|
3
11
|
import type { definition } from "./definition"
|
|
4
12
|
import { createSpeaker } from "./speak"
|
|
5
13
|
import { VoiceSettings } from "./settings"
|
|
@@ -11,8 +19,11 @@ import { VoiceSettings } from "./settings"
|
|
|
11
19
|
export const setup: Plugin.Setup<typeof definition> = (ctx) => {
|
|
12
20
|
const dictation = ctx.main(Dictation)
|
|
13
21
|
const speech = ctx.main(Speech)
|
|
22
|
+
const voiceTyping = ctx.main(VoiceTyping)
|
|
14
23
|
const speaker = createSpeaker(ctx, speech)
|
|
15
24
|
const prefs = ctx.stores.prefs
|
|
25
|
+
const engine = ctx.stores.engine
|
|
26
|
+
const [windowsActive, setWindowsActive] = createSignal(false)
|
|
16
27
|
|
|
17
28
|
let targetSession: string | undefined
|
|
18
29
|
|
|
@@ -37,6 +48,10 @@ export const setup: Plugin.Setup<typeof definition> = (ctx) => {
|
|
|
37
48
|
}
|
|
38
49
|
|
|
39
50
|
const start = () => {
|
|
51
|
+
if (windowsActive()) {
|
|
52
|
+
setWindowsActive(false)
|
|
53
|
+
void voiceTyping.toggle().catch(() => {})
|
|
54
|
+
}
|
|
40
55
|
speaker.cancel()
|
|
41
56
|
targetSession = ctx.sessions.current()?.key
|
|
42
57
|
void dictation
|
|
@@ -54,7 +69,30 @@ export const setup: Plugin.Setup<typeof definition> = (ctx) => {
|
|
|
54
69
|
void dictation.stop().catch(() => {})
|
|
55
70
|
}
|
|
56
71
|
|
|
72
|
+
const toggleWindows = () => {
|
|
73
|
+
speaker.cancel()
|
|
74
|
+
ctx.screen.current()?.composer.focus()
|
|
75
|
+
|
|
76
|
+
void voiceTyping
|
|
77
|
+
.toggle()
|
|
78
|
+
.then(() => setWindowsActive((value) => !value))
|
|
79
|
+
.catch((cause: unknown) => {
|
|
80
|
+
setWindowsActive(false)
|
|
81
|
+
ctx.toast.show({
|
|
82
|
+
variant: "error",
|
|
83
|
+
title: ctx.t("pill.title"),
|
|
84
|
+
description:
|
|
85
|
+
cause instanceof Error ? `${ctx.t("error.winh")} ${cause.message}` : ctx.t("error.winh"),
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
57
90
|
const toggle = () => {
|
|
91
|
+
if (engine.value.mode === "windows") {
|
|
92
|
+
toggleWindows()
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
|
|
58
96
|
const status = dictation.state()?.status ?? "idle"
|
|
59
97
|
if (status === "starting" || status === "listening") stop()
|
|
60
98
|
else start()
|
|
@@ -126,6 +164,23 @@ export const setup: Plugin.Setup<typeof definition> = (ctx) => {
|
|
|
126
164
|
const view = (): ComposerPillView | undefined => {
|
|
127
165
|
if (ctx.app.platform !== "desktop") return undefined
|
|
128
166
|
|
|
167
|
+
if (engine.value.mode === "windows") {
|
|
168
|
+
return windowsActive()
|
|
169
|
+
? {
|
|
170
|
+
label: ctx.t("pill.dictating"),
|
|
171
|
+
icon: "outline-wave-audio",
|
|
172
|
+
tone: "danger",
|
|
173
|
+
title: ctx.t("pill.stop"),
|
|
174
|
+
run: toggle,
|
|
175
|
+
}
|
|
176
|
+
: {
|
|
177
|
+
label: ctx.t("pill.idle"),
|
|
178
|
+
icon: "outline-wave-audio",
|
|
179
|
+
title: ctx.t("pill.winH"),
|
|
180
|
+
run: toggle,
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
129
184
|
const status = dictation.state()?.status ?? "idle"
|
|
130
185
|
|
|
131
186
|
if (status === "starting") {
|
|
@@ -160,23 +215,47 @@ export const setup: Plugin.Setup<typeof definition> = (ctx) => {
|
|
|
160
215
|
ctx.add(ComposerPill, () => ({
|
|
161
216
|
id: "read",
|
|
162
217
|
order: 1,
|
|
163
|
-
show: () => {
|
|
218
|
+
show: (): ComposerPillView | undefined => {
|
|
164
219
|
if (ctx.app.platform !== "desktop") return undefined
|
|
165
220
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
221
|
+
if (!speaker.speaking()) {
|
|
222
|
+
return { label: ctx.t("read.idle"), icon: "outline-audio", title: ctx.t("read.title"), run: read }
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const paused = speaker.paused()
|
|
226
|
+
const rows: ComposerPillRow[] = []
|
|
227
|
+
|
|
228
|
+
if (speaker.canPause()) {
|
|
229
|
+
rows.push({
|
|
230
|
+
id: "pause",
|
|
231
|
+
label: paused ? ctx.t("read.resume") : ctx.t("read.pause"),
|
|
232
|
+
icon: "outline-audio",
|
|
233
|
+
run: () => speaker.togglePause(),
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
rows.push({
|
|
238
|
+
id: "restart",
|
|
239
|
+
label: ctx.t("read.restart"),
|
|
240
|
+
icon: "outline-reset",
|
|
241
|
+
run: () => void speaker.restart(),
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
rows.push({
|
|
245
|
+
id: "stop",
|
|
246
|
+
label: ctx.t("read.stop"),
|
|
247
|
+
icon: "xmark-small",
|
|
248
|
+
tone: "danger",
|
|
249
|
+
run: () => speaker.cancel(),
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
return {
|
|
253
|
+
label: paused ? ctx.t("read.paused") : ctx.t("read.speaking"),
|
|
254
|
+
icon: "outline-audio",
|
|
255
|
+
tone: "success",
|
|
256
|
+
title: ctx.t("read.title"),
|
|
257
|
+
rows,
|
|
258
|
+
}
|
|
180
259
|
},
|
|
181
260
|
}))
|
|
182
261
|
|
|
@@ -225,6 +304,8 @@ export const setup: Plugin.Setup<typeof definition> = (ctx) => {
|
|
|
225
304
|
},
|
|
226
305
|
get entries() {
|
|
227
306
|
return [
|
|
307
|
+
{ id: "engine", title: ctx.t("settings.engine"), keywords: "engine motor dictation dictado winh voz" },
|
|
308
|
+
{ id: "winh", title: ctx.t("settings.winh"), keywords: "winh windows voice typing dictado" },
|
|
228
309
|
{ id: "language", title: ctx.t("settings.language"), keywords: "voice language idioma voz" },
|
|
229
310
|
{ id: "confidence", title: ctx.t("settings.confidence"), keywords: "voice confidence confianza" },
|
|
230
311
|
{ id: "test", title: ctx.t("settings.test"), keywords: "voice microphone microphone test microfono" },
|