opencode-voice-dictation 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -3
- package/dist/gui-experimental.cjs +8 -8
- package/package.json +5 -2
- package/src/gui/definition.ts +8 -0
- package/src/gui/speak.ts +47 -1
- package/src/gui/window.tsx +90 -20
package/README.md
CHANGED
|
@@ -143,9 +143,10 @@ La píldora del micrófono muestra el estado: `Dictar`, `Iniciando…`,
|
|
|
143
143
|
`Escuchando…` (System.Speech), `Dictando…` (Win+H) y `Reintentar dictado` si
|
|
144
144
|
algo falla.
|
|
145
145
|
|
|
146
|
-
La píldora «Leer» cambia a `Leyendo
|
|
147
|
-
|
|
148
|
-
|
|
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.
|
|
149
150
|
|
|
150
151
|
El texto se inserta en la posición del cursor. Si ya hay texto y no termina en
|
|
151
152
|
espacio, se añade uno de separación (configurable).
|
|
@@ -175,6 +176,10 @@ La lectura limpia el Markdown antes de hablar: quita fences, backticks,
|
|
|
175
176
|
negritas, encabezados, viñetas y convierte `[texto](url)` en `texto`. Trocea el
|
|
176
177
|
texto por frases para poder detenerse rápido.
|
|
177
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
|
+
|
|
178
183
|
## Permisos
|
|
179
184
|
|
|
180
185
|
El plugin es local y no hace peticiones de red. Para funcionar:
|
|
@@ -1,4 +1,4 @@
|
|
|
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(
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const S=require("@opencode/plugin/gui"),d=require("effect"),z=require("node:child_process"),V=require("node:crypto"),A=require("node:fs"),D=require("node:os"),L=require("node:path"),g=require("solid-js/web"),T=require("solid-js"),ne=S.Plugin.define({os:["windows"],stores:{prefs:S.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:S.Store.global(d.Schema.Struct({voiceURI:d.Schema.String,rate:d.Schema.Number,skipCode:d.Schema.Boolean}),{voiceURI:"",rate:1,skipCode:!0}),engine:S.Store.global(d.Schema.Struct({mode:d.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."}}}),H=S.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)})}}),q=S.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})}}),U=S.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
|
-
`)}}),
|
|
108
|
+
`,ie="powershell.exe";function K(){const e=L.join(D.tmpdir(),"opencode-voice-dictation");A.mkdirSync(e,{recursive:!0});const t=V.createHash("sha1").update(j).digest("hex").slice(0,12),n=L.join(e,`dictation-${t}.ps1`);return A.writeFileSync(n,j,"utf8"),n}function Z(e){return z.spawn(ie,e,{windowsHide:!0,stdio:["ignore","pipe","pipe"]})}function X(e){const t=e.pid;if(t===void 0){e.kill();return}z.spawn("taskkill",["/PID",String(t),"/T","/F"],{windowsHide:!0,stdio:"ignore"}).on("error",()=>e.kill())}function oe(e,t){const n=Z(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",K(),"-Culture",e.locale,"-MinConfidence",String(e.minConfidence)]);let l=!1,o="",r="";const u=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 n.stdout?.setEncoding("utf8"),n.stdout?.on("data",s=>{r+=s;let a=r.indexOf(`
|
|
109
|
+
`);for(;a>=0;){const p=r.slice(0,a).replace(/\r$/,"").trim();if(r=r.slice(a+1),p)try{u(JSON.parse(p))}catch{}a=r.indexOf(`
|
|
110
|
+
`)}}),n.stderr?.setEncoding("utf8"),n.stderr?.on("data",s=>{o=(o+s).slice(-2e3)}),n.on("error",s=>{l||t.onError("ENGINE_START_FAILED",s.message,[])}),n.on("close",s=>{l||t.onExit(s,o.trim().slice(-500))}),{stop(){l=!0,X(n)}}}function re(){return new Promise((e,t)=>{const n=Z(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",K(),"-Diagnose"]);let l="",o="",r=!1;const u=(a,p)=>{r||(r=!0,clearTimeout(s),a?t(a):e(p))},s=setTimeout(()=>{X(n),u(new Error("diagnose timed out"))},2e4);n.stdout?.setEncoding("utf8"),n.stdout?.on("data",a=>{l+=a}),n.stderr?.setEncoding("utf8"),n.stderr?.on("data",a=>{o+=a}),n.on("error",a=>u(a)),n.on("close",()=>{const a=l.split(/\r?\n/).map(p=>p.trim()).filter(p=>p.startsWith("{")).at(-1);if(!a){u(new Error(o.trim()||"no output from PowerShell"));return}try{const p=JSON.parse(a);u(void 0,{locales:p.locales??[],microphone:p.microphone===!0,selected:p.selected??"",error:p.error??""})}catch(p){u(p instanceof Error?p:new Error(String(p)))}})})}const M=String.raw`param(
|
|
111
111
|
[string]$TextFile = "",
|
|
112
112
|
[int]$Rate = 0,
|
|
113
113
|
[string]$Voice = "",
|
|
@@ -160,7 +160,7 @@ try {
|
|
|
160
160
|
} catch { }
|
|
161
161
|
|
|
162
162
|
$synth.Dispose()
|
|
163
|
-
`,
|
|
163
|
+
`,se="powershell.exe";function Y(){const e=L.join(D.tmpdir(),"opencode-voice-dictation");return A.mkdirSync(e,{recursive:!0}),e}function J(){const e=V.createHash("sha1").update(M).digest("hex").slice(0,12),t=L.join(Y(),`speak-${e}.ps1`);return A.writeFileSync(t,M,"utf8"),t}function ae(e){const t=L.join(Y(),`speech-${V.randomUUID()}.txt`);return A.writeFileSync(t,e,"utf8"),t}function Q(e){return z.spawn(se,e,{windowsHide:!0,stdio:["ignore","pipe","pipe"]})}function x(e){const t=e.pid;if(t===void 0){e.kill();return}z.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 n=ae(e.text),l=Q(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",J(),"-TextFile",n,"-Rate",String(ce(e.rate)),"-Voice",e.voice]);let o=!1;const r=()=>{try{A.rmSync(n,{force:!0})}catch{}};return l.on("error",()=>{r(),o||t(!1)}),l.on("close",u=>{r(),o||t(u===0)}),{stop(){o=!0,x(l),r()}}}function de(){return new Promise(e=>{const t=Q(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",J(),"-ListVoices"]);let n="",l=!1;const o=u=>{l||(l=!0,clearTimeout(r),e(u))},r=setTimeout(()=>{x(t),o([])},1e4);t.stdout?.setEncoding("utf8"),t.stdout?.on("data",u=>{n+=u}),t.on("error",()=>o([])),t.on("close",()=>{const u=n.split(/\r?\n/).map(s=>s.trim()).filter(s=>s.length>0);o(u)})})}const G=String.raw`$ErrorActionPreference = "Stop"
|
|
164
164
|
|
|
165
165
|
Add-Type @"
|
|
166
166
|
using System;
|
|
@@ -187,6 +187,6 @@ public static class WinH {
|
|
|
187
187
|
"@
|
|
188
188
|
|
|
189
189
|
[WinH]::Send()
|
|
190
|
-
`,
|
|
191
|
-
`);return t?
|
|
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;
|
|
190
|
+
`,pe="powershell.exe";function ue(){const e=L.join(D.tmpdir(),"opencode-voice-dictation");A.mkdirSync(e,{recursive:!0});const t=V.createHash("sha1").update(G).digest("hex").slice(0,12),n=L.join(e,`win-h-${t}.ps1`);return A.writeFileSync(n,G,"utf8"),n}function ge(e){return z.spawn(pe,e,{windowsHide:!0,stdio:"ignore"})}function me(){return new Promise((e,t)=>{const n=ge(["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-File",ue()]);n.on("error",l=>t(l)),n.on("close",l=>{l===0?e():t(new Error(`Win+H helper exited with code ${l??"unknown"}`))})})}const he=e=>{let t="idle",n="",l="",o,r=!1;const u=()=>{o=void 0,r=!1},s=e.provide(H,{state:()=>({status:t,error:n,locale:l}),start(y,E){o&&(r=!0,o.stop(),u()),t="starting",n="",l=y.locale,s.changed();const C=E.window;try{o=oe({locale:y.locale,minConfidence:y.minConfidence},{onReady(f){t="listening",l=f,s.changed()},onFinal(f,h){s.emit("final",{text:f,confidence:h},C)},onError(f,h,k){t="error",n=f,s.changed(),s.emit("error",{code:f,detail:h,available:k},C)},onExit(f,h){if(r){u(),t="idle",n="",l="",s.changed();return}u(),t!=="error"&&(t="error",n=f===null?"ENGINE_EXIT":`ENGINE_EXIT_${f}`,s.changed(),s.emit("error",{code:"ENGINE_EXIT",detail:h||(f===null?"":String(f)),available:[]},C))}})}catch(f){throw t="error",n="ENGINE_START_FAILED",s.changed(),f}},stop(){o&&(r=!0,o.stop(),u()),t="idle",n="",l="",s.changed()},diagnose(){return re()}});let a;const p=e.provide(q,{speak(y){a?.stop(),a=le(y,E=>{a=void 0,p.emit("done",{ok:E})})},stop(){a&&(a.stop(),a=void 0),p.emit("done",{ok:!0})},voices(){return de()}});e.provide(U,{toggle(){return me()}}),e.onCleanup(()=>{o&&(r=!0,o.stop(),u()),a?.stop(),a=void 0})},fe=250;function Se(e,t){let n=e.replace(/\r\n/g,`
|
|
191
|
+
`);return t?n=n.replace(/```[\s\S]*?```/g," "):n=n.replace(/```[^\n]*\n([\s\S]*?)```/g,"$1"),n=n.replace(/`([^`]+)`/g,"$1"),n=n.replace(/!\[[^\]]*\]\([^)]*\)/g," "),n=n.replace(/\[([^\]]+)\]\([^)]*\)/g,"$1"),n=n.replace(/^\s*#{1,6}\s+/gm,""),n=n.replace(/^\s*>\s?/gm,""),n=n.replace(/^\s*[-*+]\s+/gm,""),n=n.replace(/^\s*\d+\.\s+/gm,""),n=n.replace(/(\*\*|__)(.*?)\1/g,"$2"),n=n.replace(/(\*|_)(.*?)\1/g,"$2"),n=n.replace(/^\s*\|.*\|\s*$/gm," "),n=n.replace(/\n{2,}/g,". "),n=n.replace(/\n/g," "),n=n.replace(/\s+/g," "),n=n.replace(/\s+([.,;:!?])/g,"$1"),n=n.replace(/([.,;:!?]){2,}/g,"$1"),n.trim()}function ve(e,t=fe){const n=e.trim();if(!n)return[];const l=n.split(new RegExp("(?<=[.!?…])\\s+")),o=[];let r="";const u=s=>{let a="";for(const p of s.split(/\s+/))p&&(a&&a.length+1+p.length>t?(o.push(a),a=p):a=a?`${a} ${p}`:p);return a};for(const s of l){if(s.length>t){r&&(o.push(r),r=""),r=u(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 n=e.stores.speech,[l,o]=T.createSignal(!1),[r,u]=T.createSignal(!1),[s,a]=T.createSignal([]),[p,y]=T.createSignal("none");let E=0,C=[],f="";const h=()=>typeof globalThis.speechSynthesis<"u"?globalThis.speechSynthesis:void 0,k=()=>{const v=h()?.getVoices()??[];if(v.length===0)return;const w=n.value.voiceURI;if(w){const $=v.find(O=>O.voiceURI===w);if($)return $}const b=e.locale.locale().split("-")[0]?.toLowerCase()??"es";return v.find($=>$.lang.toLowerCase().startsWith(b))??v[0]},R=async()=>{const v=h()?.getVoices()??[];if(v.length>0){a(v.map(w=>({id:w.voiceURI,label:`${w.name} — ${w.lang}`}))),y("web");return}try{const w=await t.voices();if(w.length>0){a(w.map(b=>({id:b,label:b}))),y("sapi");return}}catch{}y("none")},_=()=>{E++,C=[],h()?.cancel(),u(!1),o(!1),t.stop().catch(()=>{})},P=()=>p()==="web",c=()=>{!l()||r()||!P()||(h()?.pause(),u(!0))},i=()=>{!l()||!r()||!P()||(h()?.resume(),u(!1))},m=()=>{r()?i():c()},I=()=>f?N(f):Promise.resolve(!1),N=async v=>{f=v;const w=Se(v,n.value.skipCode);if(!w)return!1;if(_(),await R(),p()==="web"){const b=h();if(!b)return!1;const $=k(),O=n.value.rate,te=E;C=ve(w),o(!0),u(!1);const F=()=>{if(te!==E)return;const B=C.shift();if(!B){u(!1),o(!1);return}const W=new SpeechSynthesisUtterance(B);$&&(W.voice=$),$?.lang&&(W.lang=$.lang),W.rate=O,W.onend=F,W.onerror=F,b.speak(W)};return F(),!0}if(p()==="sapi"){o(!0),u(!1);try{await t.speak({text:w,rate:n.value.rate,voice:n.value.voiceURI})}catch(b){throw o(!1),b}return!0}throw o(!1),new Error(e.t("read.noVoices"))},ee=async()=>{const v=e.sessions.current();if(!v)return"";const b=(await v.server.client.message.list({sessionID:v.id,type:"assistant",order:"desc",limit:1})).data[0];return!b||b.type!=="assistant"?"":b.content.filter($=>$.type==="text").map($=>$.text).join(`
|
|
192
|
+
`)};return t.on("done",()=>{u(!1),o(!1)}),h()?.addEventListener?.("voiceschanged",()=>{R()}),R(),{speaking:l,paused:r,backend:p,canPause:P,voices:s,refreshVoices:R,lastAssistantText:ee,speak:N,cancel:_,pause:c,resume:i,togglePause:m,restart:I,preview:()=>N(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=S.usePlugin(),n=t.ui,l=t.stores.prefs,o=t.stores.speech,r=t.stores.engine,u=t.main(H),s=t.main(U),[a,p]=T.createSignal([]),[y,E]=T.createSignal(!1);T.onMount(()=>{u.diagnose().then(i=>{i.locales.length>0&&p(i.locales)}).catch(()=>{}),e.speaker.refreshVoices()});const C=()=>{const i=a(),m=l.value.locale;return(i.includes(m)?i:[m,...i]).map(N=>({value:N,label:N}))},f=()=>[{value:"",label:t.t("speech.voice.auto")},...e.speaker.voices().map(i=>({value:i.id,label:i.label}))],h=i=>{l.update(m=>{i.locale!==void 0&&(m.locale=i.locale),i.minConfidence!==void 0&&(m.minConfidence=i.minConfidence),i.trailingSpace!==void 0&&(m.trailingSpace=i.trailingSpace),i.autoFocus!==void 0&&(m.autoFocus=i.autoFocus)})},k=i=>{o.update(m=>{i.voiceURI!==void 0&&(m.voiceURI=i.voiceURI),i.rate!==void 0&&(m.rate=i.rate),i.skipCode!==void 0&&(m.skipCode=i.skipCode)})},R=i=>{r.update(m=>{m.mode=i})},_=async()=>{try{await s.toggle(),t.toast.show({variant:"default",title:t.t("settings.winh"),description:t.t("settings.winh.sent")})}catch(i){t.toast.show({variant:"error",title:t.t("pill.title"),description:i instanceof Error?i.message:t.t("error.winh")})}},P=async()=>{try{await e.speaker.preview()}catch(i){t.toast.show({variant:"error",title:t.t("read.title"),description:i instanceof Error?i.message:t.t("read.error")})}},c=async()=>{E(!0);try{const i=await u.diagnose();if(i.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(!i.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}i.locales.length>0&&!a().length&&p(i.locales),t.toast.show({variant:"success",title:t.t("error.title"),description:t.t("settings.test.success",{locale:i.selected||i.locales[0]||l.value.locale})})}catch(i){t.toast.show({variant:"error",title:t.t("error.title"),description:i instanceof Error?i.message:String(i)})}finally{E(!1)}};return g.createComponent(n.SettingsLayout,{get title(){return t.t("settings.title")},get description(){return t.t("settings.description")},get children(){return[g.createComponent(n.SettingsSection,{get title(){return t.t("settings.section")},get children(){return[g.createComponent(n.SettingsRow,{id:"engine",get title(){return t.t("settings.engine")},get description(){return t.t("settings.engine.description")},get children(){return g.createComponent(n.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:i=>R(i)})}}),g.createComponent(T.Show,{get when(){return r.value.mode==="windows"},get children(){return g.createComponent(n.SettingsRow,{id:"winh",get title(){return t.t("settings.winh")},get description(){return t.t("settings.winh.description")},get children(){return g.createComponent(n.Button,{onClick:()=>{_()},get children(){return t.t("settings.winh.run")}})}})}}),g.createComponent(T.Show,{get when(){return r.value.mode==="system"},get children(){return[g.createComponent(n.SettingsRow,{id:"language",get title(){return t.t("settings.language")},get description(){return t.t("settings.language.description")},get children(){return g.createComponent(n.Select,{get label(){return t.t("settings.language")},get value(){return l.value.locale},get options(){return g.memo(()=>C().length>0)()?C():ye.map(i=>({value:i,label:i}))},onChange:i=>h({locale:i})})}}),g.createComponent(n.SettingsRow,{id:"confidence",get title(){return t.t("settings.confidence")},get description(){return t.t("settings.confidence.description")},get children(){return g.createComponent(n.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:i=>h({minConfidence:Number(i)||.4})})}}),g.createComponent(n.SettingsRow,{id:"space",get title(){return t.t("settings.space")},get description(){return t.t("settings.space.description")},get children(){return g.createComponent(n.Switch,{get label(){return t.t("settings.space")},hideLabel:!0,get checked(){return l.value.trailingSpace},onChange:i=>h({trailingSpace:i})})}}),g.createComponent(n.SettingsRow,{id:"focus",get title(){return t.t("settings.focus")},get description(){return t.t("settings.focus.description")},get children(){return g.createComponent(n.Switch,{get label(){return t.t("settings.focus")},hideLabel:!0,get checked(){return l.value.autoFocus},onChange:i=>h({autoFocus:i})})}})]}})]}}),g.createComponent(n.SettingsSection,{get title(){return t.t("speech.section")},get children(){return[g.createComponent(n.SettingsRow,{id:"voice",get title(){return t.t("speech.voice")},get description(){return t.t("speech.voice.description")},get children(){return g.createComponent(n.Select,{get label(){return t.t("speech.voice")},get value(){return o.value.voiceURI},get options(){return f()},onChange:i=>k({voiceURI:i})})}}),g.createComponent(n.SettingsRow,{id:"rate",get title(){return t.t("speech.rate")},get description(){return t.t("speech.rate.description")},get children(){return g.createComponent(n.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:i=>k({rate:Number(i)||1})})}}),g.createComponent(n.SettingsRow,{id:"skip-code",get title(){return t.t("speech.skipCode")},get description(){return t.t("speech.skipCode.description")},get children(){return g.createComponent(n.Switch,{get label(){return t.t("speech.skipCode")},hideLabel:!0,get checked(){return o.value.skipCode},onChange:i=>k({skipCode:i})})}}),g.createComponent(n.SettingsRow,{id:"preview",get title(){return t.t("speech.preview")},get description(){return t.t("speech.preview.description")},get children(){return g.createComponent(n.Button,{onClick:()=>{P()},get children(){return t.t("read.idle")}})}})]}}),g.createComponent(n.SettingsSection,{get title(){return t.t("settings.test.section")},get children(){return g.createComponent(n.SettingsRow,{id:"test",get title(){return t.t("settings.test")},get description(){return t.t("settings.test.description")},get children(){return g.createComponent(n.Button,{get busy(){return y()},onClick:()=>{c()},get children(){return t.t("settings.test.run")}})}})}})]}})}function $e(e){const t=S.usePlugin();return g.memo(()=>e.actions().map(n=>g.createComponent(t.ui.Button,{get variant(){return n.id==="stop"?"danger":"neutral"},get icon(){return n.icon},onClick:()=>{n.run(),e.close()},get children(){return n.label}})))}const Ee=e=>{const t=e.main(H),n=e.main(q),l=e.main(U),o=we(e,n),r=e.stores.prefs,u=e.stores.engine,[s,a]=T.createSignal(!1);let p;const y=(c,i,m)=>{switch(c){case"LANGUAGE_NOT_AVAILABLE":return e.t("error.language",{locale:i||r.value.locale,available:m.length>0?m.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:c})}},E=()=>{s()&&(a(!1),l.toggle().catch(()=>{})),o.cancel(),p=e.sessions.current()?.key,t.start({locale:r.value.locale,minConfidence:r.value.minConfidence}).catch(c=>{e.toast.show({variant:"error",title:e.t("error.title"),description:c instanceof Error?c.message:String(c)})})},C=()=>{t.stop().catch(()=>{})},f=()=>{o.cancel(),e.screen.current()?.composer.focus(),l.toggle().then(()=>a(c=>!c)).catch(c=>{a(!1),e.toast.show({variant:"error",title:e.t("pill.title"),description:c instanceof Error?`${e.t("error.winh")} ${c.message}`:e.t("error.winh")})})},h=()=>{if(u.value.mode==="windows"){f();return}const c=t.state()?.status??"idle";c==="starting"||c==="listening"?C():E()},k=()=>{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 c=t.state()?.status??"idle";(c==="starting"||c==="listening")&&t.stop().catch(()=>{}),(async()=>{try{const i=await o.lastAssistantText();if(!i.trim()){e.toast.show({variant:"default",title:e.t("read.title"),description:e.t("read.empty")});return}await o.speak(i)||e.toast.show({variant:"default",title:e.t("read.title"),description:e.t("read.empty")})}catch(i){e.toast.show({variant:"error",title:e.t("read.title"),description:i instanceof Error?i.message:e.t("read.error")})}})()},R=()=>{if(!o.speaking())return[{id:"start",label:e.t("read.idle"),icon:"outline-audio",run:k}];const c=o.paused(),i=[{id:"restart",label:e.t("read.restart"),icon:"outline-reset",run:()=>{o.restart()}}];return o.canPause()&&i.push({id:"pause",label:c?e.t("read.resume"):e.t("read.pause"),icon:"outline-audio",run:()=>o.togglePause()}),i.push({id:"stop",label:e.t("read.stop"),icon:"xmark-small",run:()=>o.cancel()}),i};t.on("final",c=>{const i=e.sessions.current()?.key;if(p&&i&&i!==p){e.toast.show({variant:"error",title:e.t("error.title"),description:e.t("toast.discarded")});return}const m=e.screen.current()?.composer;if(!m)return;const I=m.text(),N=r.value.trailingSpace&&I.length>0&&!/\s$/.test(I)?" ":"";m.insert(N+c.text),r.value.autoFocus&&m.focus()}),t.on("error",c=>{e.toast.show({variant:"error",title:e.t("error.title"),description:y(c.code,c.detail,c.available),persistent:c.code==="LANGUAGE_NOT_AVAILABLE"||c.code==="NO_RECOGNIZERS",duration:8e3})});const _=()=>{if(e.app.platform!=="desktop")return;if(u.value.mode==="windows")return s()?{label:e.t("pill.dictating"),icon:"outline-wave-audio",tone:"danger",title:e.t("pill.stop"),run:h}:{label:e.t("pill.idle"),icon:"outline-wave-audio",title:e.t("pill.winH"),run:h};const c=t.state()?.status??"idle";return c==="starting"?{label:e.t("pill.starting"),icon:"outline-wave-audio",title:e.t("pill.title"),run:h}:c==="listening"?{label:e.t("pill.listening"),icon:"outline-wave-audio",tone:"danger",title:e.t("pill.stop"),run:h}:c==="error"?{label:e.t("pill.error"),icon:"outline-wave-audio",tone:"warning",title:e.t("pill.title"),run:h}:{label:e.t("pill.idle"),icon:"outline-wave-audio",title:e.t("pill.title"),run:h}},P=()=>{if(e.app.platform!=="desktop")return;const c=o.speaking(),i=o.paused(),m=c?R().map(I=>({id:I.id,label:I.label,icon:I.icon,tone:I.id==="stop"?"danger":void 0,run:I.run})):[];return{label:c?i?e.t("read.paused"):e.t("read.speaking"):e.t("read.idle"),icon:"outline-audio",tone:c?"success":void 0,title:e.t("read.title"),rows:m.length>0?m:void 0,run:c?void 0:k}};e.add(S.ComposerPill,()=>({id:"dictate",show:()=>_()})),e.add(S.ComposerPill,()=>({id:"read",order:1,show:()=>P(),menu:c=>g.createComponent($e,{actions:R,get close(){return c.close}})})),e.add(S.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:h})),e.add(S.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(S.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:k})),e.add(S.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})})},Ce=S.Plugin.define({...ne,setup:Ee,main:he});exports.default=Ce;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-voice-dictation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
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/definition.ts
CHANGED
|
@@ -100,6 +100,10 @@ export const definition = Plugin.define({
|
|
|
100
100
|
"common.reason.no-microphone": "no microphone available",
|
|
101
101
|
"read.idle": "Read",
|
|
102
102
|
"read.speaking": "Reading…",
|
|
103
|
+
"read.paused": "Paused",
|
|
104
|
+
"read.pause": "Pause",
|
|
105
|
+
"read.resume": "Resume",
|
|
106
|
+
"read.restart": "Read again",
|
|
103
107
|
"read.stop": "Stop reading",
|
|
104
108
|
"read.title": "Read the last message aloud",
|
|
105
109
|
"command.read": "Read the last message aloud",
|
|
@@ -176,6 +180,10 @@ export const definition = Plugin.define({
|
|
|
176
180
|
"common.reason.no-microphone": "no hay micrófono disponible",
|
|
177
181
|
"read.idle": "Leer",
|
|
178
182
|
"read.speaking": "Leyendo…",
|
|
183
|
+
"read.paused": "Pausado",
|
|
184
|
+
"read.pause": "Pausar",
|
|
185
|
+
"read.resume": "Reanudar",
|
|
186
|
+
"read.restart": "Leer de nuevo",
|
|
179
187
|
"read.stop": "Detener lectura",
|
|
180
188
|
"read.title": "Leer en voz alta el último mensaje",
|
|
181
189
|
"command.read": "Leer en voz alta el último mensaje",
|
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,10 +1,47 @@
|
|
|
1
1
|
import { createSignal } from "solid-js"
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Command,
|
|
4
|
+
ComposerPill,
|
|
5
|
+
SettingsPage,
|
|
6
|
+
usePlugin,
|
|
7
|
+
type ComposerPillRow,
|
|
8
|
+
type ComposerPillView,
|
|
9
|
+
type IconName,
|
|
10
|
+
type Plugin,
|
|
11
|
+
} from "@opencode/plugin/gui"
|
|
3
12
|
import { Dictation, Speech, VoiceTyping } from "./contract"
|
|
4
13
|
import type { definition } from "./definition"
|
|
5
|
-
import { createSpeaker } from "./speak"
|
|
14
|
+
import { createSpeaker, type Speaker } from "./speak"
|
|
6
15
|
import { VoiceSettings } from "./settings"
|
|
7
16
|
|
|
17
|
+
interface ReadAction {
|
|
18
|
+
id: string
|
|
19
|
+
label: string
|
|
20
|
+
icon: IconName
|
|
21
|
+
run: () => void
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function ReadMenu(props: { actions: () => ReadAction[]; close: () => void }) {
|
|
25
|
+
const ctx = usePlugin<typeof definition>()
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<>
|
|
29
|
+
{props.actions().map((action) => (
|
|
30
|
+
<ctx.ui.Button
|
|
31
|
+
variant={action.id === "stop" ? "danger" : "neutral"}
|
|
32
|
+
icon={action.icon}
|
|
33
|
+
onClick={() => {
|
|
34
|
+
action.run()
|
|
35
|
+
props.close()
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
38
|
+
{action.label}
|
|
39
|
+
</ctx.ui.Button>
|
|
40
|
+
))}
|
|
41
|
+
</>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
8
45
|
/**
|
|
9
46
|
* Window setup: the microphone pill above the composer, the keybind and the
|
|
10
47
|
* `/dictado` slash command.
|
|
@@ -126,6 +163,30 @@ export const setup: Plugin.Setup<typeof definition> = (ctx) => {
|
|
|
126
163
|
})()
|
|
127
164
|
}
|
|
128
165
|
|
|
166
|
+
const readActions = (): ReadAction[] => {
|
|
167
|
+
if (!speaker.speaking()) {
|
|
168
|
+
return [{ id: "start", label: ctx.t("read.idle"), icon: "outline-audio", run: read }]
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const paused = speaker.paused()
|
|
172
|
+
const actions: ReadAction[] = [
|
|
173
|
+
{ id: "restart", label: ctx.t("read.restart"), icon: "outline-reset", run: () => void speaker.restart() },
|
|
174
|
+
]
|
|
175
|
+
|
|
176
|
+
if (speaker.canPause()) {
|
|
177
|
+
actions.push({
|
|
178
|
+
id: "pause",
|
|
179
|
+
label: paused ? ctx.t("read.resume") : ctx.t("read.pause"),
|
|
180
|
+
icon: "outline-audio",
|
|
181
|
+
run: () => speaker.togglePause(),
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
actions.push({ id: "stop", label: ctx.t("read.stop"), icon: "xmark-small", run: () => speaker.cancel() })
|
|
186
|
+
|
|
187
|
+
return actions
|
|
188
|
+
}
|
|
189
|
+
|
|
129
190
|
dictation.on("final", (data) => {
|
|
130
191
|
const current = ctx.sessions.current()?.key
|
|
131
192
|
|
|
@@ -203,29 +264,38 @@ export const setup: Plugin.Setup<typeof definition> = (ctx) => {
|
|
|
203
264
|
return { label: ctx.t("pill.idle"), icon: "outline-wave-audio", title: ctx.t("pill.title"), run: toggle }
|
|
204
265
|
}
|
|
205
266
|
|
|
267
|
+
const readView = (): ComposerPillView | undefined => {
|
|
268
|
+
if (ctx.app.platform !== "desktop") return undefined
|
|
269
|
+
|
|
270
|
+
const speaking = speaker.speaking()
|
|
271
|
+
const paused = speaker.paused()
|
|
272
|
+
const rows: ComposerPillRow[] = speaking
|
|
273
|
+
? readActions().map((action): ComposerPillRow => ({
|
|
274
|
+
id: action.id,
|
|
275
|
+
label: action.label,
|
|
276
|
+
icon: action.icon,
|
|
277
|
+
tone: action.id === "stop" ? "danger" : undefined,
|
|
278
|
+
run: action.run,
|
|
279
|
+
}))
|
|
280
|
+
: []
|
|
281
|
+
|
|
282
|
+
return {
|
|
283
|
+
label: speaking ? (paused ? ctx.t("read.paused") : ctx.t("read.speaking")) : ctx.t("read.idle"),
|
|
284
|
+
icon: "outline-audio",
|
|
285
|
+
tone: speaking ? "success" : undefined,
|
|
286
|
+
title: ctx.t("read.title"),
|
|
287
|
+
rows: rows.length > 0 ? rows : undefined,
|
|
288
|
+
run: speaking ? undefined : read,
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
206
292
|
ctx.add(ComposerPill, () => ({ id: "dictate", show: () => view() }))
|
|
207
293
|
|
|
208
294
|
ctx.add(ComposerPill, () => ({
|
|
209
295
|
id: "read",
|
|
210
296
|
order: 1,
|
|
211
|
-
show: () =>
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return speaker.speaking()
|
|
215
|
-
? {
|
|
216
|
-
label: ctx.t("read.speaking"),
|
|
217
|
-
icon: "outline-audio",
|
|
218
|
-
tone: "success",
|
|
219
|
-
title: ctx.t("read.stop"),
|
|
220
|
-
run: read,
|
|
221
|
-
}
|
|
222
|
-
: {
|
|
223
|
-
label: ctx.t("read.idle"),
|
|
224
|
-
icon: "outline-audio",
|
|
225
|
-
title: ctx.t("read.title"),
|
|
226
|
-
run: read,
|
|
227
|
-
}
|
|
228
|
-
},
|
|
297
|
+
show: () => readView(),
|
|
298
|
+
menu: (input) => <ReadMenu actions={readActions} close={input.close} />,
|
|
229
299
|
}))
|
|
230
300
|
|
|
231
301
|
ctx.add(Command, (): Command => ({
|