diff --git a/apps/web/src/components/ChatView.browser.test.tsx b/apps/web/src/components/ChatView.browser.test.tsx
index 96eb837db4d69..8a39fa8c7cec5 100644
--- a/apps/web/src/components/ChatView.browser.test.tsx
+++ b/apps/web/src/components/ChatView.browser.test.tsx
@@ -1,6 +1,6 @@
import { createMemoryHistory } from "@tanstack/react-router";
import { scopeProjectRef } from "@t3tools/client-runtime/environment";
-import { ThreadId } from "@t3tools/contracts";
+import { ThreadId, type VoiceTranscriptionDestination } from "@t3tools/contracts";
import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings";
import type * as Context from "effect/Context";
import { expect, it, vi } from "vite-plus/test";
@@ -13,6 +13,7 @@ import "~/components/ChatView";
import { DraftId, useComposerDraftStore } from "~/composerDraftStore";
import { __setClientSettingsForTests } from "~/hooks/useSettings";
import { getRouter } from "~/router";
+import { chooseAudioDestination } from "~/speech/voiceConsent";
import {
ENVIRONMENT_ID,
PROJECT_ID,
@@ -20,6 +21,8 @@ import {
type FakeDriver,
} from "../../test/fakeEnvironment";
import { render } from "../../test/render";
+import { useComposerDictation } from "~/dictation/useComposerDictation";
+import { useEnvironmentSpeechInput } from "~/speech/useEnvironmentSpeechInput";
// The socket is the only fake layer; see test/appScenarios.renders.tsx.
vi.mock("../../../../packages/client-runtime/src/connection/driver.ts", async (importOriginal) => {
@@ -31,6 +34,8 @@ vi.mock("../../../../packages/client-runtime/src/connection/driver.ts", async (i
return { ...actual, layer: Layer.succeed(actual.ConnectionDriver, fakeDriver) };
});
+vi.mock(import("~/dictation/useComposerDictation"), { spy: true });
+vi.mock(import("~/speech/useEnvironmentSpeechInput"), { spy: true });
vi.mock(import("~/rpc/requestLatencyState"), async (original) => ({
...(await original()),
trackRpcRequestSent: () => {},
@@ -65,3 +70,96 @@ it("a new draft does not load its reserved thread before the server lists it", a
// A 404 here marks the thread deleted, and the view never loads it once the send creates it.
expect(threadRequests).toEqual([]);
});
+
+const MICROPHONE_BUTTONS = /^(Dictate|Set up dictation|Start voice input)$/;
+
+async function renderDraftComposer(name: string) {
+ __setClientSettingsForTests({
+ ...DEFAULT_CLIENT_SETTINGS,
+ onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
+ });
+ const draftId = DraftId.make(`draft-microphone-${name}`);
+ useComposerDraftStore
+ .getState()
+ .setProjectDraftThreadId(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID), draftId, {
+ threadId: ThreadId.make(`thread-microphone-${name}`),
+ });
+ const router = getRouter(createMemoryHistory({ initialEntries: [`/draft/${draftId}`] }));
+ await router.load();
+ // AppRoot brings its own router.
+ return render(, { router: false });
+}
+
+it.each<{
+ readonly state: string;
+ readonly destination: VoiceTranscriptionDestination | null;
+ readonly microphone: string;
+}>([
+ { state: "no Voice destination", destination: null, microphone: "Set up dictation" },
+ {
+ state: "a chosen Voice destination",
+ destination: { kind: "cloud", environmentId: ENVIRONMENT_ID, provider: "openai" },
+ microphone: "Start voice input",
+ },
+])("the composer shows one microphone with $state", async ({ destination, microphone }) => {
+ using _environment = installFakeEnvironment([]);
+ using _voiceChoice = {
+ [Symbol.dispose]: () => window.localStorage.removeItem("t3code:voice-audio-grant:v1"),
+ };
+ if (destination) chooseAudioDestination(destination);
+ await using _app = await renderDraftComposer(destination?.kind ?? "none");
+ await expect.element(page.getByRole("button", { name: microphone, exact: true })).toBeVisible();
+
+ const microphones = page.getByRole("button", { name: MICROPHONE_BUTTONS }).elements();
+ expect(microphones.map((button) => button.getAttribute("aria-label"))).toEqual([microphone]);
+});
+
+const isMac = /Mac/.test(navigator.platform);
+
+it.each([
+ {
+ running: "Voice input",
+ chord: { key: " ", code: "Space", altKey: isMac, ctrlKey: !isMac, shiftKey: !isMac },
+ visibleControl: "Finish voice input",
+ },
+ {
+ running: "Dictation",
+ chord: { key: "d", code: "KeyD", metaKey: isMac, ctrlKey: !isMac, shiftKey: true },
+ visibleControl: "Stop and insert dictation",
+ },
+])("a running $running recording blocks the other shortcut", async (row) => {
+ const { useEnvironmentSpeechInput: realVoice } = await vi.importActual<
+ typeof import("~/speech/useEnvironmentSpeechInput")
+ >("~/speech/useEnvironmentSpeechInput");
+ const { useComposerDictation: realDictation } = await vi.importActual<
+ typeof import("~/dictation/useComposerDictation")
+ >("~/dictation/useComposerDictation");
+ const recording = { phase: "recording", error: null, errorAction: null } as const;
+ const voiceRunning = row.running === "Voice input";
+ const startVoice = vi.fn(async () => {});
+ const startDictation = vi.fn();
+ using _environment = installFakeEnvironment([]);
+ using _voice = vi.mocked(useEnvironmentSpeechInput).mockImplementation((input) => ({
+ ...realVoice(input),
+ available: true,
+ start: startVoice,
+ ...(voiceRunning ? { state: recording, blocksSubmission: true } : {}),
+ }));
+ using _dictation = vi.mocked(useComposerDictation).mockImplementation((input) => ({
+ ...realDictation(input),
+ start: startDictation,
+ ...(voiceRunning ? {} : { state: recording, active: true, readPhase: () => "recording" }),
+ }));
+ await using _app = await renderDraftComposer(`busy-${row.running}`);
+ await expect
+ .element(page.getByRole("button", { name: row.visibleControl, exact: true }))
+ .toBeVisible();
+
+ window.dispatchEvent(new KeyboardEvent("keydown", { ...row.chord, cancelable: true }));
+
+ expect(startVoice).not.toHaveBeenCalled();
+ expect(startDictation).not.toHaveBeenCalled();
+ await expect
+ .element(page.getByRole("button", { name: row.visibleControl, exact: true }))
+ .toBeVisible();
+});
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index 8cdb50ef6a256..e47a652892d1a 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -1941,6 +1941,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
ownerKey: questionAttachmentTarget ?? composerDraftTargetKey,
draftText: prompt,
disabled: dictationDisabled,
+ offerSetup: false,
readDraft: () => {
const snapshot = readComposerSnapshot();
return {
@@ -1963,13 +1964,15 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
window.requestAnimationFrame(() => composerEditorRef.current?.focusAt(cursor));
},
});
+ // Dictation and Voice input are separate systems that share one composer microphone.
+ const voiceInputOwnsMicrophone = speechInput.available && !dictation.active;
const { blocksSubmission: voiceInputActive, submitAfterDictation } = speechInput;
const voiceSendDisabledReason =
sendDisabledReason ?? (speechInput.preparing ? "Preparing voice input" : null);
const dictationShortcutLabel = useDictationShortcut({
keybindings,
speech: speechInput,
- disabled: dictationDisabled,
+ disabled: dictationDisabled || dictation.active,
terminalOpen,
modelPickerOpen: isComposerModelPickerOpen,
...(backgroundThread ? { targetRef: composerFormRef } : {}),
@@ -2695,7 +2698,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
useDictationHoldShortcut({
dictation,
- enabled: !composerTextUnavailable,
+ enabled: !composerTextUnavailable && !voiceInputActive,
isDictateShortcut: (event) =>
!isCommandPaletteOpen() &&
(backgroundThread
@@ -3718,11 +3721,13 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
>
{composerControls}
-
+ {voiceInputOwnsMicrophone ? null : (
+
+ )}
- {speechInput.available ? (
+ {voiceInputOwnsMicrophone ? (
<>