GeezerVison is showing github.com — Merge pull request #1 from YassinTM/voice/dictation · YassinTM/t3code@282c907
This repository was archived by the owner on Oct 29, 2026. It is now read-only.
File treeExpand file treeCollapse file tree Open diff view settings mobile/src/features/voice-input
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: FORK.md +9Lines changed: 9 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -39,6 +39,15 @@ Keep this list short; each one can conflict with upstream. | 39 | 39 |
| 40 | 40 | Put new features in new files where possible and hook them in with small edits. | 41 | 41 |
| | 42 | +## Fork features | | 43 | + | | 44 | +- **Dictation** (voice/dictation): upstream PR pingdotgg/t3code#19273, restructured so | | 45 | + its code lives in `*/dictation/*`, `contracts/src/dictation*.ts` and | | 46 | + `shared/src/spokenSkills.ts`, with one- or two-line hooks in `rpc.ts`, `ws.ts`, | | 47 | + `server.ts`, `settings.ts`, `RpcAuthorization.ts`, `RpcInstrumentation.ts`, | | 48 | + `clientRpcPermissions.ts` and a single block in `ChatComposer.tsx`. If upstream | | 49 | + merges dictation, drop the fork copy in favour of theirs. | | 50 | + | 42 | 51 | ## Setup (once) | 43 | 52 |
| 44 | 53 | - Repository secret `FORK_SYNC_TOKEN`: a fine-grained PAT for this repo only, | |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/window/DesktopWindow.test.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -94,6 +94,7 @@ function makeFakeBrowserWindow() { | 94 | 94 | reloadIgnoringCache: vi.fn(), | 95 | 95 | replaceMisspelling: vi.fn(), | 96 | 96 | send: vi.fn(), | | 97 | + session: { setPermissionRequestHandler: vi.fn() }, | 97 | 98 | setBackgroundThrottling: vi.fn(), | 98 | 99 | setWindowOpenHandler: vi.fn(), | 99 | 100 | toggleDevTools: vi.fn(), | |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/window/DesktopWindow.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,6 +34,7 @@ import * as ElectronApp from "../electron/ElectronApp.ts"; | 34 | 34 | import * as DesktopRendererHistory from "../telemetry/DesktopRendererHistory.ts"; | 35 | 35 | import { makeQuitShortcutHandler } from "./QuitHold.ts"; | 36 | 36 | import { copyContextMenuImage } from "./ContextMenuImage.ts"; | | 37 | +import { installMainWindowPermissions } from "./MainWindowPermissions.ts"; | 37 | 38 |
| 38 | 39 | const TITLEBAR_HEIGHT = 40; | 39 | 40 | // Matches --workspace-topbar-height in apps/web/src/index.css. Native macOS | @@ -391,6 +392,7 @@ export const make = Effect.gen(function* () { | 391 | 392 | }); | 392 | 393 |
| 393 | 394 | yield* rendererHistory.register(window.webContents, { surface: "main" }); | | 395 | + installMainWindowPermissions(window.webContents, environment.platform); | 394 | 396 | if (environment.platform === "darwin") { | 395 | 397 | window.setAutoHideCursor(false); | 396 | 398 | } | |
Collapse file Copy file name to clipboard +29Lines changed: 29 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import * as Electron from "electron"; | | 2 | + | | 3 | +/** | | 4 | + * Permission policy for the main window's session. A session without a | | 5 | + * handler grants every request, and this keeps that. The one addition is | | 6 | + * microphone capture from the main window on macOS: it asks the OS for | | 7 | + * consent first, so dictation gets the system prompt instead of silence | | 8 | + * when the app has not been allowed to record yet. | | 9 | + */ | | 10 | +export function installMainWindowPermissions( | | 11 | + webContents: Electron.WebContents, | | 12 | + platform: NodeJS.Platform, | | 13 | +): void { | | 14 | + webContents.session.setPermissionRequestHandler((requester, permission, callback, details) => { | | 15 | + const wantsMicrophone = | | 16 | + platform === "darwin" && | | 17 | + permission === "media" && | | 18 | + requester === webContents && | | 19 | + "mediaTypes" in details && | | 20 | + details.mediaTypes?.includes("audio") === true; | | 21 | + if (!wantsMicrophone) { | | 22 | + callback(true); | | 23 | + return; | | 24 | + } | | 25 | + void Electron.systemPreferences | | 26 | + .askForMediaAccess("microphone") | | 27 | + .then(callback, () => callback(false)); | | 28 | + }); | | 29 | +} |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/voice-input/voiceInputSession.test.ts +25-8Lines changed: 25 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -57,10 +57,11 @@ describe("global voice input", () => { | 57 | 57 | createTarget("second", () => "other prompt", vi.fn(), { start: 12, end: 12 }), | 58 | 58 | ); | 59 | 59 | await session.controller.stop(); | 60 | | - expect(commit).toHaveBeenCalledWith(expected, { | 61 | | - start: cursor, | 62 | | - end: cursor, | 63 | | - }); | | 60 | + expect(commit).toHaveBeenCalledWith( | | 61 | + expected, | | 62 | + { start: cursor, end: cursor }, | | 63 | + expect.anything(), | | 64 | + ); | 64 | 65 | }, | 65 | 66 | ); | 66 | 67 |
| @@ -134,7 +135,11 @@ describe("global voice input", () => { | 134 | 135 | transcription.resolve("spoken text"); | 135 | 136 | await (stopping ?? session.controller.stop()); | 136 | 137 | expect(recorder.record).toHaveBeenCalledTimes(1); | 137 | | - expect(firstCommit).toHaveBeenCalledWith("first spoken text", { start: 17, end: 17 }); | | 138 | + expect(firstCommit).toHaveBeenCalledWith( | | 139 | + "first spoken text", | | 140 | + { start: 17, end: 17 }, | | 141 | + expect.anything(), | | 142 | + ); | 138 | 143 | expect(secondCommit).not.toHaveBeenCalled(); | 139 | 144 | }, | 140 | 145 | ); | @@ -163,7 +168,11 @@ describe("global voice input", () => { | 163 | 168 | error: null, | 164 | 169 | url: recorder.uri, | 165 | 170 | }); | 166 | | - expect(commit).toHaveBeenCalledWith("first spoken text", { start: 17, end: 17 }); | | 171 | + expect(commit).toHaveBeenCalledWith( | | 172 | + "first spoken text", | | 173 | + { start: 17, end: 17 }, | | 174 | + expect.anything(), | | 175 | + ); | 167 | 176 | expect(session.controller.currentState.phase).toBe("idle"); | 168 | 177 | }); | 169 | 178 |
| @@ -238,7 +247,11 @@ describe("global voice input", () => { | 238 | 247 | expect(recorder.stop).not.toHaveBeenCalled(); | 239 | 248 | expect(session.controller.currentState.phase).toBe("recording"); | 240 | 249 | await session.controller.stop(); | 241 | | - expect(commit).toHaveBeenCalledWith("hello spoken text", { start: 17, end: 17 }); | | 250 | + expect(commit).toHaveBeenCalledWith( | | 251 | + "hello spoken text", | | 252 | + { start: 17, end: 17 }, | | 253 | + expect.anything(), | | 254 | + ); | 242 | 255 | }); | 243 | 256 |
| 244 | 257 | it("waits for canceled native work before starting a recording for another draft", async () => { | @@ -267,6 +280,10 @@ describe("global voice input", () => { | 267 | 280 | await session.controller.stop(); | 268 | 281 | expect(recorder.record).toHaveBeenCalledTimes(1); | 269 | 282 | expect(oldCommit).not.toHaveBeenCalled(); | 270 | | - expect(nextCommit).toHaveBeenCalledWith("second spoken text", { start: 18, end: 18 }); | | 283 | + expect(nextCommit).toHaveBeenCalledWith( | | 284 | + "second spoken text", | | 285 | + { start: 18, end: 18 }, | | 286 | + expect.anything(), | | 287 | + ); | 271 | 288 | }); | 272 | 289 | }); |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/voice-input/voiceInputSession.ts +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -58,7 +58,8 @@ export class VoiceInputSession { | 58 | 58 | dependencies.onStateChange(state); | 59 | 59 | }, | 60 | 60 | readDraft: () => this.target?.readDraft() ?? null, | 61 | | - commitDraft: (text, selection) => this.target?.commitDraft(text, selection), | | 61 | + commitDraft: (text, selection, inserted) => | | 62 | + this.target?.commitDraft(text, selection, inserted), | 62 | 63 | }); | 63 | 64 | } | 64 | 65 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/auth/RpcAuthorization.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { | 2 | 2 | CLIENT_GUARDED_RPC_SCOPES, | | 3 | + DICTATION_RPC_REQUIRED_SCOPES, | 3 | 4 | type DeviceListInput, | 4 | 5 | clientRpcRequiredScopes, | 5 | 6 | authScopeRequiredResponse, | @@ -201,6 +202,7 @@ export const RPC_REQUIRED_SCOPES = { | 201 | 202 | [WS_METHODS.deviceDetail]: AuthOrchestrationReadScope, | 202 | 203 | [WS_METHODS.deviceAction]: AuthOrchestrationOperateScope, | 203 | 204 | [WS_METHODS.subscribeDeviceState]: AuthOrchestrationReadScope, | | 205 | + ...DICTATION_RPC_REQUIRED_SCOPES, | 204 | 206 | [WS_METHODS.subscribeServerConfig]: AuthOrchestrationReadScope, | 205 | 207 | [WS_METHODS.subscribeServerLifecycle]: AuthOrchestrationReadScope, | 206 | 208 | [WS_METHODS.subscribeAuthAccess]: AuthAccessReadScope, | |
Collapse file Copy file name to clipboard +178Lines changed: 178 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import * as NodeServices from "@effect/platform-node/NodeServices"; | | 2 | +import { assert, it } from "@effect/vitest"; | | 3 | +import { DictationModelId } from "@t3tools/contracts"; | | 4 | +import * as Schema from "effect/Schema"; | | 5 | +import * as Clock from "effect/Clock"; | | 6 | +import * as Effect from "effect/Effect"; | | 7 | +import * as FileSystem from "effect/FileSystem"; | | 8 | +import * as NodeOS from "node:os"; | | 9 | +import * as Layer from "effect/Layer"; | | 10 | +import * as Path from "effect/Path"; | | 11 | +import * as Stream from "effect/Stream"; | | 12 | +import * as FetchHttpClient from "effect/http/FetchHttpClient"; | | 13 | +import * as HttpClient from "effect/http/HttpClient"; | | 14 | +import * as HttpClientResponse from "effect/http/HttpClientResponse"; | | 15 | +import * as ServerConfig from "../config.ts"; | | 16 | +import * as ServerSettings from "../serverSettings.ts"; | | 17 | +import * as Dictation from "./Dictation.ts"; | | 18 | +import * as DictationArtifacts from "./DictationArtifacts.ts"; | | 19 | +import * as DictationRecognizer from "./DictationRecognizer.ts"; | | 20 | +import { models } from "./models.ts"; | | 21 | + | | 22 | +const fixture = process.env.T3_DICTATION_E2E_FIXTURE; | | 23 | +const candidate = process.env.T3_DICTATION_E2E_MODEL ?? "parakeet-v3"; | | 24 | +if (!Schema.is(DictationModelId)(candidate)) | | 25 | + throw new Error("Unknown dictation verification model."); | | 26 | +const model = candidate; | | 27 | +const home = process.env.T3_DICTATION_E2E_HOME; | | 28 | + | | 29 | +/** Run explicitly with the spike model directory. Runtime + tokens use real HTTP; ONNX bytes stream from the verified cache. */ | | 30 | +it.live.skipIf(!fixture)( | | 31 | + "installs and transcribes through the real native runtime", | | 32 | + () => | | 33 | + Effect.gen(function* () { | | 34 | + const fs = yield* FileSystem.FileSystem; | | 35 | + const path = yield* Path.Path; | | 36 | + const network = yield* HttpClient.HttpClient; | | 37 | + const http = HttpClient.make((request) => { | | 38 | + const name = request.url.split("/").at(-1)!; | | 39 | + const file = | | 40 | + model === "parakeet-v3" | | 41 | + ? models[model].files.find( | | 42 | + (candidate) => candidate.name === name && name.endsWith(".onnx"), | | 43 | + ) | | 44 | + : undefined; | | 45 | + if (!file) return network.execute(request); | | 46 | + return Stream.toReadableStreamEffect(fs.stream(path.join(fixture!, name))).pipe( | | 47 | + Effect.map((stream) => | | 48 | + HttpClientResponse.fromWeb( | | 49 | + request, | | 50 | + new Response(stream, { headers: { "content-length": String(file.bytes) } }), | | 51 | + ), | | 52 | + ), | | 53 | + Effect.orDie, | | 54 | + ); | | 55 | + }); | | 56 | + const artifactsLayer = DictationArtifacts.layer.pipe( | | 57 | + Layer.provide(Layer.succeed(HttpClient.HttpClient, http)), | | 58 | + ); | | 59 | + const layer = Dictation.layer.pipe( | | 60 | + Layer.provide(DictationRecognizer.layer.pipe(Layer.provide(artifactsLayer))), | | 61 | + Layer.provideMerge(artifactsLayer), | | 62 | + Layer.provideMerge( | | 63 | + ServerSettings.layerTest({ dictation: { engine: "local", localModel: model } }), | | 64 | + ), | | 65 | + Layer.provide( | | 66 | + ServerConfig.layerTest(process.cwd(), home ?? { prefix: "t3-dictation-e2e-" }), | | 67 | + ), | | 68 | + ); | | 69 | + yield* Effect.gen(function* () { | | 70 | + const service = yield* Dictation.Dictation; | | 71 | + const settings = yield* ServerSettings.ServerSettingsService; | | 72 | + yield* service.stateStream.pipe( | | 73 | + Stream.filter((state) => state.ready), | | 74 | + Stream.take(1), | | 75 | + Stream.runDrain, | | 76 | + ); | | 77 | + yield* service.install({ model }); | | 78 | + assert.strictEqual((yield* service.state).ready, true); | | 79 | + const wav = Buffer.from(yield* fs.readFile(path.join(fixture!, "test_wavs", "en.wav"))); | | 80 | + assert.strictEqual(wav.toString("ascii", 0, 4), "RIFF"); | | 81 | + let sampleRate = 0; | | 82 | + let channels = 0; | | 83 | + let bits = 0; | | 84 | + let audio = Buffer.alloc(0); | | 85 | + for (let offset = 12; offset + 8 <= wav.length;) { | | 86 | + const name = wav.toString("ascii", offset, offset + 4); | | 87 | + const size = wav.readUInt32LE(offset + 4); | | 88 | + if (name === "fmt ") { | | 89 | + assert.strictEqual(wav.readUInt16LE(offset + 8), 1); | | 90 | + channels = wav.readUInt16LE(offset + 10); | | 91 | + sampleRate = wav.readUInt32LE(offset + 12); | | 92 | + bits = wav.readUInt16LE(offset + 22); | | 93 | + } | | 94 | + if (name === "data") audio = wav.subarray(offset + 8, offset + 8 + size); | | 95 | + offset += 8 + size + (size % 2); | | 96 | + } | | 97 | + assert.strictEqual(channels, 1); | | 98 | + assert.strictEqual(bits, 16); | | 99 | + if (sampleRate !== 16000) { | | 100 | + const converted = Buffer.alloc(Math.floor(((audio.length / 2) * 16000) / sampleRate) * 2); | | 101 | + for (let i = 0; i < converted.length / 2; i++) { | | 102 | + const position = (i * sampleRate) / 16000; | | 103 | + const left = Math.floor(position); | | 104 | + const right = Math.min(left + 1, audio.length / 2 - 1); | | 105 | + converted.writeInt16LE( | | 106 | + Math.round( | | 107 | + audio.readInt16LE(left * 2) * (1 - (position - left)) + | | 108 | + audio.readInt16LE(right * 2) * (position - left), | | 109 | + ), | | 110 | + i * 2, | | 111 | + ); | | 112 | + } | | 113 | + audio = converted; | | 114 | + } | | 115 | + const runs: { | | 116 | + text: string; | | 117 | + locale: string; | | 118 | + finishMs: number; | | 119 | + recordingSeconds: number; | | 120 | + startMs: number; | | 121 | + }[] = []; | | 122 | + for (let run = 0; run < (model === "whisper-turbo" ? 4 : 3); run++) { | | 123 | + if (model === "whisper-turbo" && run === 1) | | 124 | + yield* settings.updateSettings({ dictation: { language: "en" } }); | | 125 | + if (model === "whisper-turbo" && run === 3) | | 126 | + yield* settings.updateSettings({ dictation: { language: "nl" } }); | | 127 | + const recording = | | 128 | + run !== 2 | | 129 | + ? audio | | 130 | + : Buffer.concat( | | 131 | + Array.from({ length: 4 }, () => Buffer.concat([audio, Buffer.alloc(12800)])), | | 132 | + ); | | 133 | + const beforeStart = yield* Clock.currentTimeMillis; | | 134 | + const { sessionId } = yield* service.start; | | 135 | + const startMs = (yield* Clock.currentTimeMillis) - beforeStart; | | 136 | + let chunkCount = 0; | | 137 | + for (let offset = 0; offset < recording.length; offset += 3200) { | | 138 | + yield* service.append({ | | 139 | + sessionId, | | 140 | + seq: chunkCount++, | | 141 | + pcm: recording.subarray(offset, offset + 3200).toString("base64"), | | 142 | + }); | | 143 | + // Pace the recording as a microphone would, so background decoding overlaps speech. | | 144 | + yield* Effect.sleep("100 millis"); | | 145 | + } | | 146 | + const beforeFinish = yield* Clock.currentTimeMillis; | | 147 | + const result = yield* service.finish({ sessionId, chunkCount }); | | 148 | + runs.push({ | | 149 | + text: result.text, | | 150 | + locale: result.locale, | | 151 | + finishMs: (yield* Clock.currentTimeMillis) - beforeFinish, | | 152 | + recordingSeconds: recording.length / 32000, | | 153 | + startMs, | | 154 | + }); | | 155 | + assert.isTrue(result.text.length > 0); | | 156 | + if (model === "whisper-turbo" && run === 3) assert.strictEqual(result.locale, "nl"); | | 157 | + } | | 158 | + // This opt-in test reports the public fixture transcript; the product service never logs recordings. | | 159 | + process.stdout.write( | | 160 | + JSON.stringify( | | 161 | + { | | 162 | + model, | | 163 | + availableParallelism: NodeOS.availableParallelism(), | | 164 | + numThreads: Math.min(8, Math.max(1, NodeOS.availableParallelism())), | | 165 | + runs, | | 166 | + rssMB: Math.round(process.memoryUsage().rss / 1e6), | | 167 | + }, | | 168 | + null, | | 169 | + 2, | | 170 | + ) + "\n", | | 171 | + ); | | 172 | + }).pipe(Effect.provide(layer), Effect.scoped); | | 173 | + }).pipe( | | 174 | + Effect.provide(Layer.mergeAll(NodeServices.layer, FetchHttpClient.layer)), | | 175 | + Effect.scoped, | | 176 | + ), | | 177 | + { timeout: 900_000 }, | | 178 | +); |
|