GeezerVison is showing github.com — local: take PR #19273 head b8d5c37c onto main 01a93e7b51 · FOX-cOSMIC/FOX-cOSMIC-t3@1aea39c
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: apps/desktop/src/window/DesktopWindow.test.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,6 +93,7 @@ function makeFakeBrowserWindow() { | 93 | 93 | reloadIgnoringCache: vi.fn(), | 94 | 94 | replaceMisspelling: vi.fn(), | 95 | 95 | send: vi.fn(), | | 96 | + session: { setPermissionRequestHandler: vi.fn() }, | 96 | 97 | setBackgroundThrottling: vi.fn(), | 97 | 98 | setWindowOpenHandler: vi.fn(), | 98 | 99 | 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 |
|---|
@@ -37,6 +37,7 @@ import * as ElectronApp from "../electron/ElectronApp.ts"; | 37 | 37 | import * as DesktopRendererHistory from "../telemetry/DesktopRendererHistory.ts"; | 38 | 38 | import { makeQuitShortcutHandler } from "./QuitHold.ts"; | 39 | 39 | import { copyContextMenuImage } from "./ContextMenuImage.ts"; | | 40 | +import { installMainWindowPermissions } from "./MainWindowPermissions.ts"; | 40 | 41 |
| 41 | 42 | const TITLEBAR_HEIGHT = 40; | 42 | 43 | // Match --workspace-topbar-height in apps/web/src/index.css; native macOS buttons stay 14 points at any zoom. | @@ -417,6 +418,7 @@ export const make = Effect.gen(function* () { | 417 | 418 |
| 418 | 419 | pendingMainReveals.set(window, Effect.void); | 419 | 420 | yield* rendererHistory.register(window.webContents, { surface: "main" }); | | 421 | + installMainWindowPermissions(window.webContents, environment.platform); | 420 | 422 | if (environment.platform === "darwin") { | 421 | 423 | window.setAutoHideCursor(false); | 422 | 424 | } | |
Collapse file Copy file name to clipboard +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import * as Electron from "electron"; | | 2 | + | | 3 | +// Ask macOS for microphone consent before granting main-window capture; preserve other grants. | | 4 | +export function installMainWindowPermissions( | | 5 | + webContents: Electron.WebContents, | | 6 | + platform: NodeJS.Platform, | | 7 | +): void { | | 8 | + webContents.session.setPermissionRequestHandler((requester, permission, callback, details) => { | | 9 | + const wantsMicrophone = | | 10 | + platform === "darwin" && | | 11 | + permission === "media" && | | 12 | + requester === webContents && | | 13 | + "mediaTypes" in details && | | 14 | + details.mediaTypes?.includes("audio") === true; | | 15 | + if (!wantsMicrophone) { | | 16 | + callback(true); | | 17 | + return; | | 18 | + } | | 19 | + void Electron.systemPreferences | | 20 | + .askForMediaAccess("microphone") | | 21 | + .then(callback, () => callback(false)); | | 22 | + }); | | 23 | +} |
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 |
|---|
@@ -159,10 +159,11 @@ describe("global voice input", () => { | 159 | 159 | createTarget("second", () => "other prompt", vi.fn(), { start: 12, end: 12 }), | 160 | 160 | ); | 161 | 161 | await session.controller.stop(); | 162 | | - expect(commit).toHaveBeenCalledWith(expected, { | 163 | | - start: cursor, | 164 | | - end: cursor, | 165 | | - }); | | 162 | + expect(commit).toHaveBeenCalledWith( | | 163 | + expected, | | 164 | + { start: cursor, end: cursor }, | | 165 | + expect.anything(), | | 166 | + ); | 166 | 167 | }, | 167 | 168 | ); | 168 | 169 |
| @@ -236,7 +237,11 @@ describe("global voice input", () => { | 236 | 237 | transcription.resolve("spoken text"); | 237 | 238 | await (stopping ?? session.controller.stop()); | 238 | 239 | expect(recorder.record).toHaveBeenCalledTimes(1); | 239 | | - expect(firstCommit).toHaveBeenCalledWith("first spoken text", { start: 17, end: 17 }); | | 240 | + expect(firstCommit).toHaveBeenCalledWith( | | 241 | + "first spoken text", | | 242 | + { start: 17, end: 17 }, | | 243 | + expect.anything(), | | 244 | + ); | 240 | 245 | expect(secondCommit).not.toHaveBeenCalled(); | 241 | 246 | }, | 242 | 247 | ); | @@ -265,7 +270,11 @@ describe("global voice input", () => { | 265 | 270 | error: null, | 266 | 271 | url: recorder.uri, | 267 | 272 | }); | 268 | | - expect(commit).toHaveBeenCalledWith("first spoken text", { start: 17, end: 17 }); | | 273 | + expect(commit).toHaveBeenCalledWith( | | 274 | + "first spoken text", | | 275 | + { start: 17, end: 17 }, | | 276 | + expect.anything(), | | 277 | + ); | 269 | 278 | expect(session.controller.currentState.phase).toBe("idle"); | 270 | 279 | }); | 271 | 280 |
| @@ -324,7 +333,11 @@ describe("global voice input", () => { | 324 | 333 | expect(recorder.stop).not.toHaveBeenCalled(); | 325 | 334 | expect(session.controller.currentState.phase).toBe("recording"); | 326 | 335 | await session.controller.stop(); | 327 | | - expect(commit).toHaveBeenCalledWith("hello spoken text", { start: 17, end: 17 }); | | 336 | + expect(commit).toHaveBeenCalledWith( | | 337 | + "hello spoken text", | | 338 | + { start: 17, end: 17 }, | | 339 | + expect.anything(), | | 340 | + ); | 328 | 341 | }); | 329 | 342 |
| 330 | 343 | it("waits for canceled native work before starting a recording for another draft", async () => { | @@ -353,7 +366,11 @@ describe("global voice input", () => { | 353 | 366 | await session.controller.stop(); | 354 | 367 | expect(recorder.record).toHaveBeenCalledTimes(1); | 355 | 368 | expect(oldCommit).not.toHaveBeenCalled(); | 356 | | - expect(nextCommit).toHaveBeenCalledWith("second spoken text", { start: 18, end: 18 }); | | 369 | + expect(nextCommit).toHaveBeenCalledWith( | | 370 | + "second spoken text", | | 371 | + { start: 18, end: 18 }, | | 372 | + expect.anything(), | | 373 | + ); | 357 | 374 | }); | 358 | 375 |
| 359 | 376 | it("holds the screen awake and meters only while recording", async () => { | |
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 |
|---|
@@ -103,7 +103,8 @@ export class VoiceInputSession { | 103 | 103 | ...dependencies, | 104 | 104 | onStateChange: (state) => this.handleStateChange(state), | 105 | 105 | readDraft: () => this.target?.readDraft() ?? null, | 106 | | - commitDraft: (text, selection) => this.target?.commitDraft(text, selection), | | 106 | + commitDraft: (text, selection, inserted) => | | 107 | + this.target?.commitDraft(text, selection, inserted), | 107 | 108 | }); | 108 | 109 | } | 109 | 110 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/auth/RpcAuthorization.ts +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -205,6 +205,14 @@ export const RPC_REQUIRED_SCOPES = { | 205 | 205 | [WS_METHODS.deviceDetail]: AuthOrchestrationReadScope, | 206 | 206 | [WS_METHODS.deviceAction]: AuthOrchestrationOperateScope, | 207 | 207 | [WS_METHODS.subscribeDeviceState]: AuthOrchestrationReadScope, | | 208 | + [WS_METHODS.dictationInstall]: AuthOrchestrationOperateScope, | | 209 | + [WS_METHODS.dictationRemove]: AuthOrchestrationOperateScope, | | 210 | + [WS_METHODS.dictationStart]: AuthOrchestrationOperateScope, | | 211 | + [WS_METHODS.dictationWarm]: AuthOrchestrationOperateScope, | | 212 | + [WS_METHODS.dictationAppend]: AuthOrchestrationOperateScope, | | 213 | + [WS_METHODS.dictationFinish]: AuthOrchestrationOperateScope, | | 214 | + [WS_METHODS.dictationCancel]: AuthOrchestrationOperateScope, | | 215 | + [WS_METHODS.subscribeDictationState]: AuthOrchestrationReadScope, | 208 | 216 | [WS_METHODS.subscribeServerConfig]: AuthOrchestrationReadScope, | 209 | 217 | [WS_METHODS.subscribeServerLifecycle]: AuthOrchestrationReadScope, | 210 | 218 | [WS_METHODS.subscribeAuthAccess]: AuthAccessReadScope, | |
Collapse file Copy file name to clipboard +168Lines changed: 168 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)("installs and transcribes through the real native runtime", () => | | 31 | + Effect.gen(function* () { | | 32 | + const fs = yield* FileSystem.FileSystem; | | 33 | + const path = yield* Path.Path; | | 34 | + const network = yield* HttpClient.HttpClient; | | 35 | + const http = HttpClient.make((request) => { | | 36 | + const name = request.url.split("/").at(-1)!; | | 37 | + const file = | | 38 | + model === "parakeet-v3" | | 39 | + ? models[model].files.find( | | 40 | + (candidate) => candidate.name === name && name.endsWith(".onnx"), | | 41 | + ) | | 42 | + : undefined; | | 43 | + if (!file) return network.execute(request); | | 44 | + return Stream.toReadableStreamEffect(fs.stream(path.join(fixture!, name))).pipe( | | 45 | + Effect.map((stream) => | | 46 | + HttpClientResponse.fromWeb( | | 47 | + request, | | 48 | + new Response(stream, { headers: { "content-length": String(file.bytes) } }), | | 49 | + ), | | 50 | + ), | | 51 | + Effect.orDie, | | 52 | + ); | | 53 | + }); | | 54 | + const artifactsLayer = DictationArtifacts.layer.pipe( | | 55 | + Layer.provide(Layer.succeed(HttpClient.HttpClient, http)), | | 56 | + ); | | 57 | + const layer = Dictation.layer.pipe( | | 58 | + Layer.provide(DictationRecognizer.layer.pipe(Layer.provide(artifactsLayer))), | | 59 | + Layer.provideMerge(artifactsLayer), | | 60 | + Layer.provideMerge( | | 61 | + ServerSettings.layerTest({ dictation: { engine: "local", localModel: model } }), | | 62 | + ), | | 63 | + Layer.provide(ServerConfig.layerTest(process.cwd(), home ?? { prefix: "t3-dictation-e2e-" })), | | 64 | + ); | | 65 | + yield* Effect.gen(function* () { | | 66 | + const service = yield* Dictation.Dictation; | | 67 | + const settings = yield* ServerSettings.ServerSettingsService; | | 68 | + yield* service.stateStream.pipe( | | 69 | + Stream.filter((state) => state.ready), | | 70 | + Stream.take(1), | | 71 | + Stream.runDrain, | | 72 | + ); | | 73 | + yield* service.install({ model }); | | 74 | + assert.strictEqual((yield* service.state).ready, true); | | 75 | + const wav = Buffer.from(yield* fs.readFile(path.join(fixture!, "test_wavs", "en.wav"))); | | 76 | + assert.strictEqual(wav.toString("ascii", 0, 4), "RIFF"); | | 77 | + let sampleRate = 0; | | 78 | + let channels = 0; | | 79 | + let bits = 0; | | 80 | + let audio = Buffer.alloc(0); | | 81 | + for (let offset = 12; offset + 8 <= wav.length;) { | | 82 | + const name = wav.toString("ascii", offset, offset + 4); | | 83 | + const size = wav.readUInt32LE(offset + 4); | | 84 | + if (name === "fmt ") { | | 85 | + assert.strictEqual(wav.readUInt16LE(offset + 8), 1); | | 86 | + channels = wav.readUInt16LE(offset + 10); | | 87 | + sampleRate = wav.readUInt32LE(offset + 12); | | 88 | + bits = wav.readUInt16LE(offset + 22); | | 89 | + } | | 90 | + if (name === "data") audio = wav.subarray(offset + 8, offset + 8 + size); | | 91 | + offset += 8 + size + (size % 2); | | 92 | + } | | 93 | + assert.strictEqual(channels, 1); | | 94 | + assert.strictEqual(bits, 16); | | 95 | + if (sampleRate !== 16000) { | | 96 | + const converted = Buffer.alloc(Math.floor(((audio.length / 2) * 16000) / sampleRate) * 2); | | 97 | + for (let i = 0; i < converted.length / 2; i++) { | | 98 | + const position = (i * sampleRate) / 16000; | | 99 | + const left = Math.floor(position); | | 100 | + const right = Math.min(left + 1, audio.length / 2 - 1); | | 101 | + converted.writeInt16LE( | | 102 | + Math.round( | | 103 | + audio.readInt16LE(left * 2) * (1 - (position - left)) + | | 104 | + audio.readInt16LE(right * 2) * (position - left), | | 105 | + ), | | 106 | + i * 2, | | 107 | + ); | | 108 | + } | | 109 | + audio = converted; | | 110 | + } | | 111 | + const runs: { | | 112 | + text: string; | | 113 | + locale: string; | | 114 | + finishMs: number; | | 115 | + recordingSeconds: number; | | 116 | + startMs: number; | | 117 | + }[] = []; | | 118 | + for (let run = 0; run < (model === "whisper-turbo" ? 4 : 3); run++) { | | 119 | + if (model === "whisper-turbo" && run === 1) | | 120 | + yield* settings.updateSettings({ dictation: { language: "en" } }); | | 121 | + if (model === "whisper-turbo" && run === 3) | | 122 | + yield* settings.updateSettings({ dictation: { language: "nl" } }); | | 123 | + const recording = | | 124 | + run !== 2 | | 125 | + ? audio | | 126 | + : Buffer.concat( | | 127 | + Array.from({ length: 4 }, () => Buffer.concat([audio, Buffer.alloc(12800)])), | | 128 | + ); | | 129 | + const beforeStart = yield* Clock.currentTimeMillis; | | 130 | + const { sessionId } = yield* service.start; | | 131 | + const startMs = (yield* Clock.currentTimeMillis) - beforeStart; | | 132 | + let chunkCount = 0; | | 133 | + for (let offset = 0; offset < recording.length; offset += 3200) { | | 134 | + yield* service.append({ | | 135 | + sessionId, | | 136 | + seq: chunkCount++, | | 137 | + pcm: recording.subarray(offset, offset + 3200).toString("base64"), | | 138 | + }); | | 139 | + } | | 140 | + const beforeFinish = yield* Clock.currentTimeMillis; | | 141 | + const result = yield* service.finish({ sessionId, chunkCount }); | | 142 | + runs.push({ | | 143 | + text: result.text, | | 144 | + locale: result.locale, | | 145 | + finishMs: (yield* Clock.currentTimeMillis) - beforeFinish, | | 146 | + recordingSeconds: recording.length / 32000, | | 147 | + startMs, | | 148 | + }); | | 149 | + assert.isTrue(result.text.length > 0); | | 150 | + if (model === "whisper-turbo" && run === 3) assert.strictEqual(result.locale, "nl"); | | 151 | + } | | 152 | + // This opt-in test reports the public fixture transcript; the product service never logs recordings. | | 153 | + process.stdout.write( | | 154 | + JSON.stringify( | | 155 | + { | | 156 | + model, | | 157 | + availableParallelism: NodeOS.availableParallelism(), | | 158 | + numThreads: Math.min(8, Math.max(1, NodeOS.availableParallelism())), | | 159 | + runs, | | 160 | + rssMB: Math.round(process.memoryUsage().rss / 1e6), | | 161 | + }, | | 162 | + null, | | 163 | + 2, | | 164 | + ) + "\n", | | 165 | + ); | | 166 | + }).pipe(Effect.provide(layer), Effect.scoped); | | 167 | + }).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, FetchHttpClient.layer)), Effect.scoped), | | 168 | +); |
|