diff --git a/.gitignore b/.gitignore index 006cab8c27..2247d2adc3 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ UPCOMING_CHANGELOG.md logs/ *.bun-build tsconfig.tsbuildinfo +backups/ diff --git a/CHANGELOGS/2026-07-26-desktop-voice-control.md b/CHANGELOGS/2026-07-26-desktop-voice-control.md new file mode 100644 index 0000000000..844d14d600 --- /dev/null +++ b/CHANGELOGS/2026-07-26-desktop-voice-control.md @@ -0,0 +1,63 @@ +# Change Log — 2026-07-26 + +## Desktop microphone voice control + +### Summary + +Added built-in push-to-talk / toggle microphone voice control to the OpenCode Electron desktop app for Windows (and other desktop platforms). Speech is transcribed with cloud STT providers (Deepgram streaming, Groq Whisper, OpenAI Whisper). Short spoken phrases can be interpreted as voice commands. + +### Architecture + +- **Main process** (`packages/desktop/src/main/voice/`): recording orchestration, SoX/FFmpeg capture when available, cloud STT providers, global hotkey (`Alt+Space` by default), IPC + electron-store config. +- **Renderer fallback capture**: when SoX/FFmpeg is not installed, the renderer uses `getUserMedia`, downsamples to 16 kHz mono PCM, and streams chunks to the main process. +- **App UI** (`packages/app/src/voice/`): SolidJS voice context, mic button beside prompt submit, recording overlay, settings tab, command parser. +- **Config schema** (`packages/opencode/src/config/voice.ts`): Effect Schema for voice settings. + +### User setup + +1. Set one of: `DEEPGRAM_API_KEY`, `GROQ_API_KEY`, or `OPENAI_API_KEY` in the environment. +2. Optional: install SoX (`winget install sox`) for native capture; otherwise renderer MediaDevices is used automatically. +3. In Desktop Settings → Voice, choose provider/hotkey and enable commands. +4. Press the mic button or the global hotkey to dictate. Say `send`, `clear`, `stop`, etc. for commands. + +### Files added + +- `packages/desktop/src/main/voice/*` +- `packages/desktop/docs/voice-control.md` +- `packages/app/src/voice/*` +- `packages/opencode/src/config/voice.ts` +- `CHANGELOGS/2026-07-26-desktop-voice-control.md` +- `backups/20260726-121936/*` (pre-change backups) + +### Files modified + +- Desktop main/preload/renderer IPC surface +- Prompt input V2 (mic button + voice action wiring) +- Settings dialog (Voice tab) +- UI icon sets (microphone) +- App i18n dictionaries +- Permission dock (`data-action` hooks for voice accept/reject) + +### Notes + +- Existing npm plugin `opencode-voice` remains useful for CLI/TUI; this feature targets the Electron desktop app where plugins cannot access mic/DOM. +- Electron `globalShortcut` only fires on keydown, so the hotkey toggles recording (press to start, press again to stop). + +## Production installation — 2026-07-30 + +- Repaired the Windows checkout declaration shim used by app typechecking. +- Corrected voice recorder child-process typing, settings component contracts, public voice type naming, and resolved config typing. +- Verified `packages/desktop`, `packages/app`, `packages/opencode`, `packages/ui`, and `packages/session-ui` with their package typecheck commands. +- Verified the voice command parser with four passing unit tests. +- Built with `OPENCODE_CHANNEL=prod` and packaged `dist/opencode-desktop-win-x64.exe`. +- Installer SHA-256: `E4E4C855FB17A9027B993EFB1C59DB8DBC589A23EA9FB171F7401D359913D4EC`. +- Installed silently for the current user over OpenCode Desktop 1.18.4; the installer returned exit code 0. +- Confirmed the existing user-data backup at `C:\Users\axcho\OneDrive\Documents\Business\CloudAxc.io\Code\OpenCode\opencode-userdata-backup-20260727`. + +## CloudAxe repository publication — 2026-07-30 + +- Added `backups/` to root `.gitignore` so local timestamped safety copies stay untracked. +- Re-verified package typechecks for `desktop`, `app`, `opencode`, `ui`, and `session-ui`, plus voice command parser unit tests. +- Committed voice control source changes on `dev` as `feat(desktop): add voice control`. +- Published the fork (full upstream history preserved) to `https://repo.cloudaxe.io/CloudAxe/cloudaxe-opencode.git` via a separate `cloudaxe` remote, leaving GitHub `origin` unchanged. +- Pushed local `dev` to `cloudaxe/dev` and verified remote SHA match. diff --git a/packages/app/src/app.tsx b/packages/app/src/app.tsx index b4496ba7de..9c6a973c9d 100644 --- a/packages/app/src/app.tsx +++ b/packages/app/src/app.tsx @@ -58,6 +58,7 @@ import { SettingsProvider, useSettings } from "@/context/settings" import { TabsProvider, useTabs, type DraftTab } from "@/context/tabs" import { SDKProvider, useSDK } from "@/context/sdk" import { WslServersProvider } from "@/wsl/context" +import { VoiceOverlay, VoiceProvider } from "@/voice" import DirectoryLayout, { DirectoryDataProvider } from "@/pages/directory-layout" import LegacyLayout from "@/pages/layout" import NewLayout from "@/pages/layout-new" @@ -371,22 +372,27 @@ export function AppBaseProviders(props: ParentProps<{ locale?: Locale }>) { > - { - Sentry.captureException(error) - return - }} - > - - - - - {props.children} - - - - - + + { + Sentry.captureException(error) + return + }} + > + + + + + + {props.children} + + + + + + + + diff --git a/packages/app/src/components/prompt-input-v2.tsx b/packages/app/src/components/prompt-input-v2.tsx index 921d8ff45c..cb2292f0e5 100644 --- a/packages/app/src/components/prompt-input-v2.tsx +++ b/packages/app/src/components/prompt-input-v2.tsx @@ -6,7 +6,7 @@ import { Icon } from "@opencode-ai/ui/v2/icon" import { KeybindV2 } from "@opencode-ai/ui/v2/keybind-v2" import { TooltipV2 } from "@opencode-ai/ui/v2/tooltip-v2" import type { Prompt, ReferenceInfo } from "@opencode-ai/sdk/v2/client" -import { createEffect, createMemo, on, Show } from "solid-js" +import { createEffect, createMemo, on, onCleanup, Show } from "solid-js" import { ModelSelectorPopoverV2 } from "@/components/dialog-select-model" import { DialogSelectModelUnpaidV2 } from "@/components/dialog-select-model-unpaid-v2" import type { PromptInputProps } from "@/components/prompt-input/contracts" @@ -26,6 +26,7 @@ import { useSDK } from "@/context/sdk" import { useSync } from "@/context/sync" import { createSessionTabs } from "@/pages/session/helpers" import { showToast } from "@/utils/toast" +import { VoiceButton, useVoiceOptional } from "@/voice" import { PromptInputV2, type PromptInputV2Suggestion } from "@opencode-ai/session-ui/v2/prompt-input" import { createPromptInputV2Controller, @@ -50,10 +51,56 @@ export function PromptInputV2Composer(props: PromptInputV2ComposerProps) { const dialog = useDialog() const command = useCommand() const language = useLanguage() + const voice = useVoiceOptional() + const prompt = usePrompt() useCommands(props) useEditHandler(props) + createEffect(() => { + const unregister = voice.registerActions({ + insertText: (text) => { + const editor = document.querySelector('[data-component="prompt-input"]') + if (editor && typeof document.execCommand === "function") { + editor.focus() + document.execCommand("insertText", false, text.endsWith(" ") ? text : `${text} `) + return + } + props.controller.onInput(text) + }, + submit: () => props.controller.submit(), + clear: () => { + prompt.set([{ type: "text", content: "", start: 0, end: 0 }], 0) + props.controller.onInput("") + }, + stop: () => props.controller.stop(), + accept: () => { + document.querySelector('[data-action="permission-once"]')?.click() + }, + reject: () => { + document.querySelector('[data-action="permission-reject"]')?.click() + }, + scrollUp: () => { + const scroller = document.querySelector("[data-slot='session-scroll']") + scroller?.scrollBy({ top: -320, behavior: "smooth" }) + }, + scrollDown: () => { + const scroller = document.querySelector("[data-slot='session-scroll']") + scroller?.scrollBy({ top: 320, behavior: "smooth" }) + }, + focus: () => props.controller.restoreFocus(), + newline: () => { + const editor = document.querySelector('[data-component="prompt-input"]') + if (editor && typeof document.execCommand === "function") { + editor.focus() + document.execCommand("insertText", false, "\n") + } + }, + run: () => props.controller.submit(), + }) + onCleanup(unregister) + }) + return ( } modelControl={ {language.t("settings.tab.shortcuts")} + + + + {language.t("settings.tab.voice")} + + @@ -83,6 +90,9 @@ export const DialogSettings: Component<{ + + + diff --git a/packages/app/src/context/platform.tsx b/packages/app/src/context/platform.tsx index cf343bfa7e..4ddad0b7db 100644 --- a/packages/app/src/context/platform.tsx +++ b/packages/app/src/context/platform.tsx @@ -120,6 +120,9 @@ type PlatformBase = { /** Record a fatal renderer error in platform logs (desktop only) */ recordFatalRendererError?(error: FatalRendererErrorLog): Promise + + /** Desktop microphone voice control API (Electron only) */ + voice?: import("../voice/types").VoicePlatformAPI } export type Platform = PlatformBase & diff --git a/packages/app/src/custom-elements.d.ts b/packages/app/src/custom-elements.d.ts index e4ea0d6ceb..459c447707 120000 --- a/packages/app/src/custom-elements.d.ts +++ b/packages/app/src/custom-elements.d.ts @@ -1 +1,17 @@ -../../ui/src/custom-elements.d.ts \ No newline at end of file +import { DIFFS_TAG_NAME } from "@pierre/diffs" + +/** + * TypeScript declaration for the custom element. + * This tells TypeScript that is a valid JSX element in SolidJS. + * Required for using the @pierre/diffs web component in .tsx files. + */ + +declare module "solid-js" { + namespace JSX { + interface IntrinsicElements { + [DIFFS_TAG_NAME]: HTMLAttributes + } + } +} + +export {} \ No newline at end of file diff --git a/packages/app/src/i18n/ar.ts b/packages/app/src/i18n/ar.ts index 320738a6b0..9072f55f02 100644 --- a/packages/app/src/i18n/ar.ts +++ b/packages/app/src/i18n/ar.ts @@ -1005,4 +1005,49 @@ export const dict = { "error.childStore.persistedProjectIconCreateFailed": "فشل إنشاء أيقونة المشروع الدائمة", "error.childStore.storeCreateFailed": "فشل إنشاء المخزن", "terminal.connectionLost.abnormalClose": "تم إغلاق WebSocket بشكل غير طبيعي: {{code}}", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } diff --git a/packages/app/src/i18n/br.ts b/packages/app/src/i18n/br.ts index 9d6765ec94..91c5f9493e 100644 --- a/packages/app/src/i18n/br.ts +++ b/packages/app/src/i18n/br.ts @@ -1021,4 +1021,49 @@ export const dict = { "error.childStore.persistedProjectIconCreateFailed": "Falha ao criar ícone de projeto persistente", "error.childStore.storeCreateFailed": "Falha ao criar armazenamento", "terminal.connectionLost.abnormalClose": "WebSocket fechado anormalmente: {{code}}", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } diff --git a/packages/app/src/i18n/bs.ts b/packages/app/src/i18n/bs.ts index 915313c3e2..27eccbde0c 100644 --- a/packages/app/src/i18n/bs.ts +++ b/packages/app/src/i18n/bs.ts @@ -1097,4 +1097,49 @@ export const dict = { "error.childStore.persistedProjectIconCreateFailed": "Nije uspjelo kreiranje trajne ikone projekta", "error.childStore.storeCreateFailed": "Nije uspjelo kreiranje skladišta", "terminal.connectionLost.abnormalClose": "WebSocket zatvoren nenormalno: {{code}}", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } diff --git a/packages/app/src/i18n/da.ts b/packages/app/src/i18n/da.ts index 22fcdf39ce..76cbc87cee 100644 --- a/packages/app/src/i18n/da.ts +++ b/packages/app/src/i18n/da.ts @@ -1089,4 +1089,49 @@ export const dict = { "error.childStore.persistedProjectIconCreateFailed": "Kunne ikke oprette vedvarende projektikon", "error.childStore.storeCreateFailed": "Kunne ikke oprette lager", "terminal.connectionLost.abnormalClose": "WebSocket lukkede unormalt: {{code}}", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } diff --git a/packages/app/src/i18n/de.ts b/packages/app/src/i18n/de.ts index bc2ac9be38..aad215c22f 100644 --- a/packages/app/src/i18n/de.ts +++ b/packages/app/src/i18n/de.ts @@ -1034,4 +1034,49 @@ export const dict = { "error.childStore.persistedProjectIconCreateFailed": "Dauerhaftes Projekticon konnte nicht erstellt werden", "error.childStore.storeCreateFailed": "Speicher konnte nicht erstellt werden", "terminal.connectionLost.abnormalClose": "WebSocket abnormal geschlossen: {{code}}", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } satisfies Partial> diff --git a/packages/app/src/i18n/en.ts b/packages/app/src/i18n/en.ts index f03147f151..d9d4b66648 100644 --- a/packages/app/src/i18n/en.ts +++ b/packages/app/src/i18n/en.ts @@ -845,6 +845,54 @@ export const dict = { "settings.section.server": "Server", "settings.tab.general": "General", "settings.tab.shortcuts": "Shortcuts", + "settings.tab.voice": "Voice", + + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", + "settings.desktop.section.wsl": "WSL", "settings.desktop.wsl.title": "WSL integration", "settings.desktop.wsl.description": "Run the OpenCode server inside WSL on Windows.", diff --git a/packages/app/src/i18n/es.ts b/packages/app/src/i18n/es.ts index 00dca6704b..a7f2941893 100644 --- a/packages/app/src/i18n/es.ts +++ b/packages/app/src/i18n/es.ts @@ -1105,4 +1105,49 @@ export const dict = { "error.childStore.persistedProjectIconCreateFailed": "Error al crear icono de proyecto persistente", "error.childStore.storeCreateFailed": "Error al crear almacén", "terminal.connectionLost.abnormalClose": "WebSocket cerrado anormalmente: {{code}}", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } diff --git a/packages/app/src/i18n/fr.ts b/packages/app/src/i18n/fr.ts index d1487ff61e..daf4931038 100644 --- a/packages/app/src/i18n/fr.ts +++ b/packages/app/src/i18n/fr.ts @@ -1034,4 +1034,49 @@ export const dict = { "error.childStore.persistedProjectIconCreateFailed": "Échec de la création de l'icône de projet persistante", "error.childStore.storeCreateFailed": "Échec de la création du stockage", "terminal.connectionLost.abnormalClose": "WebSocket fermé anormalement : {{code}}", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } diff --git a/packages/app/src/i18n/ja.ts b/packages/app/src/i18n/ja.ts index 6a3b1ebcb0..ead63b1fba 100644 --- a/packages/app/src/i18n/ja.ts +++ b/packages/app/src/i18n/ja.ts @@ -1013,4 +1013,49 @@ export const dict = { "error.childStore.persistedProjectIconCreateFailed": "永続プロジェクトアイコンの作成に失敗しました", "error.childStore.storeCreateFailed": "ストアの作成に失敗しました", "terminal.connectionLost.abnormalClose": "WebSocket が異常終了しました: {{code}}", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } diff --git a/packages/app/src/i18n/ko.ts b/packages/app/src/i18n/ko.ts index 3c262ce3b9..ede002e8cd 100644 --- a/packages/app/src/i18n/ko.ts +++ b/packages/app/src/i18n/ko.ts @@ -1012,4 +1012,49 @@ export const dict = { "settings.general.row.pinchZoom.description": "트랙패드 핀치 및 Ctrl-스크롤 제스처로 확대/축소 허용", "settings.updates.action.downloading": "다운로드 중...", "settings.updates.action.installing": "설치 중...", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } diff --git a/packages/app/src/i18n/no.ts b/packages/app/src/i18n/no.ts index a4e8efb79d..aa9d7e4b46 100644 --- a/packages/app/src/i18n/no.ts +++ b/packages/app/src/i18n/no.ts @@ -1108,4 +1108,49 @@ export const dict = { "settings.general.row.pinchZoom.description": "Tillat knipebevegelser på styreflaten og Ctrl-rulling for å zoome", "settings.updates.action.downloading": "Laster ned...", "settings.updates.action.installing": "Installerer...", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } satisfies Partial> diff --git a/packages/app/src/i18n/pl.ts b/packages/app/src/i18n/pl.ts index f2e32ffeb8..83cca7ee6d 100644 --- a/packages/app/src/i18n/pl.ts +++ b/packages/app/src/i18n/pl.ts @@ -1021,4 +1021,49 @@ export const dict = { "error.childStore.persistedProjectIconCreateFailed": "Nie udało się utworzyć trwałej ikony projektu", "error.childStore.storeCreateFailed": "Nie udało się utworzyć magazynu", "terminal.connectionLost.abnormalClose": "WebSocket zamknięty nieprawidłowo: {{code}}", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } diff --git a/packages/app/src/i18n/ru.ts b/packages/app/src/i18n/ru.ts index fa6fb04d04..b55f1530f7 100644 --- a/packages/app/src/i18n/ru.ts +++ b/packages/app/src/i18n/ru.ts @@ -1100,4 +1100,49 @@ export const dict = { "error.childStore.persistedProjectIconCreateFailed": "Не удалось создать постоянный значок проекта", "error.childStore.storeCreateFailed": "Не удалось создать хранилище", "terminal.connectionLost.abnormalClose": "WebSocket закрыт аварийно: {{code}}", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } diff --git a/packages/app/src/i18n/th.ts b/packages/app/src/i18n/th.ts index 0ae67ee34e..fe8123e238 100644 --- a/packages/app/src/i18n/th.ts +++ b/packages/app/src/i18n/th.ts @@ -1084,4 +1084,49 @@ export const dict = { "error.childStore.persistedProjectIconCreateFailed": "ไม่สามารถสร้างไอคอนโปรเจกต์ถาวร", "error.childStore.storeCreateFailed": "ไม่สามารถสร้างที่เก็บ", "terminal.connectionLost.abnormalClose": "WebSocket ปิดอย่างผิดปกติ: {{code}}", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } diff --git a/packages/app/src/i18n/tr.ts b/packages/app/src/i18n/tr.ts index d401519af9..7ff969d03b 100644 --- a/packages/app/src/i18n/tr.ts +++ b/packages/app/src/i18n/tr.ts @@ -1103,4 +1103,49 @@ export const dict = { "error.childStore.persistedProjectIconCreateFailed": "Kalıcı proje simgesi oluşturulamadı", "error.childStore.storeCreateFailed": "Depo oluşturulamadı", "terminal.connectionLost.abnormalClose": "WebSocket anormal şekilde kapandı: {{code}}", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } satisfies Partial> diff --git a/packages/app/src/i18n/uk.ts b/packages/app/src/i18n/uk.ts index c949f41de2..e5a6a0717c 100644 --- a/packages/app/src/i18n/uk.ts +++ b/packages/app/src/i18n/uk.ts @@ -1102,4 +1102,49 @@ export const dict = { "workspace.reset.archived.one": "1 сесію буде заархівовано.", "workspace.reset.archived.many": "{{count}} сесій буде заархівовано.", "workspace.reset.note": "Це скине робочу область, щоб вона відповідала гілці за замовчуванням.", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } diff --git a/packages/app/src/i18n/zh.ts b/packages/app/src/i18n/zh.ts index 82d73ac3a6..698d71b865 100644 --- a/packages/app/src/i18n/zh.ts +++ b/packages/app/src/i18n/zh.ts @@ -1075,4 +1075,49 @@ export const dict = { "error.childStore.persistedProjectIconCreateFailed": "创建持久化项目图标失败", "error.childStore.storeCreateFailed": "创建存储失败", "terminal.connectionLost.abnormalClose": "WebSocket 异常关闭:{{code}}", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } satisfies Partial> diff --git a/packages/app/src/i18n/zht.ts b/packages/app/src/i18n/zht.ts index fbe80d95ee..2b5de99e33 100644 --- a/packages/app/src/i18n/zht.ts +++ b/packages/app/src/i18n/zht.ts @@ -1071,4 +1071,49 @@ export const dict = { "error.childStore.persistedProjectIconCreateFailed": "建立持續性專案圖示失敗", "error.childStore.storeCreateFailed": "建立儲存區失敗", "terminal.connectionLost.abnormalClose": "WebSocket 異常關閉:{{code}}", + "settings.tab.voice": "Voice", + "settings.voice.title": "Voice control", + "settings.voice.unavailable.title": "Desktop only", + "settings.voice.unavailable.description": "Microphone voice control is available in the OpenCode desktop app.", + "settings.voice.enabled.title": "Enable voice input", + "settings.voice.enabled.description": "Allow microphone dictation and voice commands in the desktop app", + "settings.voice.provider.title": "Speech provider", + "settings.voice.provider.description": "Cloud speech-to-text backend used for transcription", + "settings.voice.language.title": "Language", + "settings.voice.language.description": "Language hint for the speech provider (for example en, fr)", + "settings.voice.hotkey.title": "Global hotkey", + "settings.voice.hotkey.description": "Press to start or stop recording from anywhere (Electron accelerator)", + "settings.voice.commands.title": "Voice commands", + "settings.voice.commands.description": "Interpret short phrases like send, clear, or stop as commands", + "settings.voice.autoSend.title": "Auto-send", + "settings.voice.autoSend.description": "Submit the prompt automatically after a final transcription", + "settings.voice.api.title": "API keys", + "settings.voice.api.status.title": "Provider key", + "settings.voice.api.status.configured": "Found {{env}} in the environment", + "settings.voice.api.status.missing": "Set {{env}} in your environment, then restart OpenCode", + "settings.voice.api.ready": "Configured", + "settings.voice.api.missing": "Missing", + "settings.voice.api.docs.title": "Get an API key", + "settings.voice.api.docs.description": "Open the provider console to create a key", + "settings.voice.test.title": "Microphone test", + "settings.voice.test.description": "Record for a few seconds to verify capture and transcription", + "settings.voice.test.action": "Test microphone", + "settings.voice.test.started": "Recording... speak now", + "settings.voice.commands.list.title": "Supported commands", + "voice.tooltip.start": "Dictate ({{hotkey}})", + "voice.tooltip.stop": "Stop recording", + "voice.action.dictate": "Dictate", + "voice.action.stop": "Stop", + "voice.status.recording": "Recording", + "voice.status.processing": "Transcribing...", + "voice.status.listening": "Listening...", + "voice.command.send": "Submit the current prompt", + "voice.command.run": "Run / submit the current prompt", + "voice.command.accept": "Allow the pending permission once", + "voice.command.reject": "Deny the pending permission", + "voice.command.clear": "Clear the prompt input", + "voice.command.stop": "Stop the current generation", + "voice.command.scroll": "Scroll the session timeline", + "voice.command.focus": "Focus the prompt input", + "voice.command.newline": "Insert a newline in the prompt", } satisfies Partial> diff --git a/packages/app/src/pages/session/composer/session-permission-dock.tsx b/packages/app/src/pages/session/composer/session-permission-dock.tsx index 35a62f75cf..433a08e0b1 100644 --- a/packages/app/src/pages/session/composer/session-permission-dock.tsx +++ b/packages/app/src/pages/session/composer/session-permission-dock.tsx @@ -34,18 +34,31 @@ export function SessionPermissionDock(props: { <> - props.onDecide("reject")} disabled={props.responding}> + props.onDecide("reject")} + disabled={props.responding} + > {language.t("ui.permission.deny")} props.onDecide("always")} disabled={props.responding} > {language.t("ui.permission.allowAlways")} - props.onDecide("once")} disabled={props.responding}> + props.onDecide("once")} + disabled={props.responding} + > {language.t("ui.permission.allowOnce")} diff --git a/packages/app/src/voice/index.ts b/packages/app/src/voice/index.ts new file mode 100644 index 0000000000..7bb7e65c4f --- /dev/null +++ b/packages/app/src/voice/index.ts @@ -0,0 +1,17 @@ +export { VoiceProvider, useVoice, useVoiceOptional } from "./voice-context" +export { VoiceButton } from "./voice-button" +export { VoiceOverlay } from "./voice-overlay" +export { VoiceSettings } from "./voice-settings" +export { parseVoiceInput } from "./voice-command-parser" +export type { + RecordingState, + TranscriptionResult, + VoiceActions, + VoiceCommand, + VoiceConfig, + VoiceConfigView, + VoiceError, + VoiceParseResult, + VoicePlatformAPI, + VoiceProvider as VoiceProviderName, +} from "./types" diff --git a/packages/app/src/voice/types.ts b/packages/app/src/voice/types.ts new file mode 100644 index 0000000000..5dbad7280d --- /dev/null +++ b/packages/app/src/voice/types.ts @@ -0,0 +1,72 @@ +export type VoiceProvider = "deepgram" | "groq" | "openai-whisper" +export type RecordingState = "idle" | "recording" | "processing" + +export type VoiceConfig = { + enabled: boolean + provider: VoiceProvider + language: string + hotkey: string + commands: boolean + autoSend: boolean +} + +export type VoiceConfigView = VoiceConfig & { + apiKeyConfigured: boolean + apiKeyEnv: string +} + +export type TranscriptionResult = { + text: string + isFinal: boolean + confidence?: number +} + +export type VoiceError = { + code: "no-api-key" | "no-microphone" | "no-recorder" | "stt-failed" | "permission-denied" | "unknown" + message: string +} + +export type VoiceCommand = + | "send" + | "run" + | "accept" + | "reject" + | "clear" + | "stop" + | "scroll-up" + | "scroll-down" + | "focus" + | "newline" + +export type VoiceParseResult = + | { type: "command"; command: VoiceCommand; raw: string } + | { type: "text"; text: string } + +export type VoicePlatformAPI = { + getConfig: () => Promise + setConfig: (config: Partial) => Promise + start: () => Promise + stop: () => Promise + toggle: () => Promise + getState: () => Promise + sendAudioChunk: (chunk: ArrayBuffer) => Promise + checkApiKey: (provider?: VoiceProvider) => Promise<{ provider: VoiceProvider; configured: boolean; env: string }> + onTranscription: (cb: (result: TranscriptionResult) => void) => () => void + onRecordingState: (cb: (state: RecordingState) => void) => () => void + onError: (cb: (error: VoiceError) => void) => () => void + onCaptureMode: (cb: (mode: "native" | "renderer") => void) => () => void +} + +export type VoiceActions = { + insertText: (text: string) => void + submit: () => void + clear: () => void + stop: () => void + accept: () => void + reject: () => void + scrollUp: () => void + scrollDown: () => void + focus: () => void + newline: () => void + run: () => void +} diff --git a/packages/app/src/voice/voice-button.tsx b/packages/app/src/voice/voice-button.tsx new file mode 100644 index 0000000000..ea683ca485 --- /dev/null +++ b/packages/app/src/voice/voice-button.tsx @@ -0,0 +1,40 @@ +import { Show, type Component } from "solid-js" +import { Icon } from "@opencode-ai/ui/v2/icon" +import { IconButtonV2 } from "@opencode-ai/ui/v2/icon-button-v2" +import { TooltipV2 } from "@opencode-ai/ui/v2/tooltip-v2" +import { useLanguage } from "@/context/language" +import { useVoiceOptional } from "./voice-context" + +export const VoiceButton: Component<{ class?: string }> = (props) => { + const voice = useVoiceOptional() + const language = useLanguage() + + return ( + + + void voice.toggle()} + style={{ + color: voice.recording() ? "var(--color-danger, #ef4444)" : undefined, + animation: voice.recording() ? "voice-pulse 1.2s ease-in-out infinite" : undefined, + }} + icon={} + /> + + + ) +} diff --git a/packages/app/src/voice/voice-capture.ts b/packages/app/src/voice/voice-capture.ts new file mode 100644 index 0000000000..ff73671b3f --- /dev/null +++ b/packages/app/src/voice/voice-capture.ts @@ -0,0 +1,90 @@ +import type { VoicePlatformAPI } from "./types" + +/** + * Captures microphone audio in the renderer, downsamples to 16 kHz mono PCM, + * and streams chunks to the desktop main process for cloud STT. + */ +export function createRendererVoiceCapture(api: VoicePlatformAPI) { + let stream: MediaStream | undefined + let context: AudioContext | undefined + let processor: ScriptProcessorNode | undefined + let source: MediaStreamAudioSourceNode | undefined + let active = false + + const stop = () => { + active = false + processor?.disconnect() + source?.disconnect() + processor = undefined + source = undefined + void context?.close() + context = undefined + stream?.getTracks().forEach((track) => track.stop()) + stream = undefined + } + + const start = async () => { + if (active) return + active = true + stream = await navigator.mediaDevices.getUserMedia({ + audio: { + channelCount: 1, + echoCancellation: true, + noiseSuppression: true, + autoGainControl: true, + }, + video: false, + }) + + context = new AudioContext() + source = context.createMediaStreamSource(stream) + // ScriptProcessorNode is deprecated but widely available in Electron without AudioWorklet setup. + processor = context.createScriptProcessor(4096, 1, 1) + const inputRate = context.sampleRate + + processor.onaudioprocess = (event) => { + if (!active) return + const input = event.inputBuffer.getChannelData(0) + const pcm = downsampleTo16k(input, inputRate) + if (pcm.byteLength === 0) return + void api.sendAudioChunk(pcm) + } + + source.connect(processor) + processor.connect(context.destination) + } + + return { start, stop, get active() { return active } } +} + +function downsampleTo16k(input: Float32Array, inputRate: number) { + if (inputRate === 16000) return floatTo16BitPCM(input) + const ratio = inputRate / 16000 + const length = Math.floor(input.length / ratio) + const result = new Float32Array(length) + let offsetResult = 0 + let offsetInput = 0 + while (offsetResult < length) { + const next = Math.floor((offsetResult + 1) * ratio) + let accum = 0 + let count = 0 + for (let i = offsetInput; i < next && i < input.length; i += 1) { + accum += input[i] + count += 1 + } + result[offsetResult] = count ? accum / count : 0 + offsetResult += 1 + offsetInput = next + } + return floatTo16BitPCM(result) +} + +function floatTo16BitPCM(input: Float32Array) { + const buffer = new ArrayBuffer(input.length * 2) + const view = new DataView(buffer) + for (let i = 0; i < input.length; i += 1) { + const sample = Math.max(-1, Math.min(1, input[i])) + view.setInt16(i * 2, sample < 0 ? sample * 0x8000 : sample * 0x7fff, true) + } + return buffer +} diff --git a/packages/app/src/voice/voice-command-parser.test.ts b/packages/app/src/voice/voice-command-parser.test.ts new file mode 100644 index 0000000000..a7574d6e97 --- /dev/null +++ b/packages/app/src/voice/voice-command-parser.test.ts @@ -0,0 +1,23 @@ +import { describe, expect, test } from "bun:test" +import { parseVoiceInput } from "./voice-command-parser" + +describe("parseVoiceInput", () => { + test("detects send command", () => { + expect(parseVoiceInput("please send")).toEqual({ type: "command", command: "send", raw: "please send" }) + }) + + test("detects clear command", () => { + expect(parseVoiceInput("clear prompt")).toEqual({ type: "command", command: "clear", raw: "clear prompt" }) + }) + + test("returns text for longer phrases", () => { + expect(parseVoiceInput("please refactor the login form")).toEqual({ + type: "text", + text: "please refactor the login form", + }) + }) + + test("disables commands when requested", () => { + expect(parseVoiceInput("send", false)).toEqual({ type: "text", text: "send" }) + }) +}) diff --git a/packages/app/src/voice/voice-command-parser.ts b/packages/app/src/voice/voice-command-parser.ts new file mode 100644 index 0000000000..ac08a54eec --- /dev/null +++ b/packages/app/src/voice/voice-command-parser.ts @@ -0,0 +1,43 @@ +import type { VoiceCommand, VoiceParseResult } from "./types" + +const FILLERS = /\b(please|can you|could you|would you|hey|okay|ok|just|now)\b/gi + +const COMMANDS: Array<{ command: VoiceCommand; patterns: RegExp[] }> = [ + { command: "send", patterns: [/^send$/, /^submit$/, /^go$/, /^send (it|that|message|prompt)$/] }, + { command: "run", patterns: [/^run$/, /^execute$/, /^run (it|that|command)$/] }, + { command: "accept", patterns: [/^accept$/, /^approve$/, /^yes$/, /^accept (it|that|changes)$/] }, + { command: "reject", patterns: [/^reject$/, /^deny$/, /^no$/, /^reject (it|that|changes)$/] }, + { command: "clear", patterns: [/^clear$/, /^reset$/, /^erase$/, /^clear (prompt|input|text)$/] }, + { command: "stop", patterns: [/^stop$/, /^cancel$/, /^abort$/, /^stop (it|that|generation)$/] }, + { command: "scroll-up", patterns: [/^scroll up$/, /^page up$/] }, + { command: "scroll-down", patterns: [/^scroll down$/, /^page down$/] }, + { command: "focus", patterns: [/^focus$/, /^focus (prompt|input)$/] }, + { command: "newline", patterns: [/^new line$/, /^newline$/, /^line break$/] }, +] + +/** + * Detects short voice-control utterances. Longer phrases are treated as dictation text. + */ +export function parseVoiceInput(raw: string, enabled = true): VoiceParseResult { + const trimmed = raw.trim() + if (!trimmed) return { type: "text", text: "" } + if (!enabled) return { type: "text", text: trimmed } + + const normalized = trimmed + .toLowerCase() + .replace(FILLERS, " ") + .replace(/[^\w\s-]/g, " ") + .replace(/\s+/g, " ") + .trim() + + // Only treat short phrases as commands to avoid false positives in dictation + if (normalized.split(" ").length > 4) return { type: "text", text: trimmed } + + for (const entry of COMMANDS) { + if (entry.patterns.some((pattern) => pattern.test(normalized))) { + return { type: "command", command: entry.command, raw: trimmed } + } + } + + return { type: "text", text: trimmed } +} diff --git a/packages/app/src/voice/voice-context.tsx b/packages/app/src/voice/voice-context.tsx new file mode 100644 index 0000000000..6b5b8f03d1 --- /dev/null +++ b/packages/app/src/voice/voice-context.tsx @@ -0,0 +1,242 @@ +import { createSimpleContext } from "@opencode-ai/ui/context" +import { createEffect, createMemo, onCleanup } from "solid-js" +import { createStore } from "solid-js/store" +import { usePlatform } from "@/context/platform" +import { createRendererVoiceCapture } from "./voice-capture" +import { parseVoiceInput } from "./voice-command-parser" +import type { + RecordingState, + TranscriptionResult, + VoiceActions, + VoiceConfigView, + VoiceError, + VoicePlatformAPI, +} from "./types" + +const defaultConfig: VoiceConfigView = { + enabled: true, + provider: "deepgram", + language: "en", + hotkey: "Alt+Space", + commands: true, + autoSend: false, + apiKeyConfigured: false, + apiKeyEnv: "DEEPGRAM_API_KEY", +} + +const noopVoice = { + available: () => false, + state: () => "idle" as RecordingState, + interim: () => "", + finalText: () => "", + error: () => undefined as VoiceError | undefined, + config: () => defaultConfig, + durationMs: () => 0, + recording: () => false, + processing: () => false, + async start() {}, + async stop() {}, + async toggle() {}, + async setConfig(_patch: Partial) {}, + async refreshConfig() {}, + registerActions(_next: Partial) { + return () => undefined + }, + clearError() {}, +} + +const ctx = createSimpleContext({ + name: "Voice", + gate: false, + init: () => { + const platform = usePlatform() + const api = () => platform.voice + const [store, setStore] = createStore({ + available: false, + state: "idle" as RecordingState, + interim: "", + finalText: "", + error: undefined as VoiceError | undefined, + config: defaultConfig, + captureMode: "native" as "native" | "renderer", + durationMs: 0, + }) + + let actions: Partial = {} + let capture: ReturnType | undefined + let timer: ReturnType | undefined + let startedAt = 0 + + const refreshConfig = async () => { + const voice = api() + if (!voice) { + setStore("available", false) + return + } + setStore("available", true) + const config = await voice.getConfig() + setStore("config", config) + } + + createEffect(() => { + const voice = api() + if (!voice) { + setStore("available", false) + return + } + setStore("available", true) + void refreshConfig() + void voice.getState().then((state) => setStore("state", state)) + + const unsubState = voice.onRecordingState((state) => { + setStore("state", state) + if (state === "recording") { + startedAt = Date.now() + clearInterval(timer) + timer = setInterval(() => setStore("durationMs", Date.now() - startedAt), 200) + return + } + clearInterval(timer) + timer = undefined + if (state === "idle") { + setStore("durationMs", 0) + capture?.stop() + } + }) + + const unsubTranscription = voice.onTranscription((result) => { + handleTranscription(result) + }) + + const unsubError = voice.onError((error) => { + setStore("error", error) + capture?.stop() + }) + + const unsubCapture = voice.onCaptureMode((mode) => { + setStore("captureMode", mode) + if (mode === "renderer") void startRendererCapture(voice) + if (mode === "native") capture?.stop() + }) + + onCleanup(() => { + unsubState() + unsubTranscription() + unsubError() + unsubCapture() + clearInterval(timer) + capture?.stop() + }) + }) + + const startRendererCapture = async (voice: VoicePlatformAPI) => { + capture ??= createRendererVoiceCapture(voice) + try { + await capture.start() + } catch (error) { + setStore("error", { + code: "no-microphone", + message: error instanceof Error ? error.message : "Microphone access failed", + }) + await voice.stop() + } + } + + const handleTranscription = (result: TranscriptionResult) => { + setStore("interim", result.isFinal ? "" : result.text) + if (!result.isFinal) return + setStore("finalText", result.text) + const parsed = parseVoiceInput(result.text, store.config.commands) + if (parsed.type === "command") { + dispatchCommand(parsed.command) + return + } + if (!parsed.text) return + actions.insertText?.(parsed.text) + if (store.config.autoSend) actions.submit?.() + } + + const dispatchCommand = (command: string) => { + if (command === "send") return actions.submit?.() + if (command === "run") return actions.run?.() ?? actions.submit?.() + if (command === "accept") return actions.accept?.() + if (command === "reject") return actions.reject?.() + if (command === "clear") return actions.clear?.() + if (command === "stop") return actions.stop?.() + if (command === "scroll-up") return actions.scrollUp?.() + if (command === "scroll-down") return actions.scrollDown?.() + if (command === "focus") return actions.focus?.() + if (command === "newline") return actions.newline?.() + } + + return { + available: createMemo(() => store.available && store.config.enabled), + state: createMemo(() => store.state), + interim: createMemo(() => store.interim), + finalText: createMemo(() => store.finalText), + error: createMemo(() => store.error), + config: createMemo(() => store.config), + durationMs: createMemo(() => store.durationMs), + recording: createMemo(() => store.state === "recording"), + processing: createMemo(() => store.state === "processing"), + async start() { + const voice = api() + if (!voice) return + setStore("error", undefined) + setStore("interim", "") + await voice.start() + if (store.captureMode === "renderer") await startRendererCapture(voice) + }, + async stop() { + const voice = api() + if (!voice) return + capture?.stop() + await voice.stop() + }, + async toggle() { + const voice = api() + if (!voice) return + setStore("error", undefined) + if (store.state === "recording") { + capture?.stop() + await voice.stop() + return + } + await voice.start() + if (store.captureMode === "renderer") await startRendererCapture(voice) + }, + async setConfig(patch: Partial) { + const voice = api() + if (!voice) return + const next = await voice.setConfig(patch) + setStore("config", next) + }, + async refreshConfig() { + await refreshConfig() + }, + registerActions(next: Partial) { + actions = { ...actions, ...next } + return () => { + for (const key of Object.keys(next) as Array) { + if (actions[key] === next[key]) delete actions[key] + } + } + }, + clearError() { + setStore("error", undefined) + }, + } + }, +}) + +export const VoiceProvider = ctx.provider +export const useVoice = ctx.use + +/** Safe for storybook / non-app trees that omit VoiceProvider. */ +export function useVoiceOptional() { + try { + return useVoice() + } catch { + return noopVoice + } +} diff --git a/packages/app/src/voice/voice-overlay.tsx b/packages/app/src/voice/voice-overlay.tsx new file mode 100644 index 0000000000..17c93b47de --- /dev/null +++ b/packages/app/src/voice/voice-overlay.tsx @@ -0,0 +1,72 @@ +import { Show, type Component } from "solid-js" +import { Icon } from "@opencode-ai/ui/v2/icon" +import { useLanguage } from "@/context/language" +import { useVoice } from "./voice-context" + +export const VoiceOverlay: Component = () => { + const voice = useVoice() + const language = useLanguage() + + const seconds = () => Math.floor(voice.durationMs() / 1000) + const clock = () => { + const total = seconds() + const m = Math.floor(total / 60) + .toString() + .padStart(2, "0") + const s = (total % 60).toString().padStart(2, "0") + return `${m}:${s}` + } + + return ( + + + + + + + + + + + {language.t("voice.status.recording")} · {clock()} + + + + + {(error) => error().message} + + + + + void voice.stop()} + > + {language.t("voice.action.stop")} + + + + + + + + ) +} diff --git a/packages/app/src/voice/voice-settings.tsx b/packages/app/src/voice/voice-settings.tsx new file mode 100644 index 0000000000..f9e84ec285 --- /dev/null +++ b/packages/app/src/voice/voice-settings.tsx @@ -0,0 +1,220 @@ +import { For, Show, type Component, type JSX, createMemo, createSignal } from "solid-js" +import { ButtonV2 } from "@opencode-ai/ui/v2/button-v2" +import { SelectV2 } from "@opencode-ai/ui/v2/select-v2" +import { Switch } from "@opencode-ai/ui/v2/switch-v2" +import { TextInputV2 } from "@opencode-ai/ui/v2/text-input-v2" +import { useLanguage } from "@/context/language" +import { usePlatform } from "@/context/platform" +import { SettingsListV2 } from "@/components/settings-v2/parts/list" +import { SettingsRowV2 } from "@/components/settings-v2/parts/row" +import { Link } from "@/components/link" +import { useVoice } from "./voice-context" +import type { VoiceProvider } from "./types" + +const PROVIDERS: Array<{ id: VoiceProvider; label: string; docs: string }> = [ + { id: "deepgram", label: "Deepgram", docs: "https://console.deepgram.com/" }, + { id: "groq", label: "Groq Whisper", docs: "https://console.groq.com/keys" }, + { id: "openai-whisper", label: "OpenAI Whisper", docs: "https://platform.openai.com/api-keys" }, +] + +export const VoiceSettings: Component = () => { + const voice = useVoice() + const language = useLanguage() + const platform = usePlatform() + const [testing, setTesting] = createSignal(false) + const [testMessage, setTestMessage] = createSignal() + + const provider = createMemo(() => PROVIDERS.find((item) => item.id === voice.config().provider) ?? PROVIDERS[0]) + const providerOptions = () => PROVIDERS + + return ( + + + + + + } + > + + + + + void voice.setConfig({ enabled: checked })} /> + + + + + o.id} + label={(o) => o.label} + onSelect={(option) => { + if (!option) return + void voice.setConfig({ provider: option.id }) + }} + /> + + + + + void voice.setConfig({ language: event.currentTarget.value || "en" })} + /> + + + + + + void voice.setConfig({ hotkey: event.currentTarget.value || "Alt+Space" })} + /> + + + + + + void voice.setConfig({ commands: checked })} + /> + + + + + + void voice.setConfig({ autoSend: checked })} + /> + + + + + + + + {voice.config().apiKeyConfigured + ? language.t("settings.voice.api.ready") + : language.t("settings.voice.api.missing")} + + + + + {provider().label} + + + + { + setTesting(true) + setTestMessage(undefined) + try { + await voice.start() + setTestMessage(language.t("settings.voice.test.started")) + setTimeout(() => void voice.stop(), 3000) + } catch (error) { + setTestMessage(error instanceof Error ? error.message : String(error)) + } finally { + setTesting(false) + } + }} + > + {language.t("settings.voice.test.action")} + + + + + {testMessage()} + + + + + + {([phrase, key]) => ( + + + + )} + + + + + ) +} + +const SettingsSection: Component<{ title: string; children: JSX.Element }> = (props) => ( + + {props.title} + {props.children} + +) diff --git a/packages/desktop/docs/voice-control.md b/packages/desktop/docs/voice-control.md new file mode 100644 index 0000000000..a56064bc56 --- /dev/null +++ b/packages/desktop/docs/voice-control.md @@ -0,0 +1,64 @@ +# Desktop Voice Control + +## Overview + +OpenCode Desktop includes built-in microphone voice control for Windows (and other Electron platforms). Speak to fill the prompt, or issue short voice commands such as `send`, `clear`, and `stop`. + +## Requirements + +1. OpenCode Desktop app (Electron) +2. One cloud STT API key in the environment: + - `DEEPGRAM_API_KEY` (recommended for streaming) + - `GROQ_API_KEY` + - `OPENAI_API_KEY` +3. Optional native recorder: SoX (`winget install sox`) or FFmpeg + If missing, the app automatically falls back to browser `getUserMedia` capture in the renderer. + +## Usage + +1. Open **Settings → Voice** +2. Choose provider, language, and hotkey (default `Alt+Space`) +3. Press the microphone button next to Send, or press the global hotkey +4. Speak +5. Press the hotkey / button again to stop +6. Review the inserted text, then send (or say `send` if commands are enabled) + +## Voice commands + +When **Voice commands** is enabled, short phrases are treated as commands instead of dictation: + +| Phrase | Action | +| --- | --- | +| send / submit / go | Submit prompt | +| run / execute | Submit prompt | +| accept / approve / yes | Allow pending permission once | +| reject / deny / no | Deny pending permission | +| clear / reset / erase | Clear prompt | +| stop / cancel / abort | Stop generation | +| scroll up / scroll down | Scroll timeline | +| focus | Focus prompt | +| new line / line break | Insert newline | + +Longer utterances are always treated as dictation text. + +## Architecture + +``` +Hotkey / Mic button + → Desktop main VoiceManager + → Native SoX/FFmpeg capture OR renderer PCM stream + → Cloud STT (Deepgram WS / Groq / OpenAI Whisper) + → IPC transcription event + → App VoiceProvider + → Command parser OR prompt insert +``` + +### Packages + +- `packages/desktop/src/main/voice/` — main-process capture, STT, IPC, hotkeys +- `packages/app/src/voice/` — UI, context, command parser, settings +- `packages/opencode/src/config/voice.ts` — Effect Schema for voice config + +## Security + +API keys are read only from environment variables. They are never written to `opencode.json` or electron-store. diff --git a/packages/desktop/src/main/index.ts b/packages/desktop/src/main/index.ts index c7c1643092..6712b12064 100644 --- a/packages/desktop/src/main/index.ts +++ b/packages/desktop/src/main/index.ts @@ -15,6 +15,7 @@ import type { ServerReadyData } from "../preload/types" import { checkAppExists, resolveAppPath } from "./apps" import { CHANNEL } from "./constants" import { registerIpcHandlers, sendDeepLinks, sendMenuCommand } from "./ipc" +import { registerVoiceIpc } from "./voice" import { forwardInitializationFailure } from "./initialization" import { exportDebugLogs, initCrashReporter, initLogging, startNetLog, write as writeLog } from "./logging" import { parseMarkdown } from "./markdown" @@ -300,6 +301,7 @@ const main = Effect.gen(function* () { recordFatalRendererError: (error) => writeLog("renderer", "fatal renderer error", { ...error }, "error"), }) registerWslIpcHandlers(wslServers) + registerVoiceIpc() void updater.start() const updateTimer = setInterval(() => void updater.check(), 10 * 60 * 1000) updateTimer.unref() diff --git a/packages/desktop/src/main/store-keys.ts b/packages/desktop/src/main/store-keys.ts index f6f4030dba..3150cd8cda 100644 --- a/packages/desktop/src/main/store-keys.ts +++ b/packages/desktop/src/main/store-keys.ts @@ -5,3 +5,4 @@ export const OLD_LAYOUT_ELIGIBLE_KEY = "oldLayoutEligible" export const WSL_SERVERS_KEY = "wslServers" export const PINCH_ZOOM_ENABLED_KEY = "pinchZoomEnabled" export const WINDOW_IDS_KEY = "windowIds" +export const VOICE_CONFIG_KEY = "voiceConfig" diff --git a/packages/desktop/src/main/voice/index.ts b/packages/desktop/src/main/voice/index.ts new file mode 100644 index 0000000000..2680a7584b --- /dev/null +++ b/packages/desktop/src/main/voice/index.ts @@ -0,0 +1,14 @@ +export { registerVoiceIpc } from "./voice-ipc" +export { VoiceManager } from "./voice-manager" +export { VoiceRecorder } from "./voice-recorder" +export { createSttProvider } from "./voice-stt" +export { + DEFAULT_VOICE_CONFIG, + apiKeyEnvName, + resolveApiKey, + type RecordingState, + type TranscriptionResult, + type VoiceConfig, + type VoiceError, + type VoiceProvider, +} from "./voice-types" diff --git a/packages/desktop/src/main/voice/voice-ipc.ts b/packages/desktop/src/main/voice/voice-ipc.ts new file mode 100644 index 0000000000..b092a9bcba --- /dev/null +++ b/packages/desktop/src/main/voice/voice-ipc.ts @@ -0,0 +1,164 @@ +import { app, BrowserWindow, ipcMain, systemPreferences } from "electron" +import type { IpcMainInvokeEvent } from "electron" +import { getStore } from "../store" +import { VOICE_CONFIG_KEY } from "../store-keys" +import { VoiceManager } from "./voice-manager" +import { createVoiceShortcut } from "./voice-shortcut" +import { + DEFAULT_VOICE_CONFIG, + apiKeyEnvName, + resolveApiKey, + type VoiceConfig, + type VoiceProvider, +} from "./voice-types" + +export type VoiceIpcApi = { + dispose: () => void +} + +export function registerVoiceIpc(): VoiceIpcApi { + const broadcast = { + state(state: string) { + for (const win of BrowserWindow.getAllWindows()) { + if (win.isDestroyed()) continue + win.webContents.send("voice:state-changed", state) + } + }, + transcription(result: unknown) { + for (const win of BrowserWindow.getAllWindows()) { + if (win.isDestroyed()) continue + win.webContents.send("voice:transcription", result) + } + }, + error(error: unknown) { + for (const win of BrowserWindow.getAllWindows()) { + if (win.isDestroyed()) continue + win.webContents.send("voice:error", error) + } + }, + captureMode(mode: "native" | "renderer") { + for (const win of BrowserWindow.getAllWindows()) { + if (win.isDestroyed()) continue + win.webContents.send("voice:capture-mode", mode) + } + }, + } + + const manager = new VoiceManager({ + onState: (state) => broadcast.state(state), + onTranscription: (result) => broadcast.transcription(result), + onError: (error) => broadcast.error(error), + onCaptureMode: (mode) => broadcast.captureMode(mode), + }) + + manager.setConfig(loadConfig()) + + const press = async () => { + // globalShortcut only fires on keydown, so each press toggles recording. + if (manager.getState() === "recording") { + await manager.stop() + return + } + await manager.start() + } + + const shortcut = createVoiceShortcut({ + getConfig: () => manager.getConfig(), + onPress: () => { + void press() + }, + }) + shortcut.register(manager.getConfig().hotkey) + + ipcMain.handle("voice:get-config", () => { + const config = manager.getConfig() + return { + ...config, + apiKeyConfigured: !!resolveApiKey(config.provider), + apiKeyEnv: apiKeyEnvName(config.provider), + } + }) + + ipcMain.handle("voice:set-config", (_event: IpcMainInvokeEvent, patch: Partial) => { + const next = manager.setConfig(patch) + saveConfig(next) + shortcut.register(next.hotkey) + return { + ...next, + apiKeyConfigured: !!resolveApiKey(next.provider), + apiKeyEnv: apiKeyEnvName(next.provider), + } + }) + + ipcMain.handle("voice:start", async () => { + await ensureMicAccess() + await manager.start() + return manager.getState() + }) + + ipcMain.handle("voice:stop", async () => { + await manager.stop() + return manager.getState() + }) + + ipcMain.handle("voice:toggle", async () => { + await ensureMicAccess() + await manager.toggle() + return manager.getState() + }) + + ipcMain.handle("voice:get-state", () => manager.getState()) + + ipcMain.handle("voice:audio-chunk", (_event: IpcMainInvokeEvent, chunk: ArrayBuffer) => { + manager.ingestAudio(chunk) + }) + + ipcMain.handle("voice:check-api-key", (_event: IpcMainInvokeEvent, provider?: VoiceProvider) => { + const selected = provider ?? manager.getConfig().provider + return { + provider: selected, + configured: !!resolveApiKey(selected), + env: apiKeyEnvName(selected), + } + }) + + const dispose = () => { + shortcut.unregister() + manager.dispose() + } + + app.once("will-quit", dispose) + + return { dispose } +} + +function loadConfig(): VoiceConfig { + const store = getStore() + const raw = store.get(VOICE_CONFIG_KEY) + if (!raw || typeof raw !== "object") return { ...DEFAULT_VOICE_CONFIG } + const value = raw as Partial + return { + enabled: value.enabled ?? DEFAULT_VOICE_CONFIG.enabled, + provider: isProvider(value.provider) ? value.provider : DEFAULT_VOICE_CONFIG.provider, + language: typeof value.language === "string" ? value.language : DEFAULT_VOICE_CONFIG.language, + hotkey: typeof value.hotkey === "string" ? value.hotkey : DEFAULT_VOICE_CONFIG.hotkey, + commands: value.commands ?? DEFAULT_VOICE_CONFIG.commands, + autoSend: value.autoSend ?? DEFAULT_VOICE_CONFIG.autoSend, + } +} + +function saveConfig(config: VoiceConfig) { + getStore().set(VOICE_CONFIG_KEY, config) +} + +function isProvider(value: unknown): value is VoiceProvider { + return value === "deepgram" || value === "groq" || value === "openai-whisper" +} + +async function ensureMicAccess() { + if (process.platform !== "darwin") return + const status = systemPreferences.getMediaAccessStatus("microphone") + if (status === "granted") return + const ok = await systemPreferences.askForMediaAccess("microphone") + if (!ok) throw new Error("Microphone permission denied") +} diff --git a/packages/desktop/src/main/voice/voice-manager.ts b/packages/desktop/src/main/voice/voice-manager.ts new file mode 100644 index 0000000000..3a60e89a7c --- /dev/null +++ b/packages/desktop/src/main/voice/voice-manager.ts @@ -0,0 +1,165 @@ +import { VoiceRecorder } from "./voice-recorder" +import { createSttProvider, type SttProvider } from "./voice-stt" +import { + DEFAULT_VOICE_CONFIG, + type RecordingState, + type TranscriptionResult, + type VoiceConfig, + type VoiceError, +} from "./voice-types" + +export type VoiceManagerCallbacks = { + onState: (state: RecordingState) => void + onTranscription: (result: TranscriptionResult) => void + onError: (error: VoiceError) => void + /** Request renderer MediaDevices capture when SoX/FFmpeg is unavailable. */ + onCaptureMode: (mode: "native" | "renderer") => void +} + +export class VoiceManager { + private config: VoiceConfig = { ...DEFAULT_VOICE_CONFIG } + private state: RecordingState = "idle" + private recorder: VoiceRecorder | undefined + private stt: SttProvider | undefined + private captureMode: "native" | "renderer" = "native" + private toggleArmed = false + private lastPressAt = 0 + private callbacks: VoiceManagerCallbacks + + constructor(callbacks: VoiceManagerCallbacks) { + this.callbacks = callbacks + } + + getConfig() { + return { ...this.config } + } + + setConfig(patch: Partial) { + this.config = { + ...this.config, + ...patch, + provider: patch.provider ?? this.config.provider, + language: patch.language ?? this.config.language, + hotkey: patch.hotkey ?? this.config.hotkey, + enabled: patch.enabled ?? this.config.enabled, + commands: patch.commands ?? this.config.commands, + autoSend: patch.autoSend ?? this.config.autoSend, + } + return this.getConfig() + } + + getState() { + return this.state + } + + async start() { + if (!this.config.enabled) return + if (this.state === "recording" || this.state === "processing") return + + this.setState("recording") + const hasNative = !!VoiceRecorder.detectTool() + this.captureMode = hasNative ? "native" : "renderer" + this.callbacks.onCaptureMode(this.captureMode) + + try { + this.stt = createSttProvider(this.config) + await this.stt.start( + (result) => this.callbacks.onTranscription(result), + (error) => this.fail("stt-failed", error.message), + ) + } catch (error) { + this.fail("no-api-key", error instanceof Error ? error.message : String(error)) + return + } + + if (this.captureMode === "native") { + this.recorder = new VoiceRecorder() + this.recorder.on("data", (chunk) => this.stt?.send(chunk)) + this.recorder.on("error", (error) => { + // Fall back to renderer capture if native recorder fails at runtime + this.recorder?.stop() + this.recorder = undefined + this.captureMode = "renderer" + this.callbacks.onCaptureMode("renderer") + this.callbacks.onError({ code: "no-recorder", message: error.message }) + }) + this.recorder.start() + } + } + + async stop() { + if (this.state !== "recording") return + this.setState("processing") + this.recorder?.stop() + this.recorder = undefined + + const finalText = await this.stt?.stop().catch((error) => { + this.fail("stt-failed", error instanceof Error ? error.message : String(error)) + return undefined + }) + this.stt = undefined + + if (finalText) { + this.callbacks.onTranscription({ text: finalText, isFinal: true }) + } + this.setState("idle") + this.callbacks.onCaptureMode("native") + } + + async toggle() { + if (this.state === "recording") { + await this.stop() + return + } + await this.start() + } + + /** Push-to-talk press. Double-press within 400ms arms toggle mode. */ + async press() { + const now = Date.now() + if (now - this.lastPressAt < 400) { + this.toggleArmed = true + this.lastPressAt = now + await this.toggle() + return + } + this.lastPressAt = now + this.toggleArmed = false + await this.start() + } + + /** Push-to-talk release. Ignored when toggle mode is armed. */ + async release() { + if (this.toggleArmed) return + await this.stop() + } + + ingestAudio(chunk: ArrayBuffer | Buffer) { + if (this.state !== "recording") return + if (this.captureMode !== "renderer") return + const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk) + this.stt?.send(buffer) + } + + dispose() { + this.recorder?.stop() + this.recorder = undefined + void this.stt?.stop() + this.stt = undefined + this.setState("idle") + } + + private setState(state: RecordingState) { + this.state = state + this.callbacks.onState(state) + } + + private fail(code: VoiceError["code"], message: string) { + this.recorder?.stop() + this.recorder = undefined + void this.stt?.stop() + this.stt = undefined + this.setState("idle") + this.callbacks.onError({ code, message }) + } +} diff --git a/packages/desktop/src/main/voice/voice-recorder.ts b/packages/desktop/src/main/voice/voice-recorder.ts new file mode 100644 index 0000000000..293fcd7896 --- /dev/null +++ b/packages/desktop/src/main/voice/voice-recorder.ts @@ -0,0 +1,115 @@ +import { spawn, type ChildProcessByStdio } from "node:child_process" +import { EventEmitter } from "node:events" +import { existsSync } from "node:fs" +import { delimiter, join } from "node:path" +import type { Readable } from "node:stream" + +export type VoiceRecorderEvents = { + data: [Buffer] + error: [Error] + end: [] +} + +/** + * Captures 16 kHz mono signed 16-bit little-endian PCM via SoX or FFmpeg. + * When neither tool is available, callers should fall back to renderer MediaDevices capture. + */ +export class VoiceRecorder extends EventEmitter { + private process: ChildProcessByStdio | undefined + private running = false + + get active() { + return this.running + } + + static detectTool(): { tool: "sox" | "ffmpeg"; command: string } | undefined { + const sox = which("sox") + if (sox) return { tool: "sox", command: sox } + const ffmpeg = which("ffmpeg") + if (ffmpeg) return { tool: "ffmpeg", command: ffmpeg } + return + } + + start() { + if (this.running) return + const detected = VoiceRecorder.detectTool() + if (!detected) { + this.emit("error", new Error("No recording tool found. Install SoX (winget install sox) or FFmpeg.")) + return + } + + const child = + detected.tool === "sox" + ? spawn( + detected.command, + ["-d", "-q", "-r", "16000", "-c", "1", "-e", "signed-integer", "-b", "16", "-t", "raw", "-"], + { stdio: ["ignore", "pipe", "pipe"], windowsHide: true }, + ) + : spawn( + detected.command, + ffmpegArgs(), + { stdio: ["ignore", "pipe", "pipe"], windowsHide: true }, + ) + + this.process = child + this.running = true + + child.stdout.on("data", (chunk: Buffer) => { + this.emit("data", chunk) + }) + + child.stderr.on("data", (chunk: Buffer) => { + const message = chunk.toString("utf8").trim() + if (!message) return + if (/error|failed|cannot|unable/i.test(message) && !/Input #|Output #|Stream #|size=/i.test(message)) { + this.emit("error", new Error(message)) + } + }) + + child.on("error", (error) => { + this.running = false + this.emit("error", error instanceof Error ? error : new Error(String(error))) + }) + + child.on("close", () => { + this.running = false + this.process = undefined + this.emit("end") + }) + } + + stop() { + if (!this.process) { + this.running = false + return + } + const child = this.process + this.process = undefined + this.running = false + child.kill("SIGTERM") + setTimeout(() => { + if (!child.killed) child.kill("SIGKILL") + }, 1500).unref?.() + } +} + +function ffmpegArgs() { + if (process.platform === "win32") { + return ["-f", "dshow", "-i", "audio=default", "-ac", "1", "-ar", "16000", "-f", "s16le", "-acodec", "pcm_s16le", "pipe:1"] + } + if (process.platform === "darwin") { + return ["-f", "avfoundation", "-i", ":0", "-ac", "1", "-ar", "16000", "-f", "s16le", "-acodec", "pcm_s16le", "pipe:1"] + } + return ["-f", "alsa", "-i", "default", "-ac", "1", "-ar", "16000", "-f", "s16le", "-acodec", "pcm_s16le", "pipe:1"] +} + +function which(binary: string) { + const extensions = process.platform === "win32" ? [".exe", ".cmd", ".bat", ""] : [""] + const dirs = (process.env.PATH ?? "").split(delimiter) + for (const dir of dirs) { + for (const ext of extensions) { + const candidate = join(dir, binary + ext) + if (existsSync(candidate)) return candidate + } + } +} diff --git a/packages/desktop/src/main/voice/voice-shortcut.ts b/packages/desktop/src/main/voice/voice-shortcut.ts new file mode 100644 index 0000000000..98bd98feae --- /dev/null +++ b/packages/desktop/src/main/voice/voice-shortcut.ts @@ -0,0 +1,66 @@ +import { BrowserWindow, globalShortcut } from "electron" +import type { VoiceConfig } from "./voice-types" + +export type VoiceShortcutController = { + register: (hotkey: string) => boolean + unregister: () => void + getHotkey: () => string +} + +/** + * Electron globalShortcut only fires on keydown (not keyup), so true hold-to-talk + * is approximated: first press starts recording, second press stops. + * Double-press within 400ms is handled by VoiceManager as an explicit toggle. + */ +export function createVoiceShortcut(input: { + getConfig: () => VoiceConfig + onPress: () => void +}): VoiceShortcutController { + let current = "" + + const unregister = () => { + if (!current) return + try { + globalShortcut.unregister(current) + } catch {} + current = "" + } + + const register = (hotkey: string) => { + unregister() + if (!hotkey || !input.getConfig().enabled) return false + const accelerator = toAccelerator(hotkey) + const ok = globalShortcut.register(accelerator, () => { + const win = BrowserWindow.getFocusedWindow() ?? BrowserWindow.getAllWindows()[0] + if (win && !win.isDestroyed()) { + if (win.isMinimized()) win.restore() + win.show() + win.focus() + } + input.onPress() + }) + if (ok) current = accelerator + return ok + } + + return { + register, + unregister, + getHotkey: () => current, + } +} + +function toAccelerator(hotkey: string) { + return hotkey + .split("+") + .map((part) => { + const key = part.trim() + if (/^alt$/i.test(key)) return "Alt" + if (/^ctrl|control$/i.test(key)) return "Control" + if (/^shift$/i.test(key)) return "Shift" + if (/^meta|cmd|command|super|win$/i.test(key)) return "Super" + if (/^space$/i.test(key)) return "Space" + return key.length === 1 ? key.toUpperCase() : key + }) + .join("+") +} diff --git a/packages/desktop/src/main/voice/voice-stt.ts b/packages/desktop/src/main/voice/voice-stt.ts new file mode 100644 index 0000000000..400ad577ad --- /dev/null +++ b/packages/desktop/src/main/voice/voice-stt.ts @@ -0,0 +1,218 @@ +import { apiKeyEnvName, resolveApiKey, type TranscriptionResult, type VoiceConfig, type VoiceProvider } from "./voice-types" + +export type SttProvider = { + readonly provider: VoiceProvider + start(onTranscription: (result: TranscriptionResult) => void, onError: (error: Error) => void): Promise + send(chunk: Buffer): void + stop(): Promise +} + +export function createSttProvider(config: VoiceConfig): SttProvider { + if (config.provider === "deepgram") return createDeepgramProvider(config) + if (config.provider === "groq") return createHttpChunkProvider(config, "groq") + return createHttpChunkProvider(config, "openai-whisper") +} + +function requireKey(provider: VoiceProvider) { + const key = resolveApiKey(provider) + if (key) return key + throw new Error(`Missing ${apiKeyEnvName(provider)}. Set it in the environment before using voice input.`) +} + +function createDeepgramProvider(config: VoiceConfig): SttProvider { + let socket: WebSocket | undefined + let onTranscription: ((result: TranscriptionResult) => void) | undefined + let onError: ((error: Error) => void) | undefined + let finalText = "" + + return { + provider: "deepgram", + async start(nextTranscription, nextError) { + onTranscription = nextTranscription + onError = nextError + finalText = "" + const key = requireKey("deepgram") + const params = new URLSearchParams({ + model: "nova-2", + encoding: "linear16", + sample_rate: "16000", + channels: "1", + punctuate: "true", + interim_results: "true", + smart_format: "true", + }) + if (config.language && config.language !== "auto") params.set("language", config.language) + + const ws = new WebSocket(`wss://api.deepgram.com/v1/listen?${params}`, ["token", key]) + socket = ws + + await new Promise((resolve, reject) => { + const timer = setTimeout(() => reject(new Error("Deepgram connection timed out")), 10_000) + ws.addEventListener("open", () => { + clearTimeout(timer) + resolve() + }) + ws.addEventListener("error", () => { + clearTimeout(timer) + reject(new Error("Deepgram WebSocket failed to connect")) + }) + }) + + ws.addEventListener("message", (event) => { + const payload = typeof event.data === "string" ? event.data : undefined + if (!payload) return + const parsed = JSON.parse(payload) as { + type?: string + channel?: { alternatives?: Array<{ transcript?: string; confidence?: number }> } + is_final?: boolean + } + if (parsed.type && parsed.type !== "Results") return + const alternative = parsed.channel?.alternatives?.[0] + const text = alternative?.transcript?.trim() + if (!text) return + if (parsed.is_final) { + finalText = joinText(finalText, text) + onTranscription?.({ text: finalText, isFinal: true, confidence: alternative?.confidence }) + return + } + onTranscription?.({ text: joinText(finalText, text), isFinal: false, confidence: alternative?.confidence }) + }) + + ws.addEventListener("error", () => { + onError?.(new Error("Deepgram WebSocket error")) + }) + }, + send(chunk) { + if (socket?.readyState !== WebSocket.OPEN) return + socket.send(chunk) + }, + async stop() { + const ws = socket + socket = undefined + if (!ws) return finalText || undefined + if (ws.readyState === WebSocket.OPEN) { + ws.send(JSON.stringify({ type: "CloseStream" })) + await new Promise((resolve) => { + const timer = setTimeout(resolve, 1000) + ws.addEventListener("close", () => { + clearTimeout(timer) + resolve() + }) + }) + } + if (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING) ws.close() + return finalText || undefined + }, + } +} + +function createHttpChunkProvider(config: VoiceConfig, provider: "groq" | "openai-whisper"): SttProvider { + const chunkDurationMs = provider === "groq" ? (config as VoiceConfig & { chunkDurationMs?: number }).chunkDurationMs ?? 5000 : 10_000 + const bytesPerMs = (16000 * 2) / 1000 + const chunkBytes = Math.floor(chunkDurationMs * bytesPerMs) + + let buffer = Buffer.alloc(0) + let parts: string[] = [] + let onTranscription: ((result: TranscriptionResult) => void) | undefined + let onError: ((error: Error) => void) | undefined + let busy = Promise.resolve() + let active = false + + const flush = (force = false) => { + if (!active) return + if (!force && buffer.length < chunkBytes) return + if (buffer.length === 0) return + const payload = buffer + buffer = Buffer.alloc(0) + busy = busy + .then(async () => { + const text = await transcribeHttp(provider, payload, config.language) + if (!text) return + parts.push(text) + onTranscription?.({ text: parts.join(" "), isFinal: false }) + }) + .catch((error) => { + onError?.(error instanceof Error ? error : new Error(String(error))) + }) + } + + return { + provider, + async start(nextTranscription, nextError) { + requireKey(provider) + onTranscription = nextTranscription + onError = nextError + buffer = Buffer.alloc(0) + parts = [] + busy = Promise.resolve() + active = true + }, + send(chunk) { + if (!active) return + buffer = Buffer.concat([buffer, chunk]) + flush(false) + }, + async stop() { + active = false + flush(true) + await busy + const text = parts.join(" ").trim() + if (text) onTranscription?.({ text, isFinal: true }) + return text || undefined + }, + } +} + +async function transcribeHttp(provider: "groq" | "openai-whisper", pcm: Buffer, language: string) { + const key = requireKey(provider) + const wav = pcmToWav(pcm, 16000, 1) + const form = new FormData() + form.append("file", new Blob([new Uint8Array(wav)], { type: "audio/wav" }), "audio.wav") + form.append("model", provider === "groq" ? "whisper-large-v3-turbo" : "whisper-1") + form.append("response_format", "json") + if (language && language !== "auto") form.append("language", language) + + const url = + provider === "groq" + ? "https://api.groq.com/openai/v1/audio/transcriptions" + : "https://api.openai.com/v1/audio/transcriptions" + + const response = await fetch(url, { + method: "POST", + headers: { Authorization: `Bearer ${key}` }, + body: form, + }) + + if (!response.ok) { + const body = await response.text().catch(() => "") + throw new Error(`${provider} transcription failed (${response.status}): ${body || response.statusText}`) + } + + const json = (await response.json()) as { text?: string } + return json.text?.trim() ?? "" +} + +function pcmToWav(pcm: Buffer, sampleRate: number, channels: number) { + const header = Buffer.alloc(44) + const dataSize = pcm.length + header.write("RIFF", 0) + header.writeUInt32LE(36 + dataSize, 4) + header.write("WAVE", 8) + header.write("fmt ", 12) + header.writeUInt32LE(16, 16) + header.writeUInt16LE(1, 20) + header.writeUInt16LE(channels, 22) + header.writeUInt32LE(sampleRate, 24) + header.writeUInt32LE(sampleRate * channels * 2, 28) + header.writeUInt16LE(channels * 2, 32) + header.writeUInt16LE(16, 34) + header.write("data", 36) + header.writeUInt32LE(dataSize, 40) + return Buffer.concat([header, pcm]) +} + +function joinText(left: string, right: string) { + if (!left) return right + if (!right) return left + return `${left} ${right}` +} diff --git a/packages/desktop/src/main/voice/voice-types.ts b/packages/desktop/src/main/voice/voice-types.ts new file mode 100644 index 0000000000..d31b6075ed --- /dev/null +++ b/packages/desktop/src/main/voice/voice-types.ts @@ -0,0 +1,44 @@ +export type VoiceProvider = "deepgram" | "groq" | "openai-whisper" + +export type RecordingState = "idle" | "recording" | "processing" + +export type VoiceConfig = { + enabled: boolean + provider: VoiceProvider + language: string + hotkey: string + commands: boolean + autoSend: boolean +} + +export type TranscriptionResult = { + text: string + isFinal: boolean + confidence?: number +} + +export type VoiceError = { + code: "no-api-key" | "no-microphone" | "no-recorder" | "stt-failed" | "permission-denied" | "unknown" + message: string +} + +export const DEFAULT_VOICE_CONFIG: VoiceConfig = { + enabled: true, + provider: "deepgram", + language: "en", + hotkey: "Alt+Space", + commands: true, + autoSend: false, +} + +export function resolveApiKey(provider: VoiceProvider): string | undefined { + if (provider === "deepgram") return process.env.DEEPGRAM_API_KEY || process.env.OPENCODE_VOICE_DEEPGRAM_API_KEY + if (provider === "groq") return process.env.GROQ_API_KEY || process.env.OPENCODE_VOICE_GROQ_API_KEY + return process.env.OPENAI_API_KEY || process.env.OPENCODE_VOICE_OPENAI_API_KEY +} + +export function apiKeyEnvName(provider: VoiceProvider) { + if (provider === "deepgram") return "DEEPGRAM_API_KEY" + if (provider === "groq") return "GROQ_API_KEY" + return "OPENAI_API_KEY" +} diff --git a/packages/desktop/src/main/windows.ts b/packages/desktop/src/main/windows.ts index 7a594b5302..9ca1578d8c 100644 --- a/packages/desktop/src/main/windows.ts +++ b/packages/desktop/src/main/windows.ts @@ -21,7 +21,14 @@ const rendererProtocol = "oc" const rendererHost = "renderer" const clipboardWritePermission = "clipboard-sanitized-write" const notificationPermission = "notifications" -const rendererPermissions = new Set([clipboardWritePermission, notificationPermission]) +const mediaPermission = "media" +const microphonePermission = "microphone" +const rendererPermissions = new Set([ + clipboardWritePermission, + notificationPermission, + mediaPermission, + microphonePermission, +]) const oc2Theme = oc2ThemeJson as DesktopTheme const oc2Background = { light: resolveThemeVariant(oc2Theme.light, false)["background-base"], diff --git a/packages/desktop/src/preload/index.ts b/packages/desktop/src/preload/index.ts index 87eac1fa80..d2904897ff 100644 --- a/packages/desktop/src/preload/index.ts +++ b/packages/desktop/src/preload/index.ts @@ -1,5 +1,5 @@ import { contextBridge, ipcRenderer, webUtils } from "electron" -import type { ElectronAPI, WslServersEvent } from "./types" +import type { ElectronAPI, RecordingState, TranscriptionResult, VoiceError, WslServersEvent } from "./types" import type { UpdaterState } from "@opencode-ai/app/updater" const updaterCallbacks = new Set<(state: UpdaterState) => void>() @@ -123,6 +123,36 @@ const api: ElectronAPI = { exportDebugLogs: () => ipcRenderer.invoke("export-debug-logs"), setForceFocus: (enabled) => ipcRenderer.invoke("set-force-focus", enabled), recordFatalRendererError: (error) => ipcRenderer.invoke("record-fatal-renderer-error", error), + voice: { + getConfig: () => ipcRenderer.invoke("voice:get-config"), + setConfig: (config) => ipcRenderer.invoke("voice:set-config", config), + start: () => ipcRenderer.invoke("voice:start"), + stop: () => ipcRenderer.invoke("voice:stop"), + toggle: () => ipcRenderer.invoke("voice:toggle"), + getState: () => ipcRenderer.invoke("voice:get-state"), + sendAudioChunk: (chunk) => ipcRenderer.invoke("voice:audio-chunk", chunk), + checkApiKey: (provider) => ipcRenderer.invoke("voice:check-api-key", provider), + onTranscription: (cb) => { + const handler = (_event: Electron.IpcRendererEvent, result: TranscriptionResult) => cb(result) + ipcRenderer.on("voice:transcription", handler) + return () => ipcRenderer.removeListener("voice:transcription", handler) + }, + onRecordingState: (cb) => { + const handler = (_event: Electron.IpcRendererEvent, state: RecordingState) => cb(state) + ipcRenderer.on("voice:state-changed", handler) + return () => ipcRenderer.removeListener("voice:state-changed", handler) + }, + onError: (cb) => { + const handler = (_event: Electron.IpcRendererEvent, error: VoiceError) => cb(error) + ipcRenderer.on("voice:error", handler) + return () => ipcRenderer.removeListener("voice:error", handler) + }, + onCaptureMode: (cb) => { + const handler = (_event: Electron.IpcRendererEvent, mode: "native" | "renderer") => cb(mode) + ipcRenderer.on("voice:capture-mode", handler) + return () => ipcRenderer.removeListener("voice:capture-mode", handler) + }, + }, } contextBridge.exposeInMainWorld("api", api) diff --git a/packages/desktop/src/preload/types.ts b/packages/desktop/src/preload/types.ts index 5fbace72c7..42c9d1acbb 100644 --- a/packages/desktop/src/preload/types.ts +++ b/packages/desktop/src/preload/types.ts @@ -41,6 +41,44 @@ export type FatalRendererError = { os?: string } +export type VoiceProvider = "deepgram" | "groq" | "openai-whisper" +export type RecordingState = "idle" | "recording" | "processing" +export type VoiceConfig = { + enabled: boolean + provider: VoiceProvider + language: string + hotkey: string + commands: boolean + autoSend: boolean +} +export type VoiceConfigView = VoiceConfig & { + apiKeyConfigured: boolean + apiKeyEnv: string +} +export type TranscriptionResult = { + text: string + isFinal: boolean + confidence?: number +} +export type VoiceError = { + code: "no-api-key" | "no-microphone" | "no-recorder" | "stt-failed" | "permission-denied" | "unknown" + message: string +} +export type VoiceAPI = { + getConfig: () => Promise + setConfig: (config: Partial) => Promise + start: () => Promise + stop: () => Promise + toggle: () => Promise + getState: () => Promise + sendAudioChunk: (chunk: ArrayBuffer) => Promise + checkApiKey: (provider?: VoiceProvider) => Promise<{ provider: VoiceProvider; configured: boolean; env: string }> + onTranscription: (cb: (result: TranscriptionResult) => void) => () => void + onRecordingState: (cb: (state: RecordingState) => void) => () => void + onError: (cb: (error: VoiceError) => void) => () => void + onCaptureMode: (cb: (mode: "native" | "renderer") => void) => () => void +} + export type ElectronAPI = { killSidecar: () => Promise installCli: () => Promise @@ -106,4 +144,5 @@ export type ElectronAPI = { exportDebugLogs: () => Promise setForceFocus: (enabled: boolean) => Promise recordFatalRendererError: (error: FatalRendererError) => Promise + voice: VoiceAPI } diff --git a/packages/desktop/src/renderer/index.tsx b/packages/desktop/src/renderer/index.tsx index b7d2d9a74d..195f591049 100644 --- a/packages/desktop/src/renderer/index.tsx +++ b/packages/desktop/src/renderer/index.tsx @@ -244,6 +244,8 @@ const createPlatform = (windowState: DesktopWindowState): Platform => { recordFatalRendererError: (error) => window.api.recordFatalRendererError(error), + voice: window.api.voice, + restart: async () => { await window.api.killSidecar().catch(() => undefined) window.api.relaunch() diff --git a/packages/opencode/src/config/voice.ts b/packages/opencode/src/config/voice.ts new file mode 100644 index 0000000000..e61a4ea86d --- /dev/null +++ b/packages/opencode/src/config/voice.ts @@ -0,0 +1,54 @@ +export * as ConfigVoice from "./voice" + +import { Option, Schema } from "effect" + +export const Provider = Schema.Literals(["deepgram", "groq", "openai-whisper"]).annotate({ + description: "Cloud speech-to-text provider used by desktop voice input", +}) + +export const Info = Schema.Struct({ + enabled: Schema.optional(Schema.Boolean).annotate({ + description: "Enable microphone voice control in the desktop app", + }), + provider: Schema.optional(Provider), + language: Schema.optional(Schema.String).annotate({ + description: "BCP-47 language code passed to the STT provider (for example en)", + }), + hotkey: Schema.optional(Schema.String).annotate({ + description: "Global accelerator for push-to-talk / toggle (for example Alt+Space)", + }), + commands: Schema.optional(Schema.Boolean).annotate({ + description: "Parse short spoken phrases as voice commands instead of dictation", + }), + autoSend: Schema.optional(Schema.Boolean).annotate({ + description: "Automatically submit the prompt after a final transcription", + }), +}).annotate({ + identifier: "VoiceConfig", + description: "Desktop microphone voice control settings", +}) + +export type Info = typeof Info.Type +export type Resolved = Required + +export const defaults = { + enabled: true, + provider: "deepgram", + language: "en", + hotkey: "Alt+Space", + commands: true, + autoSend: false, +} satisfies Resolved + +export function normalize(input: unknown): Resolved { + const parsed = Schema.decodeUnknownOption(Info)(input) + if (!Option.isSome(parsed)) return { ...defaults } + return { + enabled: parsed.value.enabled ?? defaults.enabled, + provider: parsed.value.provider ?? defaults.provider, + language: parsed.value.language ?? defaults.language, + hotkey: parsed.value.hotkey ?? defaults.hotkey, + commands: parsed.value.commands ?? defaults.commands, + autoSend: parsed.value.autoSend ?? defaults.autoSend, + } +} diff --git a/packages/session-ui/src/v2/components/prompt-input/index.tsx b/packages/session-ui/src/v2/components/prompt-input/index.tsx index 9b011f03e9..7d7754b07b 100644 --- a/packages/session-ui/src/v2/components/prompt-input/index.tsx +++ b/packages/session-ui/src/v2/components/prompt-input/index.tsx @@ -39,6 +39,7 @@ export type PromptInputV2Props = { borderUnderlay?: boolean class?: string modelControl?: JSX.Element + actions?: JSX.Element attachKeybind?: string[] attachShortcut?: string } @@ -244,15 +245,18 @@ export function PromptInputV2(props: PromptInputV2Props) { )} - + + {props.actions} + + diff --git a/packages/ui/src/components/icon.tsx b/packages/ui/src/components/icon.tsx index 196635269a..7267c2e262 100644 --- a/packages/ui/src/components/icon.tsx +++ b/packages/ui/src/components/icon.tsx @@ -104,6 +104,7 @@ const icons = { providers: ``, models: ``, "arrow-undo-down": ``, + microphone: ``, } const spriteID = "opencode-icon-sprite" diff --git a/packages/ui/src/v2/components/icon.tsx b/packages/ui/src/v2/components/icon.tsx index b22d3140fe..f0d5bb87bc 100644 --- a/packages/ui/src/v2/components/icon.tsx +++ b/packages/ui/src/v2/components/icon.tsx @@ -149,6 +149,10 @@ const icons = { viewBox: "0 0 16 16", body: ``, }, + microphone: { + viewBox: "0 0 16 16", + body: ``, + }, } const spriteID = "opencode-v2-icon-sprite"