The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 21:00 UTC
fix(web): voice settings and dictation match the rest of the app (#33140)
maria committed
Nov 12, 2026 at 04:10 UTC
55a94e20293ff447ecf3b21e0d93a87abb0a2344
26 files changed
+1495
-1107
apps/web/src/components/chat/AssistantCitationCommentEditor.tsx
+1
-9
@@ -113,15 +113,7 @@ export function AssistantCitationCommentEditor({
113
</p>
114
) : null}
115
<div className="mt-2 flex flex-wrap items-center justify-end gap-2">
116
- <div
117
- className={
118
- speech.state.phase === "idle"
119
- ? "contents"
120
- : "flex basis-full flex-wrap gap-2 *:min-w-0 *:grow **:data-[slot=voice-input-pill]:w-full"
121
- }
122
- >
123
- <TextFieldSpeechControls speech={speech} />
124
- </div>
116
+ <TextFieldSpeechControls speech={speech} />
117
<Button
118
variant="outline"
119
size="xs"
apps/web/src/components/chat/ChatComposer.tsx
+17
-11
@@ -985,6 +985,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
985
null,
986
);
987
const [isDragOverComposer, setIsDragOverComposer] = useState(false);
988
+ const [isComposerFooterCompact, setIsComposerFooterCompact] = useState(false);
989
const [isComposerPrimaryActionsCompact, setIsComposerPrimaryActionsCompact] = useState(false);
990
const [isComposerModelPickerOpen, setIsComposerModelPickerOpen] = useState(false);
991
const isMobileViewport = useMediaQuery("max-sm");
@@ -1484,19 +1485,18 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
1485
useLayoutEffect(() => {
1486
const composerForm = composerFormRef.current;
1487
if (!composerForm) return;
1487
- const measurePrimaryActionsCompact = () => {
1488
+ const measureCompactLayouts = () => {
1489
const composerFormWidth = composerForm.clientWidth;
1490
const options = { hasWideActions: composerFooterHasWideActions };
1490
- return (
1491
+ setIsComposerFooterCompact(shouldUseCompactComposerFooter(composerFormWidth));
1492
+ setIsComposerPrimaryActionsCompact(
1493
shouldUseCompactComposerFooter(composerFormWidth, options) &&
1492
- shouldUseCompactComposerPrimaryActions(composerFormWidth, options)
1494
+ shouldUseCompactComposerPrimaryActions(composerFormWidth, options),
1495
);
1496
};
1497
1496
- setIsComposerPrimaryActionsCompact(measurePrimaryActionsCompact());
1497
- return observeResize(composerForm, () => {
1498
- setIsComposerPrimaryActionsCompact(measurePrimaryActionsCompact());
1499
- });
1498
+ measureCompactLayouts();
1499
+ return observeResize(composerForm, measureCompactLayouts);
1500
}, [composerFooterHasWideActions]);
1501
1502
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- reads draft images as data URLs and persists them to the draft store, dropping stale results on cleanup
@@ -1825,6 +1825,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
1825
},
1826
});
1827
const { blocksSubmission: voiceInputActive, submitAfterDictation } = speechInput;
1828
+ // A compact footer gives the dictation capsule the whole row beside the send button.
1829
+ const dictationTakesFooter = isComposerFooterCompact && speechInput.state.phase !== "idle";
1830
const submissionTarget = activePendingProgress ? "pending-user-input" : "provider-turn";
1831
const submissionBlocked = isComposerSubmissionBlocked({
1832
submissionTarget,
@@ -3581,7 +3583,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
3583
"hidden sm:flex",
3584
)}
3585
>
3584
- {composerAttachButton ? <div className="me-2">{composerAttachButton}</div> : null}
3586
+ {composerAttachButton && !dictationTakesFooter ? (
3587
+ <div className="me-2">{composerAttachButton}</div>
3588
+ ) : null}
3589
<div
3590
data-chat-composer-actions="right"
3591
data-chat-composer-transition-actions="true"
@@ -3594,7 +3598,10 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
3598
ref={attachExpandedComposerControls}
3599
data-chat-composer-controls="footer"
3600
data-chat-composer-footer-controls="true"
3597
- className="relative flex min-w-0 flex-1 items-center justify-end gap-0.5"
3601
+ className={cn(
3602
+ "relative flex min-w-0 flex-1 items-center justify-end gap-0.5",
3603
+ dictationTakesFooter && "hidden",
3604
+ )}
3605
>
3606
{composerControls}
3607
</div>
@@ -3638,6 +3645,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
3645
onPreviousPendingQuestion={onPreviousActivePendingUserInputQuestion}
3646
onInterrupt={handleInterruptPrimaryActionStable}
3647
compactBeforeSendTokens={props.resumeCompactionTokens}
3648
+ hideCompactToggle={dictationTakesFooter}
3649
keepFullHistory={props.keepFullHistory}
3650
onToggleKeepFullHistory={props.onToggleKeepFullHistory}
3651
>
@@ -3657,11 +3665,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
3665
/>
3666
<ComposerSpeechButton
3667
state={speechInput.state}
3660
- progress={null}
3668
shortcutLabel={dictationShortcutLabel}
3669
disabled={dictationDisabled}
3670
onStart={() => void speechInput.start()}
3664
- onCancel={() => speechInput.cancel()}
3671
/>
3672
</>
3673
) : null}
apps/web/src/components/chat/ComposerFooterControls.tsx
+2
@@ -216,6 +216,7 @@ export const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryA
216
onPreviousPendingQuestion: () => void;
217
onInterrupt: () => void;
218
compactBeforeSendTokens: number | null;
219
+ hideCompactToggle: boolean;
220
keepFullHistory: boolean;
221
onToggleKeepFullHistory: () => void;
222
}) {
@@ -245,6 +246,7 @@ export const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryA
246
onPreviousPendingQuestion={props.onPreviousPendingQuestion}
247
onInterrupt={props.onInterrupt}
248
compactBeforeSendTokens={props.compactBeforeSendTokens}
249
+ hideCompactToggle={props.hideCompactToggle}
250
keepFullHistory={props.keepFullHistory}
251
onToggleKeepFullHistory={props.onToggleKeepFullHistory}
252
>
apps/web/src/components/chat/ComposerPrimaryActions.tsx
+3
-1
@@ -62,6 +62,7 @@ interface ComposerPrimaryActionsProps {
62
onPreviousPendingQuestion: () => void;
63
onInterrupt: () => void;
64
compactBeforeSendTokens?: number | null;
65
+ hideCompactToggle?: boolean;
66
keepFullHistory?: boolean;
67
onToggleKeepFullHistory?: () => void;
68
}
@@ -118,6 +119,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
119
onPreviousPendingQuestion,
120
onInterrupt,
121
compactBeforeSendTokens = null,
122
+ hideCompactToggle = false,
123
keepFullHistory = false,
124
onToggleKeepFullHistory,
125
}: ComposerPrimaryActionsProps) {
@@ -356,7 +358,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
358
<TooltipPopup>{submitTooltip}</TooltipPopup>
359
</Tooltip>
360
);
359
- if (compactTokens === null) {
361
+ if (compactTokens === null || hideCompactToggle) {
362
return withStopButton(
363
<>
364
{children}
apps/web/src/components/chat/ComposerSpeechButton.tsx
+111
-191
@@ -1,6 +1,6 @@
1
import type { VoiceInputState } from "@t3tools/client-runtime/voice-input";
2
import { CheckIcon, MicIcon, XIcon } from "lucide-react";
3
-import { useEffect, useState } from "react";
3
+import { useEffect, useState, type PointerEvent, type ReactElement } from "react";
4
5
import { VoiceInputErrorPill } from "./VoiceInputErrorPill";
6
import { VoiceInputPill, VoiceWaveform } from "./VoiceInputPill";
@@ -9,69 +9,33 @@ import { Button } from "../ui/button";
9
import { Spinner } from "../ui/spinner";
10
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
11
12
-type SpeechPresentation = {
13
- status: string | null;
14
- showsCancel: boolean;
15
- showsConfirm: boolean;
16
- confirmEnabled: boolean;
17
- showsSend: boolean;
18
-};
12
+type DownloadProgress = { downloaded: number; total: number } | null;
13
14
+const keepFocus = (event: PointerEvent) => event.preventDefault();
15
+
16
+/** One short status line per phase; also mirrored into the preview annotation editor. */
17
export function resolveSpeechPresentation(
18
state: VoiceInputState,
22
- progress: { downloaded: number; total: number } | null,
23
-): SpeechPresentation {
19
+ progress: DownloadProgress,
20
+): { status: string | null; active: boolean } {
21
switch (state.phase) {
22
case "idle":
26
- return {
27
- status: null,
28
- showsCancel: false,
29
- showsConfirm: false,
30
- confirmEnabled: false,
31
- showsSend: true,
32
- };
23
+ return { status: null, active: false };
24
case "error":
34
- return {
35
- status: state.error ?? "Voice input failed",
36
- showsCancel: false,
37
- showsConfirm: false,
38
- confirmEnabled: false,
39
- showsSend: true,
40
- };
25
+ return { status: state.error ?? "Voice input failed", active: false };
26
case "preparing":
27
return {
28
status: progress
44
- ? `Downloading speech model ${Math.round((progress.downloaded / Math.max(1, progress.total)) * 100)}%`
45
- : "Preparing",
46
- showsCancel: true,
47
- showsConfirm: true,
48
- confirmEnabled: false,
49
- showsSend: true,
29
+ ? `Downloading model ${Math.round((progress.downloaded / Math.max(1, progress.total)) * 100)}%`
30
+ : "Starting…",
31
+ active: true,
32
};
33
case "recording":
52
- return {
53
- status: "Recording",
54
- showsCancel: true,
55
- showsConfirm: true,
56
- confirmEnabled: true,
57
- showsSend: true,
58
- };
34
+ return { status: "Recording", active: true };
35
case "transcribing":
60
- return {
61
- status: "Transcribing",
62
- showsCancel: true,
63
- showsConfirm: true,
64
- confirmEnabled: false,
65
- showsSend: true,
66
- };
36
+ return { status: "Transcribing…", active: true };
37
case "post-processing":
68
- return {
69
- status: "Post-processing",
70
- showsCancel: true,
71
- showsConfirm: true,
72
- confirmEnabled: false,
73
- showsSend: true,
74
- };
38
+ return { status: "Cleaning up…", active: true };
39
}
40
}
41
@@ -94,81 +58,31 @@ function RecordingStatus(props: { level: number; recordingLimitSeconds?: number
58
59
return (
60
<>
97
- <VoiceWaveform level={props.level} />
98
- <span aria-hidden className="size-1.5 shrink-0 rounded-full bg-primary" />
99
- <span className="shrink-0 text-secondary-label text-xs tabular-nums">
61
+ <span aria-hidden className="size-2 shrink-0 rounded-full bg-destructive" />
62
+ <span className="shrink-0 text-xs text-muted-foreground tabular-nums">
63
{formatElapsed(elapsedSeconds)}
64
{props.recordingLimitSeconds !== undefined
65
? ` / ${formatElapsed(props.recordingLimitSeconds)}`
66
: ""}
67
</span>
68
+ <div className="me-1.5 flex w-16 min-w-0 shrink grow">
69
+ <VoiceWaveform level={props.level} />
70
+ </div>
71
</>
72
);
73
}
74
109
-function ComposerSpeechStatus(props: {
110
- state: VoiceInputState;
111
- progress: { downloaded: number; total: number } | null;
112
- level: number;
113
- recordingLimitSeconds?: number | undefined;
114
-}) {
115
- const presentation = resolveSpeechPresentation(props.state, props.progress);
116
-
117
- if (!presentation.status) return null;
118
- const isRecording = props.state.phase === "recording";
119
- const isError = props.state.phase === "error";
120
-
121
- return (
122
- <div
123
- className="flex h-7 min-w-0 flex-1 items-center gap-2"
124
- role="status"
125
- aria-live={isRecording ? "off" : "polite"}
126
- aria-label={presentation.status}
127
- >
128
- {isRecording ? (
129
- <RecordingStatus level={props.level} recordingLimitSeconds={props.recordingLimitSeconds} />
130
- ) : (
131
- <span
132
- className={cn(
133
- "min-w-0 flex-1 truncate text-right text-sm text-secondary-label",
134
- isError && "text-destructive",
135
- )}
136
- >
137
- {presentation.status}
138
- </span>
139
- )}
140
- </div>
141
- );
142
-}
143
-
144
-function ComposerSpeechCancelButton(props: {
145
- state: VoiceInputState;
146
- shortcutLabel?: string | null;
147
- onCancel(): void;
75
+function ShortcutTooltip(props: {
76
+ label: string;
77
+ shortcut?: string | null | undefined;
78
+ children: ReactElement;
79
}) {
149
- if (props.state.phase === "idle") return null;
150
- const label = props.state.phase === "error" ? "Dismiss voice input error" : "Cancel voice input";
151
-
80
return (
81
<Tooltip>
154
- <TooltipTrigger
155
- render={
156
- <Button
157
- type="button"
158
- size="icon-sm-pill"
159
- variant="ghost"
160
- aria-label={label}
161
- onPointerDown={(event) => event.preventDefault()}
162
- onClick={props.onCancel}
163
- className="shrink-0"
164
- >
165
- <XIcon />
166
- </Button>
167
- }
168
- />
82
+ <TooltipTrigger render={props.children} />
83
<TooltipPopup side="top">
170
- {label}
171
- {props.shortcutLabel ? ` (${props.shortcutLabel})` : ""}
84
+ {props.label}
85
+ {props.shortcut ? ` (${props.shortcut})` : ""}
86
</TooltipPopup>
87
</Tooltip>
88
);
@@ -176,63 +90,56 @@ function ComposerSpeechCancelButton(props: {
90
91
export function ComposerSpeechButton(props: {
92
state: VoiceInputState;
179
- progress: { downloaded: number; total: number } | null;
93
shortcutLabel?: string | null;
94
disabled?: boolean;
95
+ /** Compact matches the `xs` buttons beside text-field editors. */
96
+ size?: "default" | "compact";
97
onStart(): void;
183
- onCancel(): void;
98
}) {
185
- const presentation = resolveSpeechPresentation(props.state, props.progress);
99
+ if (props.state.phase !== "idle") return null;
100
const label = "Start voice input";
101
188
- if (presentation.showsConfirm || props.state.phase === "error") return null;
189
-
102
return (
191
- <Tooltip>
192
- <TooltipTrigger
193
- render={
194
- <Button
195
- type="button"
196
- size="icon-sm"
197
- variant="ghost"
198
- aria-label={label}
199
- disabled={props.disabled}
200
- onPointerDown={(event) => event.preventDefault()}
201
- onClick={() => {
202
- if (props.disabled) return;
203
- props.onStart();
204
- }}
205
- className="relative shrink-0"
206
- >
207
- <MicIcon />
208
- </Button>
209
- }
210
- />
211
- <TooltipPopup side="top">
212
- {label}
213
- {props.shortcutLabel ? ` (${props.shortcutLabel})` : ""}
214
- </TooltipPopup>
215
- </Tooltip>
103
+ <ShortcutTooltip label={label} shortcut={props.shortcutLabel}>
104
+ <Button
105
+ type="button"
106
+ size={props.size === "compact" ? "icon-xs" : "icon-sm"}
107
+ variant="ghost"
108
+ aria-label={label}
109
+ disabled={props.disabled}
110
+ onPointerDown={keepFocus}
111
+ onClick={() => {
112
+ if (!props.disabled) props.onStart();
113
+ }}
114
+ className="shrink-0"
115
+ >
116
+ <MicIcon />
117
+ </Button>
118
+ </ShortcutTooltip>
119
);
120
}
121
122
export function ComposerSpeechRecordingPill(props: {
123
state: VoiceInputState;
221
- progress: { downloaded: number; total: number } | null;
124
+ progress: DownloadProgress;
125
finishShortcutLabel?: string | null;
126
cancelShortcutLabel?: string | null;
127
level: number;
128
recordingLimitSeconds?: number | undefined;
129
+ /** Compact matches the `xs` buttons beside text-field editors. */
130
+ size?: "default" | "compact";
131
onStart(): void;
132
disabled?: boolean;
133
onStop(): void;
134
onCancel(): void;
135
onSkipPostProcessing(): void;
136
}) {
232
- const presentation = resolveSpeechPresentation(props.state, props.progress);
233
- if (props.state.phase === "error") {
137
+ const { phase } = props.state;
138
+ const compact = props.size === "compact";
139
+ if (phase === "error") {
140
return (
141
<VoiceInputErrorPill
142
+ size={props.size}
143
error={props.state.error}
144
errorAction={props.state.errorAction}
145
disabled={props.disabled ?? false}
@@ -242,61 +149,74 @@ export function ComposerSpeechRecordingPill(props: {
149
/>
150
);
151
}
245
- if (!presentation.showsConfirm) return null;
246
-
247
- const label = presentation.confirmEnabled
248
- ? "Finish voice input"
249
- : (presentation.status ?? "Voice input is busy");
152
+ const presentation = resolveSpeechPresentation(props.state, props.progress);
153
+ if (!presentation.active) return null;
154
+ const recording = phase === "recording";
155
+ const trailing = recording || phase === "post-processing";
156
157
return (
252
- <VoiceInputPill>
253
- <ComposerSpeechCancelButton
254
- state={props.state}
255
- shortcutLabel={props.cancelShortcutLabel ?? null}
256
- onCancel={props.onCancel}
257
- />
258
- <ComposerSpeechStatus
259
- state={props.state}
260
- progress={props.progress}
261
- level={props.level}
262
- recordingLimitSeconds={props.recordingLimitSeconds}
263
- />
264
- {props.state.phase === "post-processing" ? (
158
+ <VoiceInputPill size={props.size}>
159
+ <ShortcutTooltip label="Cancel voice input" shortcut={props.cancelShortcutLabel}>
160
<Button
161
type="button"
267
- size="sm-pill"
162
+ size={compact ? "icon-xs" : "icon-sm-pill"}
163
variant="ghost"
269
- onPointerDown={(event) => event.preventDefault()}
164
+ aria-label="Cancel voice input"
165
+ onPointerDown={keepFocus}
166
+ onClick={props.onCancel}
167
+ className="shrink-0"
168
+ >
169
+ <XIcon />
170
+ </Button>
171
+ </ShortcutTooltip>
172
+ <div
173
+ className={cn(
174
+ "flex min-w-0 flex-1 items-center gap-2 overflow-hidden",
175
+ !trailing && "pe-2.5",
176
+ )}
177
+ role="status"
178
+ aria-live={recording ? "off" : "polite"}
179
+ aria-label={presentation.status ?? undefined}
180
+ >
181
+ {recording ? (
182
+ <RecordingStatus
183
+ level={props.level}
184
+ recordingLimitSeconds={props.recordingLimitSeconds}
185
+ />
186
+ ) : (
187
+ <>
188
+ <Spinner aria-hidden size="sm" tone="muted" className="shrink-0" />
189
+ <span className="min-w-0 truncate text-sm text-muted-foreground">
190
+ {presentation.status}
191
+ </span>
192
+ </>
193
+ )}
194
+ </div>
195
+ {phase === "post-processing" ? (
196
+ <Button
197
+ type="button"
198
+ size={compact ? "xs" : "sm-pill"}
199
+ variant="ghost"
200
+ onPointerDown={keepFocus}
201
onClick={props.onSkipPostProcessing}
202
className="shrink-0"
203
>
204
Skip
205
</Button>
275
- ) : (
276
- <Tooltip>
277
- <TooltipTrigger
278
- render={
279
- <Button
280
- type="button"
281
- size="icon-sm-pill"
282
- aria-label={label}
283
- disabled={!presentation.confirmEnabled}
284
- onPointerDown={(event) => event.preventDefault()}
285
- onClick={props.onStop}
286
- className="shrink-0"
287
- >
288
- {presentation.confirmEnabled ? <CheckIcon /> : <Spinner aria-hidden />}
289
- </Button>
290
- }
291
- />
292
- <TooltipPopup side="top">
293
- {label}
294
- {presentation.confirmEnabled && props.finishShortcutLabel
295
- ? ` (${props.finishShortcutLabel})`
296
- : ""}
297
- </TooltipPopup>
298
- </Tooltip>
299
- )}
206
+ ) : recording ? (
207
+ <ShortcutTooltip label="Finish voice input" shortcut={props.finishShortcutLabel}>
208
+ <Button
209
+ type="button"
210
+ size={compact ? "icon-xs" : "icon-sm-pill"}
211
+ aria-label="Finish voice input"
212
+ onPointerDown={keepFocus}
213
+ onClick={props.onStop}
214
+ className="shrink-0"
215
+ >
216
+ <CheckIcon />
217
+ </Button>
218
+ </ShortcutTooltip>
219
+ ) : null}
220
</VoiceInputPill>
221
);
222
}
apps/web/src/components/chat/VoiceInputErrorPill.tsx
+55
-52
@@ -1,70 +1,74 @@
1
import { MICROPHONE_PERMISSION_ERROR } from "@t3tools/client-runtime/voice-input";
2
import { useNavigate } from "@tanstack/react-router";
3
-import { RotateCcwIcon, SettingsIcon, XIcon } from "lucide-react";
3
+import { CircleAlertIcon, XIcon } from "lucide-react";
4
5
import { Button } from "../ui/button";
6
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
7
import { VoiceInputPill } from "./VoiceInputPill";
8
9
const VOICE_ERROR_LABELS: Record<string, string> = {
10
- [MICROPHONE_PERMISSION_ERROR]: "Microphone access needed",
11
- "Microphone access is required for voice input.": "Microphone access needed",
10
+ [MICROPHONE_PERMISSION_ERROR]: "Mic blocked",
11
+ "Microphone access is required for voice input.": "Mic blocked",
12
"This draft is no longer available.": "Draft unavailable",
13
- "Another voice recording is already active.": "Another recording active",
13
+ "Another voice recording is already active.": "Already recording",
14
"Voice transcription is not available.": "Voice input unavailable",
15
- "Voice transcription is still finishing. Try again shortly.": "Transcription still busy",
15
+ "Voice transcription is still finishing. Try again shortly.": "Still transcribing",
16
"Voice transcription is not available for this language.": "Language unsupported",
17
- "Could not prepare voice transcription.": "Couldn’t prepare dictation",
18
- "Could not start voice recording.": "Couldn’t start recording",
17
+ "Could not prepare voice transcription.": "Couldn’t start",
18
+ "Could not start voice recording.": "Couldn’t start",
19
"Voice recording was interrupted.": "Recording interrupted",
20
- "Could not finish voice recording.": "Couldn’t finish recording",
20
+ "Could not finish voice recording.": "Couldn’t finish",
21
"Could not transcribe this recording.": "Transcription failed",
22
"Voice transcription on this environment failed.": "Transcription failed",
23
"The draft changed while voice input was running. The transcript was not added.": "Draft changed",
24
- "No speech was detected.": "No speech detected",
25
- "Microphone processing failed.": "Microphone processing failed",
26
- "The microphone disconnected.": "Microphone disconnected",
24
+ "No speech was detected.": "No speech heard",
25
+ "Microphone processing failed.": "Mic failed",
26
+ "The microphone disconnected.": "Mic disconnected",
27
};
28
29
-function voiceErrorLabel(error: string | null): string {
30
- return (error && VOICE_ERROR_LABELS[error]) || "Voice input failed";
31
-}
29
+const RETRYABLE_TRANSCRIPTIONS = new Set([
30
+ "Could not transcribe this recording.",
31
+ "Voice transcription on this environment failed.",
32
+]);
33
34
export function VoiceInputErrorPill(props: {
35
error: string | null;
36
errorAction: "retry" | "settings" | null;
37
disabled?: boolean;
38
cancelShortcutLabel?: string | null;
39
+ size?: "default" | "compact" | undefined;
40
onRetry(): void;
41
onDismiss(): void;
42
}) {
43
const navigate = useNavigate();
44
+ const message = props.error ?? "Voice input failed";
45
const openSettings = props.errorAction === "settings";
43
- const actionLabel = openSettings
44
- ? "Open voice settings"
45
- : props.error === "Could not transcribe this recording." ||
46
- props.error === "Voice transcription on this environment failed."
47
- ? "Retry transcription"
48
- : "Record again";
46
+ const compact = props.size === "compact";
47
+ const action = openSettings
48
+ ? { label: "Open voice settings", text: "Settings" }
49
+ : props.error && RETRYABLE_TRANSCRIPTIONS.has(props.error)
50
+ ? { label: "Retry transcription", text: "Retry" }
51
+ : { label: "Record again", text: "Record again" };
52
return (
50
- <VoiceInputPill>
53
+ <VoiceInputPill tone="error" size={props.size}>
54
<Tooltip>
55
<TooltipTrigger
56
render={
57
<Button
58
type="button"
56
- size="icon-sm-pill"
59
+ size={compact ? "icon-xs" : "icon-sm-pill"}
60
variant="ghost"
61
aria-label="Dismiss voice input error"
62
onPointerDown={(event) => event.preventDefault()}
63
onClick={props.onDismiss}
64
+ className="shrink-0"
65
>
66
<XIcon />
67
</Button>
68
}
69
/>
70
<TooltipPopup side="top">
67
- Dismiss voice input error
71
+ Dismiss
72
{props.cancelShortcutLabel ? ` (${props.cancelShortcutLabel})` : ""}
73
</TooltipPopup>
74
</Tooltip>
@@ -74,42 +78,41 @@ export function VoiceInputErrorPill(props: {
78
<span
79
tabIndex={0}
80
role="status"
77
- aria-label={props.error ?? "Voice input failed"}
78
- className="min-w-0 flex-1 truncate text-sm text-destructive"
81
+ aria-label={message}
82
+ className="flex min-w-0 items-center gap-1.5 rounded-sm text-sm font-medium outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset"
83
/>
84
}
85
>
82
- {voiceErrorLabel(props.error)}
86
+ <CircleAlertIcon aria-hidden className="size-3.5 shrink-0" />
87
+ <span className="truncate">
88
+ {(props.error && VOICE_ERROR_LABELS[props.error]) || "Voice input failed"}
89
+ </span>
90
</TooltipTrigger>
84
- <TooltipPopup side="top">{props.error ?? "Voice input failed"}</TooltipPopup>
91
+ <TooltipPopup side="top">{message}</TooltipPopup>
92
</Tooltip>
93
{props.errorAction ? (
87
- <Tooltip>
88
- <TooltipTrigger
89
- render={
90
- <Button
91
- type="button"
92
- size="icon-sm-pill"
93
- variant="ghost"
94
- aria-label={actionLabel}
95
- disabled={props.disabled}
96
- onPointerDown={(event) => event.preventDefault()}
97
- onClick={() => {
98
- if (openSettings) {
99
- props.onDismiss();
100
- void navigate({ to: "/settings/voice" });
101
- } else {
102
- props.onRetry();
103
- }
104
- }}
105
- >
106
- {openSettings ? <SettingsIcon /> : <RotateCcwIcon />}
107
- </Button>
94
+ <Button
95
+ type="button"
96
+ size={compact ? "xs" : "sm-pill"}
97
+ variant="outline"
98
+ aria-label={action.label}
99
+ disabled={props.disabled}
100
+ onPointerDown={(event) => event.preventDefault()}
101
+ onClick={() => {
102
+ if (openSettings) {
103
+ props.onDismiss();
104
+ void navigate({ to: "/settings/voice" });
105
+ } else {
106
+ props.onRetry();
107
}
109
- />
110
- <TooltipPopup side="top">{actionLabel}</TooltipPopup>
111
- </Tooltip>
112
- ) : null}
108
+ }}
109
+ className="ms-auto shrink-0"
110
+ >
111
+ {action.text}
112
+ </Button>
113
+ ) : (
114
+ <span aria-hidden className="w-1.5 shrink-0" />
115
+ )}
116
</VoiceInputPill>
117
);
118
}
apps/web/src/components/chat/VoiceInputPill.tsx
+31
-9
@@ -1,8 +1,10 @@
1
import { memo, useEffect, useRef, type ReactNode } from "react";
2
import { useMediaQuery } from "~/hooks/useMediaQuery";
3
+import { cn } from "~/lib/utils";
4
4
-const WAVEFORM_BAR_COUNT = 28;
5
+const WAVEFORM_BAR_COUNT = 24;
6
const WAVEFORM_BAR_IDS = Array.from({ length: WAVEFORM_BAR_COUNT }, (_, index) => String(index));
7
+const WAVEFORM_REST_SCALE = 0.2;
8
9
export const VoiceWaveform = memo(function VoiceWaveform(props: { level: number }) {
10
const prefersReducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
@@ -17,15 +19,15 @@ export const VoiceWaveform = memo(function VoiceWaveform(props: { level: number
19
barsRef.current.forEach((bar, index) => {
20
if (!bar) return;
21
const level = levels[index] ?? 0;
20
- bar.style.opacity = String(0.22 + level * 0.78);
21
- bar.style.transform = `scaleY(${prefersReducedMotion ? 0.35 : Math.max(0.08, level)})`;
22
+ bar.style.opacity = String(0.3 + level * 0.55);
23
+ bar.style.transform = `scaleY(${prefersReducedMotion ? 0.4 : Math.max(WAVEFORM_REST_SCALE, level)})`;
24
});
25
}, [prefersReducedMotion, props.level]);
26
27
return (
28
<div
29
aria-hidden
28
- className="flex h-5 min-w-0 flex-1 items-center justify-between gap-px overflow-hidden"
30
+ className="flex h-4 min-w-0 flex-1 items-center justify-end gap-0.5 overflow-hidden"
31
>
32
{WAVEFORM_BAR_IDS.map((id, index) => (
33
<span
@@ -33,20 +35,40 @@ export const VoiceWaveform = memo(function VoiceWaveform(props: { level: number
35
ref={(bar) => {
36
barsRef.current[index] = bar;
37
}}
36
- className="h-full w-0.5 shrink-0 origin-center rounded-full bg-primary opacity-25 transition-[transform,opacity] duration-100 ease-out motion-reduce:transition-none"
37
- style={{ transform: `scaleY(${prefersReducedMotion ? 0.35 : 0.08})` }}
38
+ className="h-full w-0.5 shrink-0 origin-center rounded-full bg-foreground opacity-35 transition-[transform,opacity] duration-100 ease-out motion-reduce:transition-none"
39
+ style={{ transform: `scaleY(${prefersReducedMotion ? 0.4 : WAVEFORM_REST_SCALE})` }}
40
/>
41
))}
42
</div>
43
);
44
});
45
44
-export function VoiceInputPill({ children }: { children: ReactNode }) {
46
+/**
47
+ * The capsule every dictation state renders in. Default matches the composer's send button
48
+ * and insets its pill buttons; compact matches the `xs` buttons in text-field action rows.
49
+ */
50
+export function VoiceInputPill({
51
+ children,
52
+ tone = "default",
53
+ size = "default",
54
+}: {
55
+ children: ReactNode;
56
+ tone?: "default" | "error";
57
+ size?: "default" | "compact" | undefined;
58
+}) {
59
return (
46
- // Same height as the toolbar's icon buttons, so starting a recording never resizes the composer.
60
<div
61
data-slot="voice-input-pill"
49
- className="flex h-8 w-48 min-w-0 shrink-0 items-center gap-2 sm:h-7 sm:w-64"
62
+ className={cn(
63
+ "flex min-w-0 items-center gap-1.5 ring-1 ring-inset",
64
+ size === "compact"
65
+ ? // Phones give the capsule its own row so the field's buttons stay together below it.
66
+ "h-7 rounded-md max-sm:order-first max-sm:basis-full sm:h-6"
67
+ : "h-9 max-w-fit grow-[1.5] basis-0 rounded-full p-0.5 sm:h-8",
68
+ tone === "error"
69
+ ? "bg-destructive/6 text-destructive ring-destructive/24"
70
+ : "bg-muted/48 ring-border",
71
+ )}
72
>
73
{children}
74
</div>
apps/web/src/components/chat/VoiceInputSetup.tsx
+151
-132
@@ -1,15 +1,25 @@
1
import { useStableCallback } from "~/hooks/useStableCallback";
2
-import { listBrowserMicrophones, type BrowserMicrophone } from "../../speech/browserMicrophones";
2
+import {
3
+ listBrowserMicrophones,
4
+ updateMicrophoneOrder,
5
+ type BrowserMicrophone,
6
+} from "../../speech/browserMicrophones";
7
import type {
8
EnvironmentId,
9
EnvironmentSpeechModel,
10
EnvironmentSpeechStatus,
11
} from "@t3tools/contracts";
12
import { useNavigate } from "@tanstack/react-router";
9
-import { RefreshCwIcon } from "lucide-react";
13
+import { CircleAlertIcon, MicIcon, RefreshCwIcon } from "lucide-react";
14
import { useEffect, useState } from "react";
15
12
-import { useClientSettings, updateClientSettings } from "../../hooks/useSettings";
16
+import { useClientSettings } from "../../hooks/useSettings";
17
+import {
18
+ isSystemDefaultDeviceId,
19
+ microphoneOrder,
20
+ preferMicrophone,
21
+ preferredMicrophoneId,
22
+} from "../../speech/microphoneOrder";
23
import { useEnvironment } from "../../state/environments";
24
import { AuthSettingsWriteScope } from "@t3tools/contracts";
25
import { useEnvironmentScope } from "../../state/session";
@@ -17,7 +27,7 @@ import { languageLabel } from "../settings/SpeechLanguageSelect";
27
import { Button } from "../ui/button";
28
import { Dialog } from "../ui/dialog";
29
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
20
-import { WizardFooter, WizardHeader, WizardPanel, WizardPopup, WizardSteps } from "../ui/wizard";
30
+import { WizardFooter, WizardHeader, WizardPanel, WizardPopup } from "../ui/wizard";
31
32
export function VoiceInputSetup(props: {
33
environmentId: EnvironmentId | null;
@@ -38,8 +48,9 @@ export function VoiceInputSetup(props: {
48
const navigate = useNavigate();
49
const environment = useEnvironment(props.environmentId);
50
const canManage = useEnvironmentScope(props.environmentId, AuthSettingsWriteScope);
41
- const selectedMicrophone = useClientSettings((settings) => settings.voiceMicrophone);
51
+ const order = useClientSettings(microphoneOrder);
52
const [microphones, setMicrophones] = useState<BrowserMicrophone[]>([]);
53
+ const selectedMicrophone = preferredMicrophoneId(order, microphones);
54
const [loadingMicrophones, setLoadingMicrophones] = useState(false);
55
const [microphoneError, setMicrophoneError] = useState<string | null>(null);
56
const refreshMicrophones = useStableCallback(async () => {
@@ -49,7 +60,7 @@ export function VoiceInputSetup(props: {
60
setMicrophones(await listBrowserMicrophones());
61
setMicrophoneError(null);
62
} catch {
52
- setMicrophoneError("Could not list microphones. You can still use the system default.");
63
+ setMicrophoneError("Couldn’t list microphones. The system default still works.");
64
}
65
setLoadingMicrophones(false);
66
});
@@ -77,39 +88,38 @@ export function VoiceInputSetup(props: {
88
void navigate({ to: "/settings/voice", hash });
89
};
90
91
+ const destination = environment?.label ?? "your transcription environment";
92
+
93
return (
94
<Dialog open={props.open} onOpenChange={props.onOpenChange}>
95
<WizardPopup>
96
<WizardHeader
84
- title="Set up voice input"
85
- description={`Transcribe speech on ${environment?.label ?? "your transcription environment"} and use voice input across environments.`}
86
- >
87
- <WizardSteps steps={["Model", "Ready to dictate"]} currentStep={props.step} />
88
- </WizardHeader>
97
+ title={props.step === 0 ? "Set up voice input" : "Voice input is ready"}
98
+ description={
99
+ props.step === 0
100
+ ? `Download a speech model once. Your audio is transcribed on ${destination}.`
101
+ : "Pick a microphone, then start talking."
102
+ }
103
+ />
104
<WizardPanel>
105
{props.step === 0 ? (
106
<section className="space-y-3 text-sm">
107
{model ? (
93
- <div className="rounded-lg border border-border/70 bg-card/60 p-4">
94
- <div className="flex items-center justify-between gap-2">
95
- <h3 className="font-medium">{model.name}</h3>
96
- {model?.recommended && props.language ? (
97
- <span className="text-xs font-medium text-primary">
98
- Recommended for {languageLabel(props.language)}
99
- </span>
100
- ) : null}
108
+ <div className="space-y-3 rounded-lg border border-border/70 bg-card/60 p-3">
109
+ <div className="flex items-baseline justify-between gap-3">
110
+ <h3 className="min-w-0 truncate font-medium">{model.name}</h3>
111
+ <span className="shrink-0 text-xs text-muted-foreground tabular-nums">
112
+ {Math.round(model.size / 1024 / 1024)} MB
113
+ </span>
114
</div>
102
- <p className="mt-2 text-muted-foreground">
103
- Download the {Math.round(model.size / 1024 / 1024)} MB model to{" "}
104
- {environment?.label ?? "your transcription environment"}. Microphone audio is
105
- sent there for transcription, as chosen in Voice settings.
106
- </p>
107
- <p className="mt-2 text-muted-foreground">
108
- Silero (1.2 MB), used for silence filtering and pause detection, downloads
109
- alongside the speech model. An installed copy is reused.
115
+ <p className="text-xs text-muted-foreground">
116
+ {model.recommended && props.language
117
+ ? `Recommended for ${languageLabel(props.language)}. `
118
+ : ""}
119
+ Includes a 1.2 MB silence detector.
120
</p>
121
{props.downloading ? (
112
- <div role="status" className="mt-4 space-y-1 text-muted-foreground">
122
+ <div role="status" className="space-y-1.5">
123
<div
124
role="progressbar"
125
aria-label="Speech model download progress"
@@ -123,9 +133,9 @@ export function VoiceInputSetup(props: {
133
style={{ width: `${progress ?? 0}%` }}
134
/>
135
</div>
126
- <p className="text-xs">
127
- {model?.state === "verifying"
128
- ? "Verifying download…"
136
+ <p className="text-xs text-muted-foreground tabular-nums">
137
+ {model.state === "verifying"
138
+ ? "Verifying…"
139
: progress === null
140
? "Starting download…"
141
: `${progress}% downloaded`}
@@ -139,119 +149,128 @@ export function VoiceInputSetup(props: {
149
</p>
150
) : null}
151
{props.error ? (
142
- <p role="alert" className="text-destructive">
152
+ <p role="alert" className="flex items-start gap-1.5 text-destructive">
153
+ <CircleAlertIcon aria-hidden className="mt-0.5 size-3.5 shrink-0" />
154
{props.error}
155
</p>
156
) : null}
157
</section>
158
) : (
148
- <section className="space-y-4 text-sm">
149
- <div className="space-y-2">
150
- <label className="font-medium" htmlFor="voice-setup-microphone">
151
- Microphone
152
- </label>
153
- <div className="flex items-center gap-2">
154
- <Select
155
- value={selectedMicrophone ? `device:${selectedMicrophone}` : "system-default"}
156
- disabled={loadingMicrophones}
157
- onValueChange={(value) => {
158
- if (value)
159
- void updateClientSettings({
160
- voiceMicrophone:
161
- value === "system-default" ? "" : value.slice("device:".length),
162
- });
163
- }}
164
- >
165
- <SelectTrigger
166
- id="voice-setup-microphone"
167
- size="sm"
168
- aria-label="Microphone"
169
- className="min-w-0 flex-1"
170
- >
171
- <SelectValue>{selectedMicrophoneLabel}</SelectValue>
172
- </SelectTrigger>
173
- <SelectPopup align="end" alignItemWithTrigger={false}>
174
- <SelectItem value="system-default">System default</SelectItem>
175
- {selectedIsUnavailable ? (
176
- <SelectItem value={`device:${selectedMicrophone}`}>
177
- Selected microphone (Unavailable)
178
- </SelectItem>
179
- ) : null}
180
- {microphones.map((device) => (
181
- <SelectItem key={device.deviceId} value={`device:${device.deviceId}`}>
182
- {device.label}
183
- </SelectItem>
184
- ))}
185
- </SelectPopup>
186
- </Select>
187
- <Button
188
- type="button"
189
- variant="ghost"
190
- size="icon-sm"
191
- disabled={loadingMicrophones}
192
- aria-label="Refresh microphones"
193
- onClick={() => void refreshMicrophones()}
159
+ <section className="space-y-2 text-sm">
160
+ <label className="sr-only" htmlFor="voice-setup-microphone">
161
+ Microphone
162
+ </label>
163
+ <div className="flex items-center gap-2">
164
+ <Select
165
+ value={selectedMicrophone ? `device:${selectedMicrophone}` : "system-default"}
166
+ disabled={loadingMicrophones}
167
+ onValueChange={(value) => {
168
+ if (!value) return;
169
+ const deviceId = value.slice("device:".length);
170
+ const label =
171
+ microphones.find((device) => device.deviceId === deviceId)?.label ?? "";
172
+ updateMicrophoneOrder((order) =>
173
+ preferMicrophone(
174
+ order,
175
+ value === "system-default" || isSystemDefaultDeviceId(deviceId)
176
+ ? { kind: "default" }
177
+ : { kind: "device", deviceId, label },
178
+ ),
179
+ );
180
+ }}
181
+ >
182
+ <SelectTrigger
183
+ id="voice-setup-microphone"
184
+ size="sm"
185
+ aria-label="Microphone"
186
+ className="min-w-0 flex-1"
187
>
195
- <RefreshCwIcon className="size-3.5" />
196
- </Button>
197
- </div>
198
- {selectedIsUnavailable ? (
199
- <p className="text-xs text-destructive">
200
- The selected microphone is unavailable. Choose another or use the system
201
- default.
202
- </p>
203
- ) : null}
204
- {microphoneError ? (
205
- <p role="alert" className="text-xs text-muted-foreground">
206
- {microphoneError}
207
- </p>
208
- ) : null}
188
+ <MicIcon aria-hidden className="size-3.5 shrink-0 text-muted-foreground" />
189
+ <SelectValue>{selectedMicrophoneLabel}</SelectValue>
190
+ </SelectTrigger>
191
+ <SelectPopup align="end" alignItemWithTrigger={false}>
192
+ <SelectItem value="system-default">System default</SelectItem>
193
+ {selectedIsUnavailable ? (
194
+ <SelectItem value={`device:${selectedMicrophone}`}>
195
+ Selected microphone (Unavailable)
196
+ </SelectItem>
197
+ ) : null}
198
+ {microphones.map((device) => (
199
+ <SelectItem key={device.deviceId} value={`device:${device.deviceId}`}>
200
+ {device.label}
201
+ </SelectItem>
202
+ ))}
203
+ </SelectPopup>
204
+ </Select>
205
+ <Button
206
+ type="button"
207
+ variant="ghost"
208
+ size="icon-sm"
209
+ disabled={loadingMicrophones}
210
+ aria-label="Refresh microphones"
211
+ onClick={() => void refreshMicrophones()}
212
+ >
213
+ <RefreshCwIcon className="size-3.5" />
214
+ </Button>
215
</div>
210
- <p className="text-muted-foreground">
211
- Speak and transcribe in multiple languages or translate into English, and get names
212
- and technical terms right with the dictionary in Voice settings.
213
- </p>
216
+ {selectedIsUnavailable ? (
217
+ <p className="text-xs text-destructive">
218
+ That microphone is unplugged. Pick another one.
219
+ </p>
220
+ ) : null}
221
+ {microphoneError ? (
222
+ <p role="alert" className="text-xs text-muted-foreground">
223
+ {microphoneError}
224
+ </p>
225
+ ) : null}
226
</section>
227
)}
228
</WizardPanel>
217
- <WizardFooter>
218
- {props.step === 0 ? (
219
- <>
220
- <Button variant="outline" onClick={() => openSettings("speech-models")}>
221
- {model ? "Choose another model or language" : "Choose a model or language"}
229
+ {props.step === 0 ? (
230
+ <WizardFooter
231
+ leading={
232
+ <Button variant="ghost" onClick={() => openSettings("speech-models")}>
233
+ {model ? "Other models" : "Choose a model"}
234
</Button>
223
- {props.onRetryCatalog ? (
224
- <Button onClick={props.onRetryCatalog}>Retry loading models</Button>
225
- ) : null}
226
- {props.downloading ? (
227
- <Button variant="outline" disabled={!canManage} onClick={props.onCancelDownload}>
228
- Cancel download
229
- </Button>
230
- ) : null}
231
- {model ? (
232
- <Button
233
- disabled={!canManage || props.downloading || !status}
234
- onClick={props.onDownload}
235
- >
236
- {props.downloading
237
- ? "Downloading…"
238
- : props.error
239
- ? "Try again"
240
- : canManage
241
- ? "Download model"
242
- : "Ask an environment admin to download"}
243
- </Button>
244
- ) : null}
245
- </>
246
- ) : (
247
- <>
248
- <Button variant="outline" onClick={() => openSettings("")}>
249
- Customize in Voice settings
235
+ }
236
+ >
237
+ {props.onRetryCatalog ? (
238
+ <Button onClick={props.onRetryCatalog}>Retry loading models</Button>
239
+ ) : null}
240
+ {props.downloading ? (
241
+ <Button variant="outline" disabled={!canManage} onClick={props.onCancelDownload}>
242
+ Cancel download
243
</Button>
251
- <Button onClick={props.onStartRecording}>Start dictating</Button>
252
- </>
253
- )}
254
- </WizardFooter>
244
+ ) : null}
245
+ {model ? (
246
+ <Button
247
+ disabled={!canManage || props.downloading || !status}
248
+ onClick={props.onDownload}
249
+ >
250
+ {props.downloading
251
+ ? "Downloading…"
252
+ : props.error
253
+ ? "Try again"
254
+ : canManage
255
+ ? "Download model"
256
+ : "Needs an admin to download"}
257
+ </Button>
258
+ ) : null}
259
+ </WizardFooter>
260
+ ) : (
261
+ <WizardFooter
262
+ leading={
263
+ <Button variant="ghost" onClick={() => openSettings("")}>
264
+ Voice settings
265
+ </Button>
266
+ }
267
+ >
268
+ <Button onClick={props.onStartRecording}>
269
+ <MicIcon />
270
+ Start dictating
271
+ </Button>
272
+ </WizardFooter>
273
+ )}
274
</WizardPopup>
275
</Dialog>
276
);
apps/web/src/components/pullRequest/PullRequestCommentForm.tsx
+1
-3
@@ -137,9 +137,7 @@ export function PullRequestCommentForm({
137
}}
138
/>
139
<div className="flex flex-wrap items-center justify-end gap-2">
140
- <div className="mr-auto flex min-w-0 flex-wrap items-center gap-1">
141
- <TextFieldSpeechControls speech={speech} disabled={locked} />
142
- </div>
140
+ <TextFieldSpeechControls speech={speech} disabled={locked} />
141
{followUpAction === null ? null : (
142
<Button
143
size="xs"
apps/web/src/components/pullRequest/PullRequestReviewForm.tsx
+1
-3
@@ -177,9 +177,7 @@ export function PullRequestReviewForm({
177
}}
178
/>
179
<div className="mt-2 flex flex-wrap items-center justify-end gap-2">
180
- <div className="mr-auto flex min-w-0 flex-wrap items-center gap-1">
181
- <TextFieldSpeechControls speech={speech} disabled={pending} />
182
- </div>
180
+ <TextFieldSpeechControls speech={speech} disabled={pending} />
181
{offered.length > 1 ? (
182
<Select
183
value={selectedVerdict?.value ?? null}
apps/web/src/components/settings/MicrophoneOrderList.tsx
new
+172
@@ -0,0 +1,172 @@
1
+import {
2
+ DndContext,
3
+ type DragEndEvent,
4
+ PointerSensor,
5
+ closestCenter,
6
+ useSensor,
7
+ useSensors,
8
+} from "@dnd-kit/core";
9
+import { restrictToParentElement, restrictToVerticalAxis } from "@dnd-kit/modifiers";
10
+import { SortableContext, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
11
+import { CSS } from "@dnd-kit/utilities";
12
+import { ArrowDownIcon, ArrowUpIcon, GripVerticalIcon, XIcon } from "lucide-react";
13
+
14
+import { cn } from "~/lib/utils";
15
+import { type BrowserMicrophone, updateMicrophoneOrder } from "../../speech/browserMicrophones";
16
+import {
17
+ type MicrophoneEntry,
18
+ forgetMicrophone,
19
+ microphoneEntryKey,
20
+ moveMicrophone,
21
+ preferredMicrophone,
22
+} from "../../speech/microphoneOrder";
23
+import { Button } from "../ui/button";
24
+
25
+/** The saved microphone order. Keyboard users reorder with the step buttons. */
26
+export function MicrophoneOrderList(props: {
27
+ readonly order: ReadonlyArray<MicrophoneEntry>;
28
+ readonly devices: ReadonlyArray<BrowserMicrophone>;
29
+}) {
30
+ const { order, devices } = props;
31
+ const keys = order.map(microphoneEntryKey);
32
+ const inUse = microphoneEntryKey(preferredMicrophone(order, devices));
33
+ // Device ids stay hidden until microphone permission, so connection is unknown before it.
34
+ const devicesKnown = devices.some((device) => device.deviceId);
35
+ const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 4 } }));
36
+ const move = (key: string, steps: number) =>
37
+ updateMicrophoneOrder((current) => moveMicrophone(current, key, steps));
38
+ const handleDragEnd = (event: DragEndEvent) => {
39
+ if (event.over === null || event.active.id === event.over.id) return;
40
+ const from = keys.indexOf(String(event.active.id));
41
+ const to = keys.indexOf(String(event.over.id));
42
+ if (from !== -1 && to !== -1) move(String(event.active.id), to - from);
43
+ };
44
+
45
+ return (
46
+ <DndContext
47
+ sensors={sensors}
48
+ collisionDetection={closestCenter}
49
+ modifiers={[restrictToVerticalAxis, restrictToParentElement]}
50
+ onDragEnd={handleDragEnd}
51
+ >
52
+ <SortableContext items={keys} strategy={verticalListSortingStrategy}>
53
+ <ol
54
+ aria-label="Microphones, preferred first"
55
+ className="divide-y divide-border/60 rounded-lg border border-border/60"
56
+ >
57
+ {order.map((entry, index) => {
58
+ const key = microphoneEntryKey(entry);
59
+ const device =
60
+ entry.kind === "device"
61
+ ? devices.find((candidate) => candidate.deviceId === entry.deviceId)
62
+ : undefined;
63
+ return (
64
+ <MicrophoneRow
65
+ key={key}
66
+ id={key}
67
+ name={
68
+ entry.kind === "default"
69
+ ? "System default"
70
+ : entry.label || device?.label || "Saved microphone"
71
+ }
72
+ position={index + 1}
73
+ count={order.length}
74
+ inUse={key === inUse}
75
+ notConnected={entry.kind === "device" && devicesKnown && !device}
76
+ onMove={(steps) => move(key, steps)}
77
+ onForget={
78
+ entry.kind === "device"
79
+ ? () => updateMicrophoneOrder((current) => forgetMicrophone(current, key))
80
+ : undefined
81
+ }
82
+ />
83
+ );
84
+ })}
85
+ </ol>
86
+ </SortableContext>
87
+ </DndContext>
88
+ );
89
+}
90
+
91
+function MicrophoneRow(props: {
92
+ readonly id: string;
93
+ readonly name: string;
94
+ readonly position: number;
95
+ readonly count: number;
96
+ readonly inUse: boolean;
97
+ readonly notConnected: boolean;
98
+ readonly onMove: (steps: number) => void;
99
+ readonly onForget: (() => void) | undefined;
100
+}) {
101
+ const { name } = props;
102
+ const { listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } =
103
+ useSortable({ id: props.id });
104
+ return (
105
+ <li
106
+ ref={setNodeRef}
107
+ style={{ transform: CSS.Translate.toString(transform), transition }}
108
+ className={cn(
109
+ // Phones put the marker and controls on a second line so names stay readable.
110
+ "grid grid-cols-[1rem_minmax(0,1fr)_auto] items-center gap-x-2 py-1.5 ps-3 pe-1.5 @min-[32rem]/settings-row:grid-cols-[1rem_auto_minmax(0,1fr)_auto_auto]",
111
+ isDragging && "relative z-10 rounded-lg bg-background shadow-md",
112
+ )}
113
+ >
114
+ <span className="text-xs tabular-nums text-muted-foreground">{props.position}</span>
115
+ <span className="col-span-2 text-sm leading-5 break-words @min-[32rem]/settings-row:col-span-1">
116
+ {name}
117
+ </span>
118
+ <span className="col-start-2 flex @min-[32rem]/settings-row:col-start-auto">
119
+ {props.inUse ? (
120
+ <span className="rounded-sm bg-success/12 px-1 text-2xs text-success-foreground">
121
+ In use
122
+ </span>
123
+ ) : props.notConnected ? (
124
+ <span className="text-2xs text-muted-foreground">Not connected</span>
125
+ ) : null}
126
+ </span>
127
+ <span
128
+ ref={setActivatorNodeRef}
129
+ {...listeners}
130
+ aria-hidden
131
+ className="hidden size-6 shrink-0 cursor-grab touch-none items-center justify-center rounded text-muted-foreground/70 hover:text-foreground active:cursor-grabbing @min-[32rem]/settings-row:flex"
132
+ >
133
+ <GripVerticalIcon className="size-3.5" />
134
+ </span>
135
+ <span className="flex items-center gap-0.5">
136
+ <Button
137
+ type="button"
138
+ size="icon-xs"
139
+ variant="ghost-muted"
140
+ disabled={props.position === 1}
141
+ aria-label={`Move ${name} up`}
142
+ onClick={() => props.onMove(-1)}
143
+ >
144
+ <ArrowUpIcon />
145
+ </Button>
146
+ <Button
147
+ type="button"
148
+ size="icon-xs"
149
+ variant="ghost-muted"
150
+ disabled={props.position === props.count}
151
+ aria-label={`Move ${name} down`}
152
+ onClick={() => props.onMove(1)}
153
+ >
154
+ <ArrowDownIcon />
155
+ </Button>
156
+ {props.onForget ? (
157
+ <Button
158
+ type="button"
159
+ size="icon-xs"
160
+ variant="ghost-muted"
161
+ aria-label={`Forget ${name}`}
162
+ onClick={props.onForget}
163
+ >
164
+ <XIcon />
165
+ </Button>
166
+ ) : (
167
+ <span aria-hidden className="size-7 sm:size-6" />
168
+ )}
169
+ </span>
170
+ </li>
171
+ );
172
+}
apps/web/src/components/settings/MicrophoneTest.tsx
+113
-116
@@ -1,12 +1,15 @@
1
import { MICROPHONE_PERMISSION_ERROR } from "@t3tools/client-runtime/voice-input";
2
-import { CheckIcon, MicIcon, PauseIcon, PlayIcon, RotateCcwIcon, XIcon } from "lucide-react";
2
+import { MicIcon, PauseIcon, PlayIcon, RotateCcwIcon, SquareIcon, XIcon } from "lucide-react";
3
import { useEffect, useRef, useState } from "react";
4
5
import { useStableCallback } from "~/hooks/useStableCallback";
6
+import { openMicrophone } from "../../speech/browserPcmCapture";
7
import workletUrl from "../../speech/pcmWorklet.ts?worker&url";
7
-import { VoiceInputErrorPill } from "../chat/VoiceInputErrorPill";
8
-import { VoiceInputPill, VoiceWaveform } from "../chat/VoiceInputPill";
8
+import { VoiceWaveform } from "../chat/VoiceInputPill";
9
+import { cn } from "../../lib/utils";
10
import { Button } from "../ui/button";
11
+import { SettingsRow } from "./settingsLayout";
12
+import { searchableSetting } from "./settingsSearch";
13
14
const LOOPBACK_SECONDS = 10;
15
const formatTime = (seconds: number) =>
@@ -27,7 +30,14 @@ type Capture = {
30
* device: no environment, transcriber, or provider is involved, so a silent result points
31
* at the microphone rather than at transcription.
32
*/
30
-export function MicrophoneTest({ microphoneId }: { microphoneId: string }) {
33
+export function MicrophoneTest({
34
+ microphoneId,
35
+ onMicrophoneAccess,
36
+}: {
37
+ microphoneId: string;
38
+ /** Labels and device ids become readable once the browser grants access. */
39
+ onMicrophoneAccess: () => void;
40
+}) {
41
const [phase, setPhase] = useState<"idle" | "starting" | "recording" | "ready">("idle");
42
const [recording, setRecording] = useState<{ url: string; duration: number } | null>(null);
43
const [error, setError] = useState<string | null>(null);
@@ -82,14 +92,13 @@ export function MicrophoneTest({ microphoneId }: { microphoneId: string }) {
92
const current: Capture = {};
93
capture.current = current;
94
try {
85
- const stream = await navigator.mediaDevices.getUserMedia({
86
- audio: microphoneId ? { deviceId: { exact: microphoneId } } : true,
87
- });
95
+ const stream = await openMicrophone(microphoneId);
96
if (capture.current !== current) {
97
stream.getTracks().forEach((track) => track.stop());
98
return;
99
}
100
current.stream = stream;
101
+ onMicrophoneAccess();
102
const recorder = new MediaRecorder(stream);
103
current.recorder = recorder;
104
const chunks: Blob[] = [];
@@ -163,15 +172,15 @@ export function MicrophoneTest({ microphoneId }: { microphoneId: string }) {
172
if (capture.current !== current) return;
173
releaseCapture();
174
setPhase("idle");
175
+ const name = typeof cause === "object" && cause !== null && "name" in cause && cause.name;
176
setError(
167
- typeof cause === "object" &&
168
- cause !== null &&
169
- "name" in cause &&
170
- cause.name === "NotAllowedError"
177
+ name === "NotAllowedError"
178
? MICROPHONE_PERMISSION_ERROR
172
- : cause instanceof Error
173
- ? cause.message
174
- : "Could not access the microphone.",
179
+ : name === "NotFoundError"
180
+ ? "No microphone found."
181
+ : cause instanceof Error
182
+ ? cause.message
183
+ : "Could not access the microphone.",
184
);
185
}
186
};
@@ -181,70 +190,11 @@ export function MicrophoneTest({ microphoneId }: { microphoneId: string }) {
190
setError(null);
191
};
192
184
- if (error) {
185
- return (
186
- <VoiceInputErrorPill
187
- error={error}
188
- errorAction="retry"
189
- onRetry={() => void start()}
190
- onDismiss={cancel}
191
- />
192
- );
193
- }
194
- if (phase === "idle") {
195
- return (
196
- <Button size="sm" variant="outline" onClick={() => void start()}>
197
- <MicIcon />
198
- Test microphone
199
- </Button>
200
- );
201
- }
202
- if (phase === "ready" && recording) {
203
- return (
204
- <MicrophonePlayback
205
- key={recording.url}
206
- src={recording.url}
207
- duration={recording.duration}
208
- onRetry={() => void start()}
209
- onDone={cancel}
210
- />
211
- );
212
- }
213
- return (
214
- <VoiceInputPill>
193
+ const control =
194
+ phase === "recording" || phase === "starting" ? (
195
<Button
216
- size="icon-sm-pill"
217
- variant="ghost"
218
- aria-label="Cancel microphone test"
219
- onClick={cancel}
220
- >
221
- <XIcon />
222
- </Button>
223
- {phase === "recording" ? (
224
- <>
225
- <VoiceWaveform level={level} />
226
- <span aria-hidden className="size-1.5 shrink-0 rounded-full bg-primary" />
227
- <span
228
- className="shrink-0 text-xs tabular-nums text-muted-foreground"
229
- aria-label="Recording time"
230
- >
231
- {formatTime(elapsed)} / {formatTime(LOOPBACK_SECONDS)}
232
- </span>
233
- <meter
234
- aria-label="Microphone input level"
235
- min={0}
236
- max={1}
237
- value={level}
238
- className="sr-only"
239
- />
240
- </>
241
- ) : (
242
- <span role="status" className="min-w-0 flex-1 truncate text-xs text-muted-foreground">
243
- Opening microphone…
244
- </span>
245
- )}
246
- <Button
247
- size="icon-sm-pill"
196
+ size="sm"
197
+ variant="outline"
198
aria-label="Stop recording"
199
disabled={phase !== "recording"}
200
onClick={() => {
@@ -252,23 +202,77 @@ export function MicrophoneTest({ microphoneId }: { microphoneId: string }) {
202
if (recorder && recorder.state !== "inactive") recorder.stop();
203
}}
204
>
255
- <CheckIcon />
205
+ <SquareIcon />
206
+ Stop
207
+ </Button>
208
+ ) : (
209
+ <Button size="sm" variant="outline" onClick={() => void start()}>
210
+ {phase === "ready" ? <RotateCcwIcon /> : <MicIcon />}
211
+ {phase === "ready" ? "Record again" : "Record"}
212
</Button>
257
- </VoiceInputPill>
213
+ );
214
+ const panel = error ? (
215
+ <p role="alert" className="min-w-0 flex-1 text-xs text-destructive">
216
+ {error}
217
+ </p>
218
+ ) : phase === "starting" ? (
219
+ <span role="status" className="min-w-0 flex-1 truncate text-xs text-muted-foreground">
220
+ Opening microphone…
221
+ </span>
222
+ ) : phase === "recording" ? (
223
+ <>
224
+ <span aria-hidden className="size-1.5 shrink-0 rounded-full bg-destructive" />
225
+ <div className="flex w-24 min-w-0">
226
+ <VoiceWaveform level={level} />
227
+ </div>
228
+ <span
229
+ className="ms-auto shrink-0 text-xs tabular-nums text-muted-foreground"
230
+ aria-label="Recording time"
231
+ >
232
+ {formatTime(elapsed)} / {formatTime(LOOPBACK_SECONDS)}
233
+ </span>
234
+ <meter
235
+ aria-label="Microphone input level"
236
+ min={0}
237
+ max={1}
238
+ value={level}
239
+ className="sr-only"
240
+ />
241
+ </>
242
+ ) : phase === "ready" && recording ? (
243
+ <MicrophonePlayback key={recording.url} src={recording.url} duration={recording.duration} />
244
+ ) : null;
245
+
246
+ return (
247
+ <SettingsRow
248
+ {...searchableSetting("microphone-test")}
249
+ title="Test microphone"
250
+ description="Record ten seconds and play it back. The audio stays on this device."
251
+ control={control}
252
+ >
253
+ {panel ? (
254
+ <div
255
+ className={cn(
256
+ "mt-3 mb-2 flex min-h-10 items-center gap-3 rounded-lg border border-border/60 bg-muted/30 py-1 pe-1",
257
+ phase === "ready" && !error ? "ps-1" : "ps-3",
258
+ )}
259
+ >
260
+ {panel}
261
+ <Button
262
+ size="icon-sm"
263
+ variant="ghost-muted"
264
+ aria-label={phase === "ready" ? "Discard recording" : "Cancel microphone test"}
265
+ onClick={cancel}
266
+ >
267
+ <XIcon />
268
+ </Button>
269
+ </div>
270
+ ) : null}
271
+ </SettingsRow>
272
);
273
}
274
261
-function MicrophonePlayback({
262
- src,
263
- duration,
264
- onRetry,
265
- onDone,
266
-}: {
267
- src: string;
268
- duration: number;
269
- onRetry(): void;
270
- onDone(): void;
271
-}) {
275
+function MicrophonePlayback({ src, duration }: { src: string; duration: number }) {
276
const audio = useRef<HTMLAudioElement>(null);
277
const [playing, setPlaying] = useState(false);
278
const [position, setPosition] = useState(0);
@@ -292,7 +296,7 @@ function MicrophonePlayback({
296
};
297
298
return (
295
- <div className="flex flex-col gap-1">
299
+ <>
300
<audio
301
ref={audio}
302
src={src}
@@ -303,15 +307,19 @@ function MicrophonePlayback({
307
onTimeUpdate={() => setPosition(audio.current?.currentTime ?? 0)}
308
onError={() => setFailed(true)}
309
/>
306
- <VoiceInputPill>
307
- <Button
308
- size="icon-sm-pill"
309
- variant="ghost"
310
- aria-label={playing ? "Pause recording" : "Play recording"}
311
- onClick={() => void togglePlayback()}
312
- >
313
- {playing ? <PauseIcon /> : <PlayIcon />}
314
- </Button>
310
+ <Button
311
+ size="icon-sm-pill"
312
+ variant="outline"
313
+ aria-label={playing ? "Pause recording" : "Play recording"}
314
+ onClick={() => void togglePlayback()}
315
+ >
316
+ {playing ? <PauseIcon /> : <PlayIcon />}
317
+ </Button>
318
+ {failed ? (
319
+ <p role="alert" className="min-w-0 flex-1 text-xs text-destructive">
320
+ Could not play this recording. Try recording again.
321
+ </p>
322
+ ) : (
323
<input
324
type="range"
325
aria-label="Recording playback position"
@@ -330,21 +338,10 @@ function MicrophonePlayback({
338
}}
339
className="h-1 min-w-0 flex-1 cursor-pointer appearance-none rounded-full bg-muted accent-primary focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring [&::-webkit-slider-thumb]:size-2.5 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-primary [&::-moz-range-thumb]:size-2.5 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-0 [&::-moz-range-thumb]:bg-primary"
340
/>
333
- <span className="shrink-0 text-xs tabular-nums text-muted-foreground">
334
- {formatTime(position)}
335
- </span>
336
- <Button size="icon-sm-pill" variant="ghost" aria-label="Record again" onClick={onRetry}>
337
- <RotateCcwIcon />
338
- </Button>
339
- <Button size="icon-sm-pill" aria-label="Done" onClick={onDone}>
340
- <CheckIcon />
341
- </Button>
342
- </VoiceInputPill>
343
- {failed ? (
344
- <p role="alert" className="text-xs text-destructive">
345
- Could not play this recording. Try recording again.
346
- </p>
347
- ) : null}
348
- </div>
341
+ )}
342
+ <span className="shrink-0 text-xs tabular-nums text-muted-foreground">
343
+ {formatTime(position)} / {formatTime(duration)}
344
+ </span>
345
+ </>
346
);
347
}
apps/web/src/components/settings/SpeechModelComparison.tsx
-27
@@ -1,7 +1,5 @@
1
import type { EnvironmentSpeechModel, SpeechBenchmarkTier } from "@t3tools/contracts";
2
-import { CheckIcon } from "lucide-react";
2
4
-import { cn } from "../../lib/utils";
3
import { languageLabel } from "./SpeechLanguageSelect";
4
5
const commonLanguages = [
@@ -45,31 +43,6 @@ export function orderSpeechLanguages(languages: readonly string[], preferred: re
43
);
44
}
45
48
-export function LanguageRow({
49
- label,
50
- selected,
51
- onClick,
52
-}: {
53
- label: string;
54
- selected: boolean;
55
- onClick: () => void;
56
-}) {
57
- return (
58
- <button
59
- type="button"
60
- aria-pressed={selected}
61
- onClick={onClick}
62
- className={cn(
63
- "flex shrink-0 cursor-pointer items-center justify-between gap-2 rounded-md px-2.5 py-1.5 text-left text-sm outline-none hover:bg-muted/50 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
64
- selected && "bg-muted font-medium",
65
- )}
66
- >
67
- {label}
68
- {selected && <CheckIcon className="size-3.5 shrink-0" />}
69
- </button>
70
- );
71
-}
72
-
46
export function ModelBenchmarks({
47
model,
48
languages,
apps/web/src/components/settings/VoiceSettingsPanel.browser.test.tsx
+56
-2
@@ -14,6 +14,7 @@ import { expect, it, vi } from "vite-plus/test";
14
import { userEvent } from "vite-plus/test/browser";
15
import { render } from "../../../test/render";
16
import { __setClientSettingsForTests, getClientSettings } from "../../hooks/useSettings";
17
+import { chooseRecordingMicrophone } from "../../speech/browserMicrophones";
18
import {
19
useEnvironmentSpeechInput,
20
useVoiceTranscriptionDestination,
@@ -331,17 +332,23 @@ it("tests the selected model after download and preserves its transcript across
332
const result = screen.getByRole("status", { name: "Test transcript" });
333
await expect.element(result).toHaveTextContent(transcript);
334
334
- const search = screen.getByRole("textbox", { name: "Search transcription models" });
335
+ const search = screen.getByRole("searchbox", { name: "Search transcription models" });
336
await userEvent.fill(search, "no matching model");
337
await expect.element(screen.getByText("No models match.")).toBeVisible();
338
await userEvent.clear(search);
339
+ const languages = screen.getByRole("button", { name: /^Filter by language/ });
340
+ await userEvent.click(languages);
341
await userEvent.fill(screen.getByRole("textbox", { name: "Search languages" }), "fr");
339
- const french = screen.getByRole("button", { name: "French", exact: true });
342
+ const french = screen.getByRole("menuitemcheckbox", { name: "French", exact: true });
343
await userEvent.click(french);
344
+ await userEvent.keyboard("{Escape}");
345
await expect.element(screen.getByText("Bilingual", { exact: true })).toBeVisible();
346
await expect.element(screen.getByText("B+", { exact: true })).toBeVisible();
347
expect(screen.container.querySelector("#transcription-test")).toHaveAttribute("hidden");
348
+ await userEvent.click(languages);
349
+ await userEvent.fill(screen.getByRole("textbox", { name: "Search languages" }), "fr");
350
await userEvent.click(french);
351
+ await userEvent.keyboard("{Escape}");
352
await expect.element(result).toBeVisible();
353
await vi.waitFor(() =>
354
expect(
@@ -591,3 +598,50 @@ it("keeps punctuation in a saved dictionary term and its alias", async () => {
598
{ term: "O'Reilly", aliases: ['"Oh Really"'] },
599
]);
600
});
601
+
602
+it("records from the first connected microphone in the saved order", async () => {
603
+ const previous = getClientSettings();
604
+ using cleanup = new DisposableStack();
605
+ cleanup.defer(() => __setClientSettingsForTests(previous));
606
+ // A single saved microphone from before the order existed comes first.
607
+ __setClientSettingsForTests({ ...previous, voiceMicrophone: "yeti", voiceMicrophones: [] });
608
+ const input = (deviceId: string, label: string) =>
609
+ ({ deviceId, label, groupId: deviceId, kind: "audioinput" }) as MediaDeviceInfo;
610
+ const yeti = input("yeti", "Blue Yeti");
611
+ const airpods = input("airpods", "AirPods Pro");
612
+ using devices = vi
613
+ .spyOn(navigator.mediaDevices, "enumerateDevices")
614
+ .mockResolvedValue([yeti, airpods]);
615
+ const saved = () =>
616
+ getClientSettings().voiceMicrophones.map((entry) =>
617
+ entry.kind === "default" ? "System default" : entry.label,
618
+ );
619
+ await using screen = await render(
620
+ <SettingsScopeProvider search={{}} onChange={() => {}}>
621
+ <VoiceSettingsPanel />
622
+ </SettingsScopeProvider>,
623
+ );
624
+ const list = screen.getByRole("list", { name: "Microphones, preferred first" });
625
+ await expect.poll(saved).toEqual(["Blue Yeti", "System default", "AirPods Pro"]);
626
+ const row = (index: number) => list.getByRole("listitem").nth(index);
627
+ await expect.element(row(0)).toHaveTextContent("1Blue YetiIn use");
628
+ expect(await chooseRecordingMicrophone()).toBe("yeti");
629
+
630
+ devices.mockResolvedValue([airpods]);
631
+ await userEvent.click(screen.getByRole("button", { name: "Refresh microphones" }));
632
+ await expect.element(row(0)).toHaveTextContent("1Blue YetiNot connected");
633
+ await expect.element(row(1)).toHaveTextContent("2System defaultIn use");
634
+ expect(await chooseRecordingMicrophone()).toBe("");
635
+
636
+ await userEvent.click(screen.getByRole("button", { name: "Move AirPods Pro up" }));
637
+ await userEvent.click(screen.getByRole("button", { name: "Move AirPods Pro up" }));
638
+ expect(saved()).toEqual(["AirPods Pro", "Blue Yeti", "System default"]);
639
+ await expect.element(screen.getByRole("button", { name: "Move AirPods Pro up" })).toBeDisabled();
640
+ expect(await chooseRecordingMicrophone()).toBe("airpods");
641
+
642
+ await userEvent.click(screen.getByRole("button", { name: "Forget Blue Yeti" }));
643
+ expect(saved()).toEqual(["AirPods Pro", "System default"]);
644
+ await expect
645
+ .element(screen.getByRole("button", { name: "Forget System default" }))
646
+ .not.toBeInTheDocument();
647
+});
apps/web/src/components/settings/VoiceSettingsPanel.tsx
+514
-505
@@ -32,6 +32,7 @@ import { createModelSelection } from "@t3tools/shared/model";
32
import { resolveSpeechPostProcessingModelSelection } from "@t3tools/shared/serverSettings";
33
import { cloudSpeechLanguages } from "@t3tools/shared/speech";
34
import {
35
+ ArrowDownUpIcon,
36
AudioLinesIcon,
37
CheckIcon,
38
DownloadIcon,
@@ -40,9 +41,10 @@ import {
41
MonitorIcon,
42
MicOffIcon,
43
MicIcon,
44
+ PlusIcon,
45
RefreshCwIcon,
46
+ SearchIcon,
47
StarIcon,
45
- SlidersHorizontalIcon,
48
Trash2Icon,
49
UnlinkIcon,
50
XIcon,
@@ -50,7 +52,17 @@ import {
52
import { useEffect, useRef, useState, type ReactNode } from "react";
53
54
import { useStableCallback } from "~/hooks/useStableCallback";
53
-import { listBrowserMicrophones, type BrowserMicrophone } from "../../speech/browserMicrophones";
55
+import { cn } from "~/lib/utils";
56
+import {
57
+ listAudioInputs,
58
+ updateMicrophoneOrder,
59
+ type BrowserMicrophone,
60
+} from "../../speech/browserMicrophones";
61
+import {
62
+ microphoneOrder,
63
+ preferredMicrophoneId,
64
+ rememberMicrophones,
65
+} from "../../speech/microphoneOrder";
66
import { preferredSpeechLanguages } from "../../speech/preferredSpeechLanguages";
67
import {
68
chooseAudioDestination,
@@ -91,6 +103,7 @@ import {
103
MenuRadioGroup,
104
MenuRadioItem,
105
MenuRadioItemIndicator,
106
+ MenuSearchInput,
107
MenuSeparator,
108
MenuTrigger,
109
} from "../ui/menu";
@@ -106,9 +119,10 @@ import {
119
import { Switch } from "../ui/switch";
120
import { Textarea } from "../ui/textarea";
121
import { toastManager } from "../ui/toast";
122
+import { MicrophoneOrderList } from "./MicrophoneOrderList";
123
import { MicrophoneTest } from "./MicrophoneTest";
124
import { CloudVoiceConfiguration } from "./CloudVoiceConfiguration";
111
-import { LanguageRow, ModelBenchmarks, orderSpeechLanguages } from "./SpeechModelComparison";
125
+import { ModelBenchmarks, orderSpeechLanguages } from "./SpeechModelComparison";
126
import { languageLabel, SpeechLanguageSelect } from "./SpeechLanguageSelect";
127
import { filterSpeechModels, type SpeechModelSort } from "./speechModelBrowser";
128
import { AdvancedSettings } from "./AdvancedSettings";
@@ -136,12 +150,11 @@ function CloudSpeechLogo({ provider }: { provider: CloudSpeechProvider }) {
150
/>
151
);
152
}
139
-const SYSTEM_DEFAULT = "system-default";
153
const formatSize = (bytes: number) => `${Math.round(bytes / 1024 / 1024)} MB`;
141
-const SHORTCUT_MODE_LABELS: Record<VoiceShortcutMode, string> = {
142
- auto: "Auto: press to toggle, hold to record",
143
- hold: "Hold: record while held",
144
- toggle: "Toggle: press to start, press again to stop",
154
+const SHORTCUT_MODES: Record<VoiceShortcutMode, { label: string; hint: string }> = {
155
+ auto: { label: "Auto", hint: "Tap to toggle, hold to talk" },
156
+ hold: { label: "Hold", hint: "Record while held" },
157
+ toggle: { label: "Toggle", hint: "Tap to start, tap to stop" },
158
};
159
const UNLOAD_LABELS: Record<SpeechModelUnloadTimeout, string> = {
160
never: "Never",
@@ -171,6 +184,8 @@ type ModelCardProps = {
184
readonly onCancel: () => void;
185
readonly onDelete: () => void;
186
readonly testControls?: ReactNode;
187
+ /** Keeps the controls under the text, so a live test never squeezes the model's details. */
188
+ readonly stacked?: boolean;
189
readonly children?: ReactNode;
190
};
191
@@ -191,120 +206,128 @@ function ModelCard(props: ModelCardProps) {
206
const downloading = model.state === "downloading" || model.state === "verifying";
207
const progress = model.downloaded === undefined ? 0 : (model.downloaded / model.size) * 100;
208
return (
194
- <div className="flex flex-wrap items-start gap-3 px-3 py-2.5 sm:px-4">
195
- <div className="min-w-0 flex-1">
196
- <div className="flex flex-wrap items-center gap-1.5">
197
- <span className="text-sm font-medium leading-5">{model.name}</span>
198
- {model.recommended ? (
199
- <ModelBadge
200
- icon={<StarIcon className="mr-1 size-3" />}
201
- label="Recommended"
202
- tooltip="A good default pick for the languages it covers."
203
- />
209
+ <div className="@container/model px-3 py-3">
210
+ <div
211
+ className={cn(
212
+ "flex flex-col gap-2.5",
213
+ !props.stacked &&
214
+ "@min-[28rem]/model:flex-row @min-[28rem]/model:items-start @min-[28rem]/model:gap-4",
215
+ )}
216
+ >
217
+ <div className="min-w-0 flex-1">
218
+ <div className="flex flex-wrap items-center gap-1.5">
219
+ <span className="text-sm font-medium leading-5">{model.name}</span>
220
+ {model.recommended ? (
221
+ <ModelBadge
222
+ icon={<StarIcon className="mr-1 size-3" />}
223
+ label="Recommended"
224
+ tooltip="A good default pick for the languages it covers."
225
+ />
226
+ ) : null}
227
+ {model.supportsStreaming ? (
228
+ <ModelBadge
229
+ icon={<AudioLinesIcon className="mr-1 size-3" />}
230
+ label="Live preview"
231
+ tooltip="Shows words in your draft as you speak, before the recording finishes."
232
+ />
233
+ ) : null}
234
+ {model.supportsTranslation ? (
235
+ <ModelBadge
236
+ icon={<LanguagesIcon className="mr-1 size-3" />}
237
+ label="Translate"
238
+ tooltip="Can write English text from speech in another language. Turn on Translate to English to use it."
239
+ />
240
+ ) : null}
241
+ </div>
242
+ {model.description ? (
243
+ <p className="mt-0.5 text-xs leading-normal text-muted-foreground">
244
+ {model.description}
245
+ </p>
246
) : null}
205
- {model.supportsStreaming ? (
206
- <ModelBadge
207
- icon={<AudioLinesIcon className="mr-1 size-3" />}
208
- label="Live preview"
209
- tooltip="Shows words in your draft as you speak, before the recording finishes."
210
- />
247
+ {model.linkedFrom ? (
248
+ <p className="mt-0.5 break-all text-2xs text-muted-foreground">
249
+ Using your file at {model.linkedFrom}
250
+ </p>
251
) : null}
212
- {model.supportsTranslation ? (
213
- <ModelBadge
214
- icon={<LanguagesIcon className="mr-1 size-3" />}
215
- label="Translate"
216
- tooltip="Can write English text from speech in another language. Turn on Translate to English to use it."
217
- />
252
+ <ModelBenchmarks
253
+ model={model}
254
+ languages={props.comparisonLanguages}
255
+ tier={props.benchmarkTier}
256
+ facts={[
257
+ ...(model.languages.length > 1
258
+ ? [`${model.languages.length} languages`]
259
+ : model.benchmark
260
+ ? []
261
+ : [languageLabel(model.languages[0] ?? "")]),
262
+ formatSize(model.size),
263
+ ]}
264
+ />
265
+ {downloading ? (
266
+ <div className="mt-2">
267
+ <div
268
+ role="progressbar"
269
+ aria-label={`${model.name} download progress`}
270
+ aria-valuemin={0}
271
+ aria-valuemax={100}
272
+ aria-valuenow={Math.round(progress)}
273
+ className="h-1 overflow-hidden rounded-full bg-muted"
274
+ >
275
+ <div
276
+ className="h-full bg-primary transition-[width] duration-200"
277
+ style={{ width: `${progress}%` }}
278
+ />
279
+ </div>
280
+ <p className="mt-1 text-2xs text-muted-foreground">
281
+ {model.state === "verifying"
282
+ ? "Verifying download…"
283
+ : `${Math.round(progress)}% downloaded`}
284
+ </p>
285
+ </div>
286
) : null}
287
</div>
220
- <p className="mt-0.5 text-xs leading-relaxed text-muted-foreground">{model.description}</p>
221
- {model.linkedFrom ? (
222
- <p className="mt-0.5 break-all text-2xs text-muted-foreground">
223
- Using your file at {model.linkedFrom}
224
- </p>
225
- ) : null}
226
- <ModelBenchmarks
227
- model={model}
228
- languages={props.comparisonLanguages}
229
- tier={props.benchmarkTier}
230
- facts={[
231
- ...(model.languages.length > 1
232
- ? [`${model.languages.length} languages`]
233
- : model.benchmark
234
- ? []
235
- : [languageLabel(model.languages[0] ?? "")]),
236
- formatSize(model.size),
237
- ]}
238
- />
239
- {downloading ? (
240
- <div className="mt-2">
241
- <div
242
- role="progressbar"
243
- aria-label={`${model.name} download progress`}
244
- aria-valuemin={0}
245
- aria-valuemax={100}
246
- aria-valuenow={Math.round(progress)}
247
- className="h-1 overflow-hidden rounded-full bg-muted"
288
+ <div className="flex max-w-full shrink-0 flex-wrap items-center gap-1.5">
289
+ {props.testControls}
290
+ {downloading ? (
291
+ <Button
292
+ size="icon-sm"
293
+ variant="outline"
294
+ aria-label={`Cancel ${model.name} download`}
295
+ disabled={!props.canCancel}
296
+ onClick={props.onCancel}
297
>
249
- <div
250
- className="h-full bg-primary transition-[width] duration-200"
251
- style={{ width: `${progress}%` }}
252
- />
253
- </div>
254
- <p className="mt-1 text-2xs text-muted-foreground">
255
- {model.state === "verifying"
256
- ? "Verifying download…"
257
- : `${Math.round(progress)}% downloaded`}
258
- </p>
259
- </div>
260
- ) : null}
261
- </div>
262
- <div className="flex max-w-full flex-wrap items-center justify-end gap-1">
263
- {props.testControls}
264
- {downloading ? (
265
- <Button
266
- size="icon-sm"
267
- variant="ghost"
268
- aria-label={`Cancel ${model.name} download`}
269
- disabled={!props.canCancel}
270
- onClick={props.onCancel}
271
- >
272
- <XIcon className="size-3.5" />
273
- </Button>
274
- ) : model.state === "downloadable" ? (
275
- <Button size="sm" variant="outline" disabled={props.busy} onClick={props.onDownload}>
276
- <DownloadIcon className="mr-1.5 size-3.5" />
277
- Download
278
- </Button>
279
- ) : model.active ? (
280
- <Button size="sm" variant="secondary" disabled>
281
- <CheckIcon className="mr-1.5 size-3.5" />
282
- Selected
283
- </Button>
284
- ) : (
285
- <Button size="sm" variant="outline" disabled={props.busy} onClick={props.onSelect}>
286
- Use model
287
- </Button>
288
- )}
289
- {model.state === "installed" ? (
290
- <Button
291
- size="icon-sm"
292
- variant="ghost"
293
- disabled={props.busy}
294
- aria-label={
295
- model.linkedFrom
296
- ? `Stop using your ${model.name} file; the file stays on disk`
297
- : `Delete ${model.name}`
298
- }
299
- onClick={props.onDelete}
300
- >
301
- {model.linkedFrom ? (
302
- <UnlinkIcon className="size-3.5" />
303
- ) : (
304
- <Trash2Icon className="size-3.5" />
305
- )}
306
- </Button>
307
- ) : null}
298
+ <XIcon className="size-3.5" />
299
+ </Button>
300
+ ) : model.state === "downloadable" ? (
301
+ <Button size="sm" variant="outline" disabled={props.busy} onClick={props.onDownload}>
302
+ <DownloadIcon />
303
+ Download
304
+ </Button>
305
+ ) : model.active ? (
306
+ <Button size="sm" variant="secondary" disabled>
307
+ <CheckIcon />
308
+ Selected
309
+ </Button>
310
+ ) : (
311
+ <Button size="sm" variant="outline" disabled={props.busy} onClick={props.onSelect}>
312
+ Use model
313
+ </Button>
314
+ )}
315
+ {model.state === "installed" ? (
316
+ <Button
317
+ size="icon-sm"
318
+ variant="outline"
319
+ disabled={props.busy}
320
+ aria-label={
321
+ model.linkedFrom
322
+ ? `Stop using your ${model.name} file; the file stays on disk`
323
+ : `Delete ${model.name}`
324
+ }
325
+ onClick={props.onDelete}
326
+ >
327
+ {model.linkedFrom ? <UnlinkIcon /> : <Trash2Icon />}
328
+ </Button>
329
+ ) : null}
330
+ </div>
331
</div>
332
{props.children}
333
</div>
@@ -356,27 +379,34 @@ function DictionaryEditor(props: {
379
};
380
return (
381
<>
359
- <div className="flex items-start gap-1.5">
360
- <Textarea
361
- value={termDraft}
362
- rows={1}
363
- maxLength={5_100}
364
- disabled={disabled}
365
- placeholder="Add words or phrases, separated by commas or line breaks"
366
- aria-label={`Add a word or phrase to the ${label}`}
367
- onChange={(event) => setTermDraft(event.target.value)}
368
- onKeyDown={(event) => {
369
- if (event.key !== "Enter" || event.shiftKey) return;
370
- event.preventDefault();
371
- addTerm();
372
- }}
373
- />
374
- <Button type="button" disabled={!canAddTerm} onClick={addTerm}>
382
+ <div className="flex items-start gap-2">
383
+ {/* One line while empty, so a wrapped placeholder never makes the field taller than Add. */}
384
+ <div className="min-w-0 flex-1 [&_textarea]:placeholder-shown:whitespace-nowrap">
385
+ <Textarea
386
+ value={termDraft}
387
+ rows={1}
388
+ maxLength={5_100}
389
+ disabled={disabled}
390
+ placeholder="Add words, separated by commas"
391
+ aria-label={`Add a word or phrase to the ${label}`}
392
+ onChange={(event) => setTermDraft(event.target.value)}
393
+ onKeyDown={(event) => {
394
+ if (event.key !== "Enter" || event.shiftKey) return;
395
+ event.preventDefault();
396
+ addTerm();
397
+ }}
398
+ />
399
+ </div>
400
+ <Button type="button" variant="outline" disabled={!canAddTerm} onClick={addTerm}>
401
+ <PlusIcon />
402
Add
403
</Button>
404
</div>
405
{words.length > 0 ? (
379
- <ul aria-label={`${label} entries`} className="mt-3 flex flex-wrap gap-1.5">
406
+ <ul
407
+ aria-label={`${label} entries`}
408
+ className="mt-2.5 flex flex-col gap-1.5 @min-[32rem]/settings-row:flex-row @min-[32rem]/settings-row:flex-wrap"
409
+ >
410
{words.map(({ term, aliases }) => (
411
<li
412
key={term}
@@ -393,7 +423,7 @@ function DictionaryEditor(props: {
423
maxLength={50}
424
aria-label={`Alias for ${term}`}
425
placeholder="Misspelling"
396
- className="w-32"
426
+ className="ms-auto w-32"
427
onChange={(event) => setAliasDraft({ term, value: event.target.value })}
428
onBlur={() => setAliasDraft(null)}
429
onKeyDown={(event) => {
@@ -408,6 +438,7 @@ function DictionaryEditor(props: {
438
type="button"
439
size="xs"
440
variant="ghost-muted"
441
+ className="ms-auto"
442
disabled={disabled || aliases.length >= 8}
443
aria-label={`Add an alias for ${term}`}
444
onClick={() => setAliasDraft({ term, value: "" })}
@@ -448,16 +479,11 @@ function ProjectDictionaryRow() {
479
title={isProjectScope ? "Project dictionary" : "Shared dictionary"}
480
description={
481
isProjectScope
451
- ? `Saved with ${scope.scope.label} on its environment. Everyone who dictates in this project gets these spellings, along with their own dictionary. Project spellings win when the two overlap.`
452
- : "Saved on the environment and used in every project there, along with each person’s own dictionary. Pick a project above to limit these words to one project."
453
- }
454
- control={
455
- <span className="text-xs text-muted-foreground">
456
- {words.length} {words.length === 1 ? "entry" : "entries"}
457
- </span>
482
+ ? `Used by everyone who dictates in ${scope.scope.label}.`
483
+ : "Used by everyone who dictates on this environment."
484
}
485
>
460
- <div className="mt-2 pb-3.5">
486
+ <div className="mt-3 pb-2">
487
<DictionaryEditor
488
label={isProjectScope ? "project dictionary" : "shared dictionary"}
489
words={words}
@@ -530,7 +556,7 @@ function CleanupModelRow() {
556
connectedEnvironments.length === 0 ? (
557
<span className="text-sm text-muted-foreground">Connect an environment first.</span>
558
) : (
533
- <div className="flex min-w-0 flex-wrap items-center justify-end gap-2">
559
+ <div className="flex min-w-0 flex-wrap items-center gap-2 @min-[32rem]/settings-row:justify-end">
560
{dedicated && (!hasProvider || !instanceEntry) ? (
561
<span className="text-sm text-muted-foreground">
562
No text generation providers available.
@@ -812,10 +838,14 @@ function SpeechModelBrowser(props: {
838
const accuracyLanguage = selectedLanguages[0] ?? "en";
839
const sortLabels: Record<SpeechModelSort, string> = {
840
recommended: "Recommended",
815
- size: "Smallest download",
816
- accuracy: `Best ${languageLabel(accuracyLanguage)} accuracy`,
817
- speed: "Fastest transcription",
841
+ size: "Smallest",
842
+ accuracy: "Most accurate",
843
+ speed: "Fastest",
844
};
845
+ const languagesLabel =
846
+ selectedLanguages.length === 0
847
+ ? "All languages"
848
+ : selectedLanguages.map(languageLabel).join(", ");
849
const sortedModels = filterSpeechModels(models, {
850
search,
851
languages: selectedLanguages,
@@ -830,212 +860,204 @@ function SpeechModelBrowser(props: {
860
? [activeModel, ...sortedModels]
861
: sortedModels;
862
863
+ if (!status) return null;
864
+ if (!status.supported)
865
+ return (
866
+ <SettingsRow
867
+ {...searchableSetting("speech-models")}
868
+ title="Models"
869
+ description={`This environment can’t transcribe audio: ${status.reason}.`}
870
+ />
871
+ );
872
return (
834
- <SettingsSearchTarget
873
+ <SettingsRow
874
{...searchableSetting("speech-models")}
875
+ title="Models"
876
+ description={`Grades are error rates and speed is seconds per 30 s of audio, from Handy’s benchmark ${status.benchmarkTier === "cpu" ? "CPU" : "GPU"}.`}
877
className="@container/voice-models"
878
>
838
- {status && !status.supported ? (
839
- <p className="px-4 py-2 text-sm text-muted-foreground">
840
- This environment can’t transcribe audio: {status.reason}.
841
- </p>
842
- ) : null}
843
- {status?.supported ? (
844
- <>
845
- <p className="border-b border-border/60 px-3 py-2 text-xs text-muted-foreground sm:px-4">
846
- Pick languages to see models that support all of them. Accuracy is word or character
847
- error rate: lower is better. Speed is the time to transcribe 30 seconds of audio on
848
- Handy’s benchmark {status.benchmarkTier === "cpu" ? "CPU" : "GPU"}.
849
- </p>
850
- <div className="@min-[32rem]/voice-models:grid @min-[32rem]/voice-models:grid-cols-[11rem_minmax(0,1fr)]">
851
- <div className="flex min-h-0 flex-col border-b border-border/60 bg-muted/10 @min-[32rem]/voice-models:border-r @min-[32rem]/voice-models:border-b-0">
852
- <div className="space-y-2 p-3">
853
- <p className="text-sm font-medium">Languages</p>
854
- <Input
855
- size="compact"
856
- aria-label="Search languages"
857
- placeholder="Search languages"
858
- value={languageSearch}
859
- onChange={(e) => setLanguageSearch(e.target.value)}
860
- />
861
- </div>
862
- <div
863
- role="group"
864
- aria-label="Browse models by language"
865
- className="flex gap-1 overflow-x-auto px-2 pb-2 @min-[32rem]/voice-models:h-72 @min-[32rem]/voice-models:flex-col @min-[32rem]/voice-models:overflow-y-auto"
866
- >
867
- <LanguageRow
868
- label="All languages"
869
- selected={selectedLanguages.length === 0}
870
- onClick={() => setSelection([])}
871
- />
872
- {visibleLanguages.map((code) => (
873
- <LanguageRow
874
- key={code}
875
- label={languageLabel(code)}
876
- selected={selectedLanguages.includes(code)}
877
- onClick={() =>
878
- setSelection(
879
- selectedLanguages.includes(code)
880
- ? selectedLanguages.filter((language) => language !== code)
881
- : [...selectedLanguages, code],
882
- )
883
- }
884
- />
885
- ))}
886
- {visibleLanguages.length === 0 && (
887
- <p className="px-2 py-1 text-xs text-muted-foreground">No languages match.</p>
888
- )}
889
- </div>
890
- </div>
891
- <div className="flex min-w-0 flex-col">
892
- <div className="space-y-2 p-3">
893
- <p className="text-sm font-medium">
894
- {selectedLanguages.length
895
- ? "Models for " + selectedLanguages.map(languageLabel).join(", ")
896
- : "All models"}
897
- </p>
898
- <InputGroup>
899
- <InputGroupInput
900
- size="compact"
901
- aria-label="Search transcription models"
902
- placeholder="Search models"
903
- value={search}
904
- onChange={(e) => setSearch(e.target.value)}
905
- />
906
- <InputGroupAddon align="inline-end">
907
- <Menu>
908
- <MenuTrigger
909
- render={<Button size="compact" variant="ghost-muted" />}
910
- aria-label={`Sort and filter models: ${sortLabels[sort]}${downloadedOnly ? ", downloaded only" : ""}`}
911
- >
912
- <SlidersHorizontalIcon />
913
- <span className="hidden @min-[40rem]/voice-models:inline">
914
- {sortLabels[sort]}
915
- </span>
916
- {downloadedOnly && <span>1</span>}
917
- </MenuTrigger>
918
- <MenuPopup align="end">
919
- <MenuGroup>
920
- <MenuGroupLabel>Sort by</MenuGroupLabel>
921
- <MenuRadioGroup
922
- value={sort}
923
- onValueChange={(value) => setSort(value as SpeechModelSort)}
924
- >
925
- {(Object.keys(sortLabels) as SpeechModelSort[]).map((value) => (
926
- <MenuRadioItem key={value} value={value} closeOnClick>
927
- <span className="flex items-center justify-between gap-3">
928
- {sortLabels[value]}
929
- <MenuRadioItemIndicator />
930
- </span>
931
- </MenuRadioItem>
932
- ))}
933
- </MenuRadioGroup>
934
- </MenuGroup>
935
- <MenuSeparator />
936
- <MenuCheckboxItem
937
- checked={downloadedOnly}
938
- onCheckedChange={setDownloadedOnly}
939
- >
940
- Downloaded only
941
- </MenuCheckboxItem>
942
- </MenuPopup>
943
- </Menu>
944
- </InputGroupAddon>
945
- </InputGroup>
946
- </div>
947
- <div
948
- className="h-72 overflow-y-auto divide-y divide-border/60"
949
- role="region"
950
- aria-label="Transcription models"
951
- tabIndex={0}
952
- >
953
- {sortedModels.length === 0 && (
954
- <p className="px-4 py-2 text-sm text-muted-foreground">No models match.</p>
955
- )}
956
- {renderedModels.map((model) => {
957
- const card: ModelCardProps = {
958
- model:
959
- model.id === requestedDownload && model.state === "downloadable"
960
- ? { ...model, state: "downloading" }
961
- : model,
962
- busy: controlsDisabled,
963
- canCancel,
964
- comparisonLanguages: selectedLanguages,
965
- benchmarkTier: status.benchmarkTier,
966
- onDownload: () =>
967
- void run(
968
- "Could not download the model",
969
- () =>
970
- runEnvironmentSpeech(downloadEnvironmentSpeechModel(prepared, model.id)),
971
- model.id,
972
- ),
973
- onSelect: () =>
974
- void run("Could not select the model", () =>
975
- runEnvironmentSpeech(selectEnvironmentSpeechModel(prepared, model.id)),
976
- ),
977
- onCancel: () =>
978
- void run("Could not cancel the download", () =>
979
- runEnvironmentSpeech(
980
- cancelEnvironmentSpeechModelDownload(prepared, model.id),
981
- ),
982
- ),
983
- onDelete: () =>
984
- void run("Could not delete the model", () =>
985
- runEnvironmentSpeech(removeEnvironmentSpeechModel(prepared, model.id)),
986
- ),
987
- };
988
- return model.active ? (
989
- <TranscriptionTest
990
- key={model.id}
991
- card={card}
992
- hidden={!sortedModels.includes(model)}
993
- environmentId={props.testEnvironmentId}
994
- projectId={props.projectId}
995
- projectName={props.projectName}
996
- />
997
- ) : (
998
- <ModelCard key={model.id} {...card} />
999
- );
1000
- })}
1001
- </div>
1002
- {status.supportsModelLinking && canReadFiles ? (
1003
- <form
1004
- className="flex items-center gap-2 border-t border-border/60 p-3"
1005
- onSubmit={(event) => {
1006
- event.preventDefault();
1007
- void run("Could not use a model from that path", async () => {
1008
- await runEnvironmentSpeech(
1009
- linkEnvironmentSpeechModels(prepared, existingPath),
1010
- );
1011
- setExistingPath("");
1012
- });
1013
- }}
879
+ <div className="mt-3 flex min-w-0 gap-2">
880
+ <InputGroup className="min-w-0 flex-1 **:[input]:h-9 sm:**:[input]:h-8">
881
+ <InputGroupAddon>
882
+ <SearchIcon aria-hidden />
883
+ </InputGroupAddon>
884
+ <InputGroupInput
885
+ type="search"
886
+ aria-label="Search transcription models"
887
+ placeholder="Search models"
888
+ value={search}
889
+ onChange={(e) => setSearch(e.target.value)}
890
+ />
891
+ </InputGroup>
892
+ <Menu>
893
+ <MenuTrigger
894
+ render={<Button variant="outline" className="max-w-56" />}
895
+ aria-label={`Filter by language: ${languagesLabel}`}
896
+ >
897
+ <LanguagesIcon />
898
+ <span className="hidden truncate @min-[34rem]/voice-models:inline">
899
+ {languagesLabel}
900
+ </span>
901
+ </MenuTrigger>
902
+ <MenuPopup align="end">
903
+ <MenuSearchInput
904
+ autoFocus
905
+ aria-label="Search languages"
906
+ placeholder="Search languages"
907
+ value={languageSearch}
908
+ onChange={(e) => setLanguageSearch(e.target.value)}
909
+ />
910
+ <div
911
+ role="group"
912
+ aria-label="Browse models by language"
913
+ className="max-h-72 overflow-y-auto"
914
+ >
915
+ {needle ? null : (
916
+ <MenuCheckboxItem
917
+ checked={selectedLanguages.length === 0}
918
+ onCheckedChange={() => setSelection([])}
919
>
1015
- <div className="min-w-0 flex-1">
1016
- <Input
1017
- size="compact"
1018
- aria-label="Path to a model file or folder already on this environment"
1019
- placeholder="Already downloaded elsewhere? Paste the model file or folder path"
1020
- value={existingPath}
1021
- onChange={(e) => setExistingPath(e.target.value)}
1022
- />
1023
- </div>
1024
- <Button
1025
- type="submit"
1026
- size="sm"
1027
- variant="outline"
1028
- disabled={controlsDisabled || !existingPath.trim()}
1029
- >
1030
- Use existing
1031
- </Button>
1032
- </form>
1033
- ) : null}
920
+ All languages
921
+ </MenuCheckboxItem>
922
+ )}
923
+ {visibleLanguages.map((code) => (
924
+ <MenuCheckboxItem
925
+ key={code}
926
+ checked={selectedLanguages.includes(code)}
927
+ onCheckedChange={() =>
928
+ setSelection(
929
+ selectedLanguages.includes(code)
930
+ ? selectedLanguages.filter((language) => language !== code)
931
+ : [...selectedLanguages, code],
932
+ )
933
+ }
934
+ >
935
+ {languageLabel(code)}
936
+ </MenuCheckboxItem>
937
+ ))}
938
+ {visibleLanguages.length === 0 && (
939
+ <p className="px-2 py-1.5 text-sm text-muted-foreground">No languages match.</p>
940
+ )}
941
</div>
942
+ </MenuPopup>
943
+ </Menu>
944
+ <Menu>
945
+ <MenuTrigger
946
+ render={<Button variant="outline" />}
947
+ aria-label={`Sort and filter models: ${sortLabels[sort]}${downloadedOnly ? ", downloaded only" : ""}`}
948
+ >
949
+ <ArrowDownUpIcon />
950
+ <span className="hidden @min-[34rem]/voice-models:inline">{sortLabels[sort]}</span>
951
+ </MenuTrigger>
952
+ <MenuPopup align="end">
953
+ <MenuGroup>
954
+ <MenuGroupLabel>Sort by</MenuGroupLabel>
955
+ <MenuRadioGroup
956
+ value={sort}
957
+ onValueChange={(value) => setSort(value as SpeechModelSort)}
958
+ >
959
+ {(Object.keys(sortLabels) as SpeechModelSort[]).map((value) => (
960
+ <MenuRadioItem key={value} value={value} closeOnClick>
961
+ <span className="flex items-center justify-between gap-3">
962
+ {value === "accuracy"
963
+ ? `Most accurate in ${languageLabel(accuracyLanguage)}`
964
+ : sortLabels[value]}
965
+ <MenuRadioItemIndicator />
966
+ </span>
967
+ </MenuRadioItem>
968
+ ))}
969
+ </MenuRadioGroup>
970
+ </MenuGroup>
971
+ <MenuSeparator />
972
+ <MenuCheckboxItem checked={downloadedOnly} onCheckedChange={setDownloadedOnly}>
973
+ Downloaded only
974
+ </MenuCheckboxItem>
975
+ </MenuPopup>
976
+ </Menu>
977
+ </div>
978
+ <div
979
+ className="mt-2 mb-2 max-h-96 divide-y divide-border/60 overflow-y-auto rounded-lg border border-border/60"
980
+ role="region"
981
+ aria-label="Transcription models"
982
+ tabIndex={0}
983
+ >
984
+ {sortedModels.length === 0 && (
985
+ <p className="px-3 py-3 text-sm text-muted-foreground">No models match.</p>
986
+ )}
987
+ {renderedModels.map((model) => {
988
+ const card: ModelCardProps = {
989
+ model:
990
+ model.id === requestedDownload && model.state === "downloadable"
991
+ ? { ...model, state: "downloading" }
992
+ : model,
993
+ busy: controlsDisabled,
994
+ canCancel,
995
+ comparisonLanguages: selectedLanguages,
996
+ benchmarkTier: status.benchmarkTier,
997
+ onDownload: () =>
998
+ void run(
999
+ "Could not download the model",
1000
+ () => runEnvironmentSpeech(downloadEnvironmentSpeechModel(prepared, model.id)),
1001
+ model.id,
1002
+ ),
1003
+ onSelect: () =>
1004
+ void run("Could not select the model", () =>
1005
+ runEnvironmentSpeech(selectEnvironmentSpeechModel(prepared, model.id)),
1006
+ ),
1007
+ onCancel: () =>
1008
+ void run("Could not cancel the download", () =>
1009
+ runEnvironmentSpeech(cancelEnvironmentSpeechModelDownload(prepared, model.id)),
1010
+ ),
1011
+ onDelete: () =>
1012
+ void run("Could not delete the model", () =>
1013
+ runEnvironmentSpeech(removeEnvironmentSpeechModel(prepared, model.id)),
1014
+ ),
1015
+ };
1016
+ return model.active ? (
1017
+ <TranscriptionTest
1018
+ key={model.id}
1019
+ card={card}
1020
+ hidden={!sortedModels.includes(model)}
1021
+ environmentId={props.testEnvironmentId}
1022
+ projectId={props.projectId}
1023
+ projectName={props.projectName}
1024
+ />
1025
+ ) : (
1026
+ <ModelCard key={model.id} {...card} />
1027
+ );
1028
+ })}
1029
+ </div>
1030
+ {status.supportsModelLinking && canReadFiles ? (
1031
+ <form
1032
+ className="mb-2 flex flex-col items-start gap-2 @min-[28rem]/voice-models:flex-row @min-[28rem]/voice-models:items-center"
1033
+ onSubmit={(event) => {
1034
+ event.preventDefault();
1035
+ void run("Could not use a model from that path", async () => {
1036
+ await runEnvironmentSpeech(linkEnvironmentSpeechModels(prepared, existingPath));
1037
+ setExistingPath("");
1038
+ });
1039
+ }}
1040
+ >
1041
+ <div className="w-full min-w-0 flex-1">
1042
+ <Input
1043
+ size="compact"
1044
+ aria-label="Path to a model file or folder already on this environment"
1045
+ placeholder="Already downloaded elsewhere? Paste the model file or folder path"
1046
+ value={existingPath}
1047
+ onChange={(e) => setExistingPath(e.target.value)}
1048
+ />
1049
</div>
1036
- </>
1050
+ <Button
1051
+ type="submit"
1052
+ size="sm"
1053
+ variant="outline"
1054
+ disabled={controlsDisabled || !existingPath.trim()}
1055
+ >
1056
+ Use existing
1057
+ </Button>
1058
+ </form>
1059
) : null}
1038
- </SettingsSearchTarget>
1060
+ </SettingsRow>
1061
);
1062
}
1063
@@ -1071,8 +1093,9 @@ function TranscriptionTest(props: {
1093
<SettingsSearchTarget {...searchableSetting("transcription-test")} hidden={props.hidden}>
1094
<ModelCard
1095
{...props.card}
1096
+ stacked={showTranscript}
1097
testControls={
1075
- <div className="flex min-w-0 max-w-full items-center gap-1">
1098
+ <div className="order-last flex min-w-0 max-w-full basis-full items-center gap-1 @min-[28rem]/model:order-none @min-[28rem]/model:basis-auto">
1099
<ComposerSpeechRecordingPill
1100
state={speech.state}
1101
progress={null}
@@ -1107,40 +1130,41 @@ function TranscriptionTest(props: {
1130
}
1131
>
1132
{showTranscript ? (
1110
- <div className="w-full">
1111
- <div className="flex items-start gap-2">
1112
- <p className="min-w-0 flex-1 text-xs leading-relaxed text-muted-foreground">
1113
- Say a sentence in the language above. Cleanup is skipped, so you see exactly what
1114
- the model heard. The transcript stays on this page.
1115
- </p>
1116
- <Button
1117
- size="icon-sm"
1118
- variant="ghost"
1119
- aria-label="Close model test"
1120
- onClick={() => {
1121
- speech.cancel();
1122
- setShowTranscript(false);
1123
- }}
1124
- >
1125
- <XIcon />
1126
- </Button>
1133
+ <div className="mt-3 flex items-start gap-3 rounded-lg border border-border/60 bg-muted/30 py-1 ps-3 pe-1">
1134
+ <div className="min-w-0 flex-1 py-1.5">
1135
+ {speech.preview || transcript !== null ? null : (
1136
+ <p className="text-xs text-muted-foreground">
1137
+ Say a sentence. Cleanup is skipped, so you see exactly what the model heard.
1138
+ </p>
1139
+ )}
1140
+ {speech.preview || transcript !== null ? (
1141
+ <p
1142
+ role="status"
1143
+ aria-label="Test transcript"
1144
+ className="select-text whitespace-pre-wrap break-words text-sm leading-relaxed"
1145
+ >
1146
+ {speech.preview ? (
1147
+ <>
1148
+ {speech.preview.committed}
1149
+ <span className="text-muted-foreground">{speech.preview.tentative}</span>
1150
+ </>
1151
+ ) : (
1152
+ transcript || "No speech recognized. Try again."
1153
+ )}
1154
+ </p>
1155
+ ) : null}
1156
</div>
1128
- {speech.preview || transcript !== null ? (
1129
- <p
1130
- role="status"
1131
- aria-label="Test transcript"
1132
- className="mt-2 select-text whitespace-pre-wrap break-words text-sm leading-relaxed"
1133
- >
1134
- {speech.preview ? (
1135
- <>
1136
- {speech.preview.committed}
1137
- <span className="text-muted-foreground">{speech.preview.tentative}</span>
1138
- </>
1139
- ) : (
1140
- transcript || "No speech recognized. Try again."
1141
- )}
1142
- </p>
1143
- ) : null}
1157
+ <Button
1158
+ size="icon-sm"
1159
+ variant="ghost-muted"
1160
+ aria-label="Close model test"
1161
+ onClick={() => {
1162
+ speech.cancel();
1163
+ setShowTranscript(false);
1164
+ }}
1165
+ >
1166
+ <XIcon />
1167
+ </Button>
1168
</div>
1169
) : null}
1170
</ModelCard>
@@ -1181,7 +1205,9 @@ export function VoiceSettingsPanel() {
1205
const refreshMicrophones = useStableCallback(async () => {
1206
if (!navigator.mediaDevices?.enumerateDevices) return;
1207
try {
1184
- setMicrophones(await listBrowserMicrophones());
1208
+ const devices = await listAudioInputs();
1209
+ setMicrophones(devices);
1210
+ updateMicrophoneOrder((order) => rememberMicrophones(order, devices));
1211
} catch {
1212
setMicrophones([]);
1213
}
@@ -1203,11 +1229,8 @@ export function VoiceSettingsPanel() {
1229
(member) => member.environmentId === target?.environmentId && member.id === target.projectId,
1230
) ?? members?.[0];
1231
1206
- const selectedMicrophone = settings.voiceMicrophone;
1207
- const selectedMicrophoneLabel = selectedMicrophone
1208
- ? (microphones.find((device) => device.deviceId === selectedMicrophone)?.label ??
1209
- "Selected microphone (unavailable)")
1210
- : "System default";
1232
+ const order = microphoneOrder(settings);
1233
+ const selectedMicrophone = preferredMicrophoneId(order, microphones);
1234
const environmentChoices = environments.map((environment) => ({
1235
environment,
1236
value: JSON.stringify(["environment", environment.environmentId]),
@@ -1266,52 +1289,39 @@ export function VoiceSettingsPanel() {
1289
<SettingsRow
1290
{...searchableSetting("voice-microphone")}
1291
title="Microphone"
1269
- description="System default follows your operating system. Record a ten-second test and play it back here. Test audio stays on this device and is never transcribed."
1292
+ description="Voice input uses the first connected microphone in this list."
1293
control={
1271
- <div className="flex min-w-0 flex-wrap items-center justify-end gap-1.5">
1272
- <SettingsSearchTarget {...searchableSetting("microphone-test")}>
1273
- <MicrophoneTest key={selectedMicrophone} microphoneId={selectedMicrophone} />
1274
- </SettingsSearchTarget>
1275
- <div className="flex min-w-0 items-center gap-1.5">
1276
- <Select
1277
- value={selectedMicrophone ? `device:${selectedMicrophone}` : SYSTEM_DEFAULT}
1278
- onValueChange={(value) => {
1279
- if (value)
1280
- void updateClientSettings({
1281
- voiceMicrophone:
1282
- value === SYSTEM_DEFAULT ? "" : value.slice("device:".length),
1283
- });
1284
- }}
1285
- >
1286
- <SelectTrigger size="sm" aria-label="Microphone" className="max-w-64">
1287
- <SelectValue>{selectedMicrophoneLabel}</SelectValue>
1288
- </SelectTrigger>
1289
- <SelectPopup align="end" alignItemWithTrigger={false}>
1290
- <SelectItem value={SYSTEM_DEFAULT}>System default</SelectItem>
1291
- {microphones.map((device) => (
1292
- <SelectItem key={device.deviceId} value={`device:${device.deviceId}`}>
1293
- {device.label}
1294
- </SelectItem>
1295
- ))}
1296
- </SelectPopup>
1297
- </Select>
1298
- <Button
1299
- type="button"
1300
- variant="ghost"
1301
- size="icon-sm"
1302
- aria-label="Refresh microphones"
1303
- onClick={() => void refreshMicrophones()}
1304
- >
1305
- <RefreshCwIcon className="size-3.5" />
1306
- </Button>
1307
- </div>
1308
- </div>
1294
+ <Tooltip>
1295
+ <TooltipTrigger
1296
+ render={
1297
+ <Button
1298
+ type="button"
1299
+ variant="outline"
1300
+ size="icon-sm"
1301
+ aria-label="Refresh microphones"
1302
+ onClick={() => void refreshMicrophones()}
1303
+ >
1304
+ <RefreshCwIcon />
1305
+ </Button>
1306
+ }
1307
+ />
1308
+ <TooltipPopup>Refresh microphones</TooltipPopup>
1309
+ </Tooltip>
1310
}
1311
+ >
1312
+ <div className="mt-3 pb-2">
1313
+ <MicrophoneOrderList order={order} devices={microphones} />
1314
+ </div>
1315
+ </SettingsRow>
1316
+ <MicrophoneTest
1317
+ key={selectedMicrophone}
1318
+ microphoneId={selectedMicrophone}
1319
+ onMicrophoneAccess={() => void refreshMicrophones()}
1320
/>
1321
<SettingsRow
1322
{...searchableSetting("dictation-shortcut-mode")}
1323
title="Dictation shortcut"
1314
- description="How the dictation shortcut starts and stops recording."
1324
+ description={`${SHORTCUT_MODES[settings.voiceShortcutMode].hint}.`}
1325
control={
1326
<Select
1327
value={settings.voiceShortcutMode}
@@ -1320,13 +1330,18 @@ export function VoiceSettingsPanel() {
1330
void updateClientSettings({ voiceShortcutMode: value as VoiceShortcutMode });
1331
}}
1332
>
1323
- <SelectTrigger size="sm" aria-label="Dictation shortcut mode" className="max-w-72">
1324
- <SelectValue>{SHORTCUT_MODE_LABELS[settings.voiceShortcutMode]}</SelectValue>
1333
+ <SelectTrigger size="sm" aria-label="Dictation shortcut mode">
1334
+ <SelectValue>{SHORTCUT_MODES[settings.voiceShortcutMode].label}</SelectValue>
1335
</SelectTrigger>
1336
<SelectPopup align="end" alignItemWithTrigger={false}>
1327
- {(Object.keys(SHORTCUT_MODE_LABELS) as VoiceShortcutMode[]).map((mode) => (
1337
+ {(Object.keys(SHORTCUT_MODES) as VoiceShortcutMode[]).map((mode) => (
1338
<SelectItem key={mode} value={mode}>
1329
- {SHORTCUT_MODE_LABELS[mode]}
1339
+ <span className="flex flex-col">
1340
+ {SHORTCUT_MODES[mode].label}
1341
+ <span className="text-xs text-muted-foreground">
1342
+ {SHORTCUT_MODES[mode].hint}
1343
+ </span>
1344
+ </span>
1345
</SelectItem>
1346
))}
1347
</SelectPopup>
@@ -1336,16 +1351,16 @@ export function VoiceSettingsPanel() {
1351
</SettingsSection>
1352
1353
<SettingsSection id="voice-transcription" title="Transcription">
1339
- <SettingsSearchTarget
1354
+ <SettingsRow
1355
{...searchableSetting("voice-transcription-destination")}
1341
- className="@container/destination px-3 py-3 sm:px-4"
1342
- >
1343
- <div className="flex items-center justify-between gap-2">
1344
- <h3 className="shrink-0 text-sm font-medium">
1345
- <span className="@max-[18rem]/destination:hidden">Transcribe with</span>
1346
- <span className="@min-[18rem]/destination:hidden">Use</span>
1347
- </h3>
1348
- <div className="flex min-w-0 items-center justify-end gap-1">
1356
+ title="Transcribe with"
1357
+ description={
1358
+ destination.environmentId && chosenUnsupported
1359
+ ? `${chosenEnvironment.label} can’t transcribe audio locally. Choose another destination.`
1360
+ : "Where your speech is turned into text."
1361
+ }
1362
+ control={
1363
+ <div className="flex w-full min-w-0 items-center gap-1.5 @min-[32rem]/settings-row:w-auto">
1364
<Select
1365
value={destinationValue}
1366
onValueChange={(value) => {
@@ -1371,7 +1386,7 @@ export function VoiceSettingsPanel() {
1386
<SelectTrigger
1387
size="sm"
1388
aria-label="Transcribe with"
1374
- className="w-auto min-w-0 max-w-72"
1389
+ className="min-w-0 @min-[32rem]/settings-row:w-auto @min-[32rem]/settings-row:max-w-72"
1390
>
1391
<SelectValue>
1392
<span className="flex min-w-0 items-center gap-2">
@@ -1472,15 +1487,8 @@ export function VoiceSettingsPanel() {
1487
</Tooltip>
1488
)}
1489
</div>
1475
- </div>
1476
- {destination.environmentId && chosenUnsupported ? (
1477
- <p className="mt-2 text-xs text-destructive">
1478
- {chosenEnvironment.label} can’t transcribe audio locally. Choose a different
1479
- destination.
1480
- </p>
1481
- ) : null}
1482
- </SettingsSearchTarget>
1483
-
1490
+ }
1491
+ />
1492
{pendingCloud && cloudEnvironment && (
1493
<CloudVoiceConfiguration
1494
key={JSON.stringify(pendingCloud)}
@@ -1499,10 +1507,10 @@ export function VoiceSettingsPanel() {
1507
title="Language"
1508
description={
1509
destination.cloudProvider
1502
- ? "The cloud provider can detect your language automatically."
1503
- : model
1504
- ? `${model.model} ${model.supportsLanguageDetection ? "detects the language automatically" : "uses one fixed language"}.`
1505
- : "Choose an environment above to see the languages its transcription model supports."
1510
+ ? "The provider detects your language automatically."
1511
+ : model?.supportsLanguageDetection
1512
+ ? `${model.model} detects the language automatically.`
1513
+ : `${model?.model ?? "This model"} uses one fixed language.`
1514
}
1515
control={
1516
<SpeechLanguageSelect
@@ -1526,28 +1534,13 @@ export function VoiceSettingsPanel() {
1534
}
1535
/>
1536
) : null}
1529
- {prepared ? (
1530
- <SpeechModelBrowser
1531
- key={prepared.environmentId}
1532
- prepared={prepared}
1533
- catalog={catalog}
1534
- testEnvironmentId={
1535
- project?.environmentId ?? target?.environmentId ?? prepared.environmentId
1536
- }
1537
- projectId={project?.id ?? null}
1538
- projectName={project?.title ?? null}
1539
- />
1540
- ) : null}
1541
- {prepared && <AdvancedSpeechSettings prepared={prepared} catalog={catalog} />}
1542
- </SettingsSection>
1543
- <SettingsSection id="voice-recognition" title="Transcription options">
1537
<SettingsRow
1538
{...searchableSetting("speech-silence-filtering")}
1539
title="Silence filtering"
1540
description={
1541
destination.cloudProvider === "openai"
1549
- ? "OpenAI handles silence automatically."
1550
- : "Skip silence and other non-speech audio before transcription, keeping a short buffer so words aren’t cut off."
1542
+ ? "OpenAI handles silence itself."
1543
+ : "Skip silence and background noise before transcribing."
1544
}
1545
control={
1546
<Switch
@@ -1563,7 +1556,7 @@ export function VoiceSettingsPanel() {
1556
<SettingsRow
1557
{...searchableSetting("remove-filler-words")}
1558
title="Remove filler words"
1566
- description="Remove filler words like “um” and “uh” from transcripts."
1559
+ description="Drop “um” and “uh” from transcripts."
1560
control={
1561
<Switch
1562
aria-label="Remove filler words"
@@ -1574,18 +1567,28 @@ export function VoiceSettingsPanel() {
1567
/>
1568
}
1569
/>
1570
+ {prepared ? (
1571
+ <SpeechModelBrowser
1572
+ key={prepared.environmentId}
1573
+ prepared={prepared}
1574
+ catalog={catalog}
1575
+ testEnvironmentId={
1576
+ project?.environmentId ?? target?.environmentId ?? prepared.environmentId
1577
+ }
1578
+ projectId={project?.id ?? null}
1579
+ projectName={project?.title ?? null}
1580
+ />
1581
+ ) : null}
1582
+ {prepared && <AdvancedSpeechSettings prepared={prepared} catalog={catalog} />}
1583
+ </SettingsSection>
1584
+
1585
+ <SettingsSection id="voice-dictionary" title="Dictionary">
1586
<SettingsRow
1587
{...searchableSetting("speech-dictionary")}
1579
- title="Dictionary"
1580
- description="Names and terms transcription should spell your way, saved on this device. Add an alias when it keeps hearing a term wrong. The name of the project you dictate in is also sent as a hint."
1581
- control={
1582
- <span className="text-xs text-muted-foreground">
1583
- {settings.speechCustomWords.length}{" "}
1584
- {settings.speechCustomWords.length === 1 ? "entry" : "entries"}
1585
- </span>
1586
- }
1588
+ title="Your dictionary"
1589
+ description="Names and terms to spell your way, saved on this device."
1590
>
1588
- <div className="mt-2 pb-3.5">
1591
+ <div className="mt-3 pb-2">
1592
<DictionaryEditor
1593
label="dictionary"
1594
words={settings.speechCustomWords}
@@ -1599,7 +1602,7 @@ export function VoiceSettingsPanel() {
1602
<SettingsSection id={searchableSetting("speech-post-processing").id} title="Cleanup">
1603
<SettingsRow
1604
title="Clean up transcripts"
1602
- description="Fixes punctuation, numbers, and spoken corrections with the cleanup model on the draft’s environment. Sends the transcript and nearby draft text, never audio."
1605
+ description="Off by default. Sends the transcript and nearby draft text, never audio, to the cleanup model."
1606
control={
1607
<Switch
1608
aria-label="Clean up transcripts"
@@ -1610,8 +1613,12 @@ export function VoiceSettingsPanel() {
1613
/>
1614
{cleanupEnabled ? (
1615
<SettingsRow
1613
- title="Cleanup instructions"
1614
- description="Use the built-in instructions or write your own."
1616
+ title="Instructions"
1617
+ description={
1618
+ settings.speechPostProcessingPrompt.mode === "custom"
1619
+ ? "Your own instructions for cleanup."
1620
+ : "Fix punctuation, numbers, lists, and spoken corrections."
1621
+ }
1622
control={
1623
<Select
1624
value={settings.speechPostProcessingPrompt.mode}
@@ -1619,13 +1626,17 @@ export function VoiceSettingsPanel() {
1626
if (value === "default" || value === "custom")
1627
void updateClientSettings({
1628
speechPostProcessingPrompt: {
1622
- ...settings.speechPostProcessingPrompt,
1629
mode: value,
1630
+ customInstructions:
1631
+ value === "custom" &&
1632
+ !settings.speechPostProcessingPrompt.customInstructions.trim()
1633
+ ? DEFAULT_SPEECH_POST_PROCESSING_PROMPT
1634
+ : settings.speechPostProcessingPrompt.customInstructions,
1635
},
1636
});
1637
}}
1638
>
1628
- <SelectTrigger size="sm" aria-label="Cleanup instructions" className="max-w-64">
1639
+ <SelectTrigger size="sm" aria-label="Cleanup instructions">
1640
<SelectValue>
1641
{settings.speechPostProcessingPrompt.mode === "custom" ? "Custom" : "Built-in"}
1642
</SelectValue>
@@ -1637,25 +1648,23 @@ export function VoiceSettingsPanel() {
1648
</Select>
1649
}
1650
>
1640
- <Textarea
1641
- aria-label="Custom cleanup instructions"
1642
- className="mt-2"
1643
- maxLength={10_000}
1644
- disabled={settings.speechPostProcessingPrompt.mode !== "custom"}
1645
- value={
1646
- settings.speechPostProcessingPrompt.mode === "custom"
1647
- ? settings.speechPostProcessingPrompt.customInstructions
1648
- : DEFAULT_SPEECH_POST_PROCESSING_PROMPT
1649
- }
1650
- onChange={(event) =>
1651
- void updateClientSettings({
1652
- speechPostProcessingPrompt: {
1653
- mode: "custom",
1654
- customInstructions: event.target.value,
1655
- },
1656
- })
1657
- }
1658
- />
1651
+ {settings.speechPostProcessingPrompt.mode === "custom" ? (
1652
+ <div className="mt-3 pb-2">
1653
+ <Textarea
1654
+ aria-label="Custom cleanup instructions"
1655
+ maxLength={10_000}
1656
+ value={settings.speechPostProcessingPrompt.customInstructions}
1657
+ onChange={(event) =>
1658
+ void updateClientSettings({
1659
+ speechPostProcessingPrompt: {
1660
+ mode: "custom",
1661
+ customInstructions: event.target.value,
1662
+ },
1663
+ })
1664
+ }
1665
+ />
1666
+ </div>
1667
+ ) : null}
1668
</SettingsRow>
1669
) : null}
1670
{cleanupEnabled && settingsScope !== null ? <CleanupModelRow /> : null}
@@ -1663,7 +1672,7 @@ export function VoiceSettingsPanel() {
1672
<SettingsRow
1673
{...searchableSetting("speech-correction-word")}
1674
title="Correction cue"
1666
- description="The word or phrase you say to flag a correction, like “sorry” or “scratch that”. Cleanup applies the correction only where one is meant, and hears the cue as a hint."
1675
+ description="The phrase you say to fix a mistake, like “scratch that”."
1676
control={
1677
<Input
1678
key={settings.speechCorrectionWord}
@@ -1671,7 +1680,7 @@ export function VoiceSettingsPanel() {
1680
maxLength={50}
1681
placeholder="sorry"
1682
aria-label="Correction cue"
1674
- className="w-40"
1683
+ className="@min-[32rem]/settings-row:w-40"
1684
onBlur={(event) => {
1685
const next = event.target.value.trim();
1686
if (next !== settings.speechCorrectionWord)
apps/web/src/components/settings/settingsSearch.ts
+1
-1
@@ -540,7 +540,7 @@ export const SETTINGS_SEARCH_ITEMS = [
540
id: "voice-microphone",
541
title: "Microphone",
542
to: "/settings/voice",
543
- searchTerms: ["mic input audio device"],
543
+ searchTerms: ["mic input audio device order priority preferred"],
544
},
545
{
546
id: "dictation-shortcut-mode",
apps/web/src/speech/browserMicrophones.ts
+43
-5
@@ -1,11 +1,49 @@
1
+import {
2
+ getClientSettings,
3
+ isClientSettingsHydrated,
4
+ updateClientSettings,
5
+} from "../hooks/useSettings";
6
+import {
7
+ type MicrophoneEntry,
8
+ microphoneOrder,
9
+ preferredMicrophoneId,
10
+ rememberMicrophones,
11
+} from "./microphoneOrder";
12
+
13
export type BrowserMicrophone = Pick<MediaDeviceInfo, "deviceId" | "label">;
14
3
-export async function listBrowserMicrophones(): Promise<BrowserMicrophone[]> {
15
+/** Audio inputs as the browser reports them. Labels stay empty until microphone permission. */
16
+export async function listAudioInputs(): Promise<BrowserMicrophone[]> {
17
const devices = await navigator.mediaDevices.enumerateDevices();
18
return devices
19
.filter((device) => device.kind === "audioinput")
7
- .map(({ deviceId, label }, index) => ({
8
- deviceId,
9
- label: label || `Microphone ${index + 1}`,
10
- }));
20
+ .map(({ deviceId, label }) => ({ deviceId, label }));
21
+}
22
+
23
+export async function listBrowserMicrophones(): Promise<BrowserMicrophone[]> {
24
+ return (await listAudioInputs()).map(({ deviceId, label }, index) => ({
25
+ deviceId,
26
+ label: label || `Microphone ${index + 1}`,
27
+ }));
28
+}
29
+
30
+/** Applies a change to the saved order. Skipped before hydration so defaults never replace a saved order. */
31
+export function updateMicrophoneOrder(
32
+ change: (order: ReadonlyArray<MicrophoneEntry>) => ReadonlyArray<MicrophoneEntry>,
33
+): ReadonlyArray<MicrophoneEntry> {
34
+ const known = microphoneOrder(getClientSettings());
35
+ if (!isClientSettingsHydrated()) return known;
36
+ const next = change(known);
37
+ if (next !== known) void updateClientSettings({ voiceMicrophones: [...next] });
38
+ return next;
39
+}
40
+
41
+/** Remembers newly seen microphones and returns the device id to record from, empty for System default. */
42
+export async function chooseRecordingMicrophone(): Promise<string> {
43
+ // Rejects where the browser has no media devices, such as plain HTTP.
44
+ const devices = await listAudioInputs().catch(() => []);
45
+ return preferredMicrophoneId(
46
+ updateMicrophoneOrder((order) => rememberMicrophones(order, devices)),
47
+ devices,
48
+ );
49
}
apps/web/src/speech/browserPcmCapture.browser.test.ts
+29
-5
@@ -1,21 +1,30 @@
1
import { expect, it, vi } from "vite-plus/test";
2
-import { createBrowserPcmCapture } from "./browserPcmCapture";
2
+import { createBrowserPcmCapture, openMicrophone } from "./browserPcmCapture";
3
4
-it("cancels an unanswered permission prompt and stops a late microphone stream", async () => {
4
+it("records from the chosen microphone, cancels an unanswered prompt, and stops a late stream", async () => {
5
let grantPermission!: (media: MediaStream) => void;
6
const permission = new Promise<MediaStream>((resolve) => {
7
grantPermission = resolve;
8
});
9
using microphone = vi.spyOn(navigator.mediaDevices, "getUserMedia").mockReturnValue(permission);
10
const capture = createBrowserPcmCapture(
11
- { getMicrophoneId: () => "", onLevel: vi.fn(), onDurationLimit: vi.fn(), onError: vi.fn() },
11
+ {
12
+ getMicrophoneId: async () => "blue-yeti",
13
+ onLevel: vi.fn(),
14
+ onDurationLimit: vi.fn(),
15
+ onError: vi.fn(),
16
+ },
17
async () => ({ locale: "en", transcribe: async () => "" }),
18
);
19
const abort = new AbortController();
20
await capture.transcriber.prepare({ signal: abort.signal });
21
const rejected = vi.fn();
22
const preparing = capture.recorder.prepareToRecordAsync(abort.signal).catch(rejected);
18
- expect(microphone).toHaveBeenCalledOnce();
23
+ await vi.waitFor(() =>
24
+ expect(microphone).toHaveBeenCalledExactlyOnceWith({
25
+ audio: { deviceId: { exact: "blue-yeti" } },
26
+ }),
27
+ );
28
abort.abort();
29
const stop = vi.fn();
30
try {
@@ -24,5 +33,20 @@ it("cancels an unanswered permission prompt and stops a late microphone stream",
33
grantPermission({ getTracks: () => [{ stop }] } as unknown as MediaStream);
34
await preparing;
35
}
27
- expect(stop).toHaveBeenCalledOnce();
36
+ await vi.waitFor(() => expect(stop).toHaveBeenCalledOnce());
37
+});
38
+
39
+it("falls back to the system default when the saved microphone is gone, and reports other failures", async () => {
40
+ const media = {} as MediaStream;
41
+ using microphone = vi
42
+ .spyOn(navigator.mediaDevices, "getUserMedia")
43
+ .mockRejectedValueOnce(new DOMException("gone", "OverconstrainedError"))
44
+ .mockResolvedValueOnce(media);
45
+ await expect(openMicrophone("blue-yeti")).resolves.toBe(media);
46
+ expect(microphone).toHaveBeenLastCalledWith({ audio: true });
47
+
48
+ const denied = new DOMException("denied", "NotAllowedError");
49
+ microphone.mockRejectedValueOnce(denied);
50
+ await expect(openMicrophone("blue-yeti")).rejects.toBe(denied);
51
+ expect(microphone).toHaveBeenCalledTimes(3);
52
});
apps/web/src/speech/browserPcmCapture.ts
+18
-5
@@ -10,9 +10,23 @@ type PreparedBrowserTranscription = PreparedVoiceTranscription & {
10
readonly streaming?: VoiceStreamingSession & { readonly feed: (pcm: Float32Array) => void };
11
};
12
13
+/** Opens a microphone. A saved device the browser can no longer find falls back to System default. */
14
+export async function openMicrophone(microphoneId: string): Promise<MediaStream> {
15
+ if (!microphoneId) return navigator.mediaDevices.getUserMedia({ audio: true });
16
+ try {
17
+ return await navigator.mediaDevices.getUserMedia({
18
+ audio: { deviceId: { exact: microphoneId } },
19
+ });
20
+ } catch (error) {
21
+ const name = typeof error === "object" && error !== null && "name" in error ? error.name : "";
22
+ if (name !== "OverconstrainedError" && name !== "NotFoundError") throw error;
23
+ return navigator.mediaDevices.getUserMedia({ audio: true });
24
+ }
25
+}
26
+
27
export function createBrowserPcmCapture(
28
input: {
15
- readonly getMicrophoneId: () => string;
29
+ readonly getMicrophoneId: () => string | Promise<string>;
30
readonly onLevel: (level: number) => void;
31
readonly onDurationLimit: () => void;
32
readonly onError: (message: string) => void;
@@ -59,12 +73,11 @@ export function createBrowserPcmCapture(
73
if (recordingUri) URL.revokeObjectURL(recordingUri);
74
recordingUri = null;
75
chunks = [];
62
- const microphoneId = input.getMicrophoneId();
76
+ const microphoneId = await input.getMicrophoneId();
77
+ captureSignal.throwIfAborted();
78
const captured = await new Promise<MediaStream>((resolve, reject) => {
79
const onAbort = () => reject(captureSignal.reason);
65
- const permission = navigator.mediaDevices.getUserMedia({
66
- audio: microphoneId ? { deviceId: { exact: microphoneId } } : true,
67
- });
80
+ const permission = openMicrophone(microphoneId);
81
captureSignal.addEventListener("abort", onAbort, { once: true });
82
void permission.then(
83
(media) => {
apps/web/src/speech/browserVoiceInput.ts
+1
-1
@@ -27,7 +27,7 @@ export function createBrowserVoiceInputPlatform(input: {
27
readonly cloudModel?: CloudSpeechModelId | undefined;
28
readonly hasAudioConsent: () => boolean;
29
readonly getTranscriptionOptions: () => SpeechTranscriptionOptions;
30
- readonly getMicrophoneId: () => string;
30
+ readonly getMicrophoneId: () => string | Promise<string>;
31
readonly onLevel: (level: number) => void;
32
readonly onDurationLimit: () => void;
33
readonly onText: (text: SpeechStreamText) => void;
apps/web/src/speech/microphoneOrder.ts
new
+128
@@ -0,0 +1,128 @@
1
+import type { ClientSettings, VoiceMicrophoneEntry } from "@t3tools/contracts";
2
+
3
+import type { BrowserMicrophone } from "./browserMicrophones";
4
+
5
+export type MicrophoneEntry = VoiceMicrophoneEntry;
6
+
7
+const SYSTEM_DEFAULT: MicrophoneEntry = { kind: "default" };
8
+
9
+// Chromium lists the current default and Windows communications device under these ids too.
10
+const ALIAS_DEVICE_IDS = new Set(["", "default", "communications"]);
11
+
12
+/** True for ids that stand for the system default, including the id-less input shown before permission. */
13
+export function isSystemDefaultDeviceId(deviceId: string): boolean {
14
+ return ALIAS_DEVICE_IDS.has(deviceId);
15
+}
16
+
17
+export function microphoneEntryKey(entry: MicrophoneEntry): string {
18
+ return entry.kind === "default" ? "default" : `device:${entry.deviceId}`;
19
+}
20
+
21
+/** The saved order with exactly one System default row; an empty order starts from the legacy choice. */
22
+export function microphoneOrder(
23
+ settings: Pick<ClientSettings, "voiceMicrophones" | "voiceMicrophone">,
24
+): ReadonlyArray<MicrophoneEntry> {
25
+ if (settings.voiceMicrophones.length === 0) {
26
+ return settings.voiceMicrophone
27
+ ? [{ kind: "device", deviceId: settings.voiceMicrophone, label: "" }, SYSTEM_DEFAULT]
28
+ : [SYSTEM_DEFAULT];
29
+ }
30
+ const keys = new Set<string>();
31
+ const order = settings.voiceMicrophones.filter((entry) => {
32
+ const key = microphoneEntryKey(entry);
33
+ if (keys.has(key)) return false;
34
+ keys.add(key);
35
+ return true;
36
+ });
37
+ return keys.has("default") ? order : [...order, SYSTEM_DEFAULT];
38
+}
39
+
40
+/** Adds labelled devices seen for the first time directly below System default and refreshes labels. */
41
+export function rememberMicrophones(
42
+ order: ReadonlyArray<MicrophoneEntry>,
43
+ devices: ReadonlyArray<BrowserMicrophone>,
44
+): ReadonlyArray<MicrophoneEntry> {
45
+ let next: MicrophoneEntry[] | null = null;
46
+ let insertAt = order.findIndex((entry) => entry.kind === "default") + 1;
47
+ for (const device of devices) {
48
+ if (!device.label || ALIAS_DEVICE_IDS.has(device.deviceId)) continue;
49
+ const current: ReadonlyArray<MicrophoneEntry> = next ?? order;
50
+ const index = current.findIndex(
51
+ (entry) => entry.kind === "device" && entry.deviceId === device.deviceId,
52
+ );
53
+ const existing = current[index];
54
+ if (existing?.kind === "device" && existing.label === device.label) continue;
55
+ next ??= [...order];
56
+ const entry: MicrophoneEntry = {
57
+ kind: "device",
58
+ deviceId: device.deviceId,
59
+ label: device.label,
60
+ };
61
+ if (index !== -1) {
62
+ next[index] = entry;
63
+ continue;
64
+ }
65
+ next.splice(insertAt, 0, entry);
66
+ insertAt += 1;
67
+ }
68
+ return next ?? order;
69
+}
70
+
71
+/**
72
+ * The first entry that is connected right now. System default always is. Before microphone
73
+ * permission the browser hides device ids, so the first entry is used as it was saved.
74
+ */
75
+export function preferredMicrophone(
76
+ order: ReadonlyArray<MicrophoneEntry>,
77
+ devices: ReadonlyArray<BrowserMicrophone>,
78
+): MicrophoneEntry {
79
+ if (devices.every((device) => !device.deviceId)) return order[0] ?? SYSTEM_DEFAULT;
80
+ return (
81
+ order.find(
82
+ (entry) =>
83
+ entry.kind === "default" || devices.some((device) => device.deviceId === entry.deviceId),
84
+ ) ?? SYSTEM_DEFAULT
85
+ );
86
+}
87
+
88
+/** The `deviceId` to record from, or an empty string for System default. */
89
+export function preferredMicrophoneId(
90
+ order: ReadonlyArray<MicrophoneEntry>,
91
+ devices: ReadonlyArray<BrowserMicrophone>,
92
+): string {
93
+ const entry = preferredMicrophone(order, devices);
94
+ return entry.kind === "device" ? entry.deviceId : "";
95
+}
96
+
97
+export function moveMicrophone(
98
+ order: ReadonlyArray<MicrophoneEntry>,
99
+ key: string,
100
+ steps: number,
101
+): ReadonlyArray<MicrophoneEntry> {
102
+ const from = order.findIndex((entry) => microphoneEntryKey(entry) === key);
103
+ const to = Math.max(0, Math.min(order.length - 1, from + steps));
104
+ if (from === -1 || from === to) return order;
105
+ const next = [...order];
106
+ const [entry] = next.splice(from, 1);
107
+ if (!entry) return order;
108
+ next.splice(to, 0, entry);
109
+ return next;
110
+}
111
+
112
+/** Moves an entry to the top, adding it when it is not listed yet. */
113
+export function preferMicrophone(
114
+ order: ReadonlyArray<MicrophoneEntry>,
115
+ entry: MicrophoneEntry,
116
+): ReadonlyArray<MicrophoneEntry> {
117
+ const key = microphoneEntryKey(entry);
118
+ const existing = order.find((candidate) => microphoneEntryKey(candidate) === key);
119
+ return [existing ?? entry, ...order.filter((candidate) => microphoneEntryKey(candidate) !== key)];
120
+}
121
+
122
+/** Removes a named microphone. System default stays. */
123
+export function forgetMicrophone(
124
+ order: ReadonlyArray<MicrophoneEntry>,
125
+ key: string,
126
+): ReadonlyArray<MicrophoneEntry> {
127
+ return key === "default" ? order : order.filter((entry) => microphoneEntryKey(entry) !== key);
128
+}
apps/web/src/speech/useEnvironmentSpeechInput.browser.test.tsx
+2
@@ -91,6 +91,8 @@ vi.mock("../state/environments", () => ({
91
}));
92
vi.mock("../hooks/useSettings", () => ({
93
updateClientSettings: vi.fn(),
94
+ getClientSettings: () => ({ ...DEFAULT_CLIENT_SETTINGS, ...mocks.settings }),
95
+ isClientSettingsHydrated: () => true,
96
useClientSettingsHydrated: () => true,
97
useClientSettings: (selector?: (settings: Record<string, unknown>) => unknown) => {
98
const settings = { ...DEFAULT_CLIENT_SETTINGS, ...mocks.settings };
apps/web/src/speech/useEnvironmentSpeechInput.ts
+2
-1
@@ -37,6 +37,7 @@ import {
37
} from "../hooks/useSettings";
38
import { useEnvironment } from "../state/environments";
39
import { useEnvironmentScope, usePreparedConnection } from "../state/session";
40
+import { chooseRecordingMicrophone } from "./browserMicrophones";
41
import { createBrowserVoiceInputPlatform } from "./browserVoiceInput";
42
import { preferredSpeechLanguages } from "./preferredSpeechLanguages";
43
import { runEnvironmentSpeech } from "./runEnvironmentSpeech";
@@ -296,7 +297,7 @@ export function useEnvironmentSpeechInput(input: HookInput) {
297
speechSilenceFiltering: settings.speechSilenceFiltering,
298
};
299
},
299
- getMicrophoneId: () => latestRef.current.clientSettings.voiceMicrophone,
300
+ getMicrophoneId: chooseRecordingMicrophone,
301
onLevel: setLevel,
302
onDurationLimit: () => void controller.stop(),
303
onText: (text) => {
apps/web/src/speech/useTextFieldSpeech.tsx
+23
-22
@@ -75,35 +75,36 @@ export function TextFieldSpeechControls({
75
return (
76
<>
77
{speech.preview ? (
78
- <p role="status" className="w-full text-sm text-muted-foreground">
78
+ <p
79
+ role="status"
80
+ className="order-first max-h-24 w-full overflow-y-auto rounded-lg border border-border/60 bg-muted/30 px-2.5 py-1.5 text-sm break-words whitespace-pre-wrap"
81
+ >
82
{speech.preview.committed}
80
- <span className="opacity-70">{speech.preview.tentative}</span>
83
+ <span className="text-muted-foreground">{speech.preview.tentative}</span>
84
</p>
85
) : null}
83
- <div className="flex min-w-0 items-center gap-1">
84
- <ComposerSpeechRecordingPill
86
+ <ComposerSpeechRecordingPill
87
+ size="compact"
88
+ state={speech.state}
89
+ progress={null}
90
+ level={speech.level}
91
+ finishShortcutLabel={speech.shortcutLabel}
92
+ cancelShortcutLabel="Esc"
93
+ disabled={disabled}
94
+ onStart={() => void speech.start()}
95
+ onStop={() => void speech.stop()}
96
+ onCancel={speech.cancel}
97
+ onSkipPostProcessing={speech.skipPostProcessing}
98
+ />
99
+ {speech.available ? (
100
+ <ComposerSpeechButton
101
state={speech.state}
86
- progress={null}
87
- level={speech.level}
88
- finishShortcutLabel={speech.shortcutLabel}
89
- cancelShortcutLabel="Esc"
102
+ size="compact"
103
+ shortcutLabel={speech.shortcutLabel}
104
disabled={disabled}
105
onStart={() => void speech.start()}
92
- onStop={() => void speech.stop()}
93
- onCancel={speech.cancel}
94
- onSkipPostProcessing={speech.skipPostProcessing}
106
/>
96
- {speech.available ? (
97
- <ComposerSpeechButton
98
- state={speech.state}
99
- progress={null}
100
- shortcutLabel={speech.shortcutLabel}
101
- disabled={disabled}
102
- onStart={() => void speech.start()}
103
- onCancel={speech.cancel}
104
- />
105
- ) : null}
106
- </div>
107
+ ) : null}
108
<VoiceInputSetup
109
environmentId={speech.transcriptionEnvironmentId}
110
open={speech.setup.open}
docs/user/voice-input.md
+8
-5
@@ -142,12 +142,15 @@ the model hears the cue as a dictionary hint.
142
143
## Test and troubleshoot
144
145
-In **Settings → Voice**, **Test microphone** beside the microphone selector
146
-records up to ten seconds and plays it back in your browser;
147
-the audio stays on this device and is never transcribed, so silent playback
145
+In **Settings → Voice**, voice input uses the first connected microphone in the
146
+**Microphone** list. A microphone joins the list below System default the first
147
+time it is seen, so nothing changes until you move it up. If a preferred
148
+microphone is unplugged, the next connected one is used.
149
+
150
+**Test microphone** records from that microphone for up to ten seconds and
151
+plays it back in your browser; the audio stays on this device and is never transcribed, so silent playback
152
points at the microphone. **Test model** on the selected model shows a transcript using the
153
same environment, language, and dictionary as the composer, but skips transcript
154
cleanup even when it is on, so you see what the model heard. Browser recording
155
needs HTTPS or localhost and microphone permission; for a remote server over
152
-plain HTTP, use the desktop app. If the selected microphone is missing, choose
153
-another or the system default.
156
+plain HTTP, use the desktop app.
packages/contracts/src/settings.ts
+12
-1
@@ -370,6 +370,12 @@ export type ModelPreferences = {
370
export const VoiceShortcutMode = Schema.Literals(["auto", "hold", "toggle"]);
371
export type VoiceShortcutMode = typeof VoiceShortcutMode.Type;
372
373
+export const VoiceMicrophoneEntry = Schema.Union([
374
+ Schema.Struct({ kind: Schema.Literal("default") }),
375
+ Schema.Struct({ kind: Schema.Literal("device"), deviceId: Schema.String, label: Schema.String }),
376
+]);
377
+export type VoiceMicrophoneEntry = typeof VoiceMicrophoneEntry.Type;
378
+
379
/**
380
* Where this device sends microphone audio. A cloud grant names the forwarding environment and
381
* the provider; an OpenRouter grant also names the exact model, since OpenRouter has no default.
@@ -548,8 +554,12 @@ export const ClientSettingsSchema = Schema.Struct({
554
timestampFormat: TimestampFormat.pipe(
555
Schema.withDecodingDefault(Effect.succeed(DEFAULT_TIMESTAMP_FORMAT)),
556
),
551
- // Device-local input device id. An empty string follows the operating system default.
557
+ // Superseded by voiceMicrophones; read only to seed an empty order.
558
voiceMicrophone: Schema.String.pipe(Schema.withDecodingDefault(Effect.succeed(""))),
559
+ // Device-local microphone order. Recording uses the first connected entry.
560
+ voiceMicrophones: Schema.Array(VoiceMicrophoneEntry).pipe(
561
+ Schema.withDecodingDefault(Effect.succeed([])),
562
+ ),
563
voiceShortcutMode: VoiceShortcutMode.pipe(Schema.withDecodingDefault(Effect.succeed("auto"))),
564
speechLanguage: SpeechLanguage.pipe(Schema.withDecodingDefault(Effect.succeed("auto"))),
565
speechTranslateToEnglish: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
@@ -2050,6 +2060,7 @@ export const ClientSettingsPatch = Schema.Struct({
2060
sidebarThreadSortOrder: Schema.optionalKey(SidebarThreadSortOrder),
2061
timestampFormat: Schema.optionalKey(TimestampFormat),
2062
voiceMicrophone: Schema.optionalKey(Schema.String),
2063
+ voiceMicrophones: Schema.optionalKey(Schema.Array(VoiceMicrophoneEntry)),
2064
voiceShortcutMode: Schema.optionalKey(VoiceShortcutMode),
2065
speechLanguage: Schema.optionalKey(SpeechLanguage),
2066
speechTranslateToEnglish: Schema.optionalKey(Schema.Boolean),