Skip to content

Commit e2cea12

Browse files
feat(mobile): choose the microphone order for voice input
Voice input recorded from whatever input iOS routed to, which is the car's or AirPods' Bluetooth microphone whenever one is connected. Settings → Microphone now lists Wired, Bluetooth, iPhone, and CarPlay in a draggable order; when recording starts, voice input selects the first connected input of the highest-ranked kind. The default ranks CarPlay below the iPhone microphone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 50647de commit e2cea12

14 files changed

Lines changed: 449 additions & 66 deletions

‎apps/mobile/src/Stack.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ import {
102102
import { ScheduledTaskEditorProvider } from "./features/settings/scheduled-task-editor";
103103
import { SettingsKeyboardRouteScreen } from "./features/settings/SettingsKeyboardRouteScreen";
104104
import { SettingsLegalRouteScreen } from "./features/settings/SettingsLegalRouteScreen";
105+
import { SettingsMicrophoneRouteScreen } from "./features/settings/SettingsMicrophoneRouteScreen";
105106
import {
106107
SettingsOpenSourceLicenseRouteScreen,
107108
SettingsOpenSourceLicensesRouteScreen,
@@ -310,6 +311,13 @@ const SettingsContentStack = createV5SheetStackNavigator({
310311
title: "Keyboard",
311312
},
312313
}),
314+
SettingsMicrophone: createNativeStackScreen({
315+
screen: SettingsMicrophoneRouteScreen,
316+
linking: "microphone",
317+
options: {
318+
title: "Microphone",
319+
},
320+
}),
313321
SettingsFollowUp: createNativeStackScreen({
314322
screen: SettingsFollowUpRouteScreen,
315323
linking: "follow-ups",

‎apps/mobile/src/components/AppSymbol.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import IconBolt from "@tabler/icons-react-native/IconBolt";
2828
import IconBox from "@tabler/icons-react-native/IconBox";
2929
import IconBrain from "@tabler/icons-react-native/IconBrain";
3030
import IconCamera from "@tabler/icons-react-native/IconCamera";
31+
import IconCar from "@tabler/icons-react-native/IconCar";
3132
import IconChartBar from "@tabler/icons-react-native/IconChartBar";
3233
import IconCheck from "@tabler/icons-react-native/IconCheck";
3334
import IconCloud from "@tabler/icons-react-native/IconCloud";
@@ -58,6 +59,7 @@ import IconFilter from "@tabler/icons-react-native/IconFilter";
5859
import IconFilterFilled from "@tabler/icons-react-native/IconFilterFilled";
5960
import IconFolder from "@tabler/icons-react-native/IconFolder";
6061
import IconFolderOpen from "@tabler/icons-react-native/IconFolderOpen";
62+
import IconHeadphones from "@tabler/icons-react-native/IconHeadphones";
6163
import IconFolderPlus from "@tabler/icons-react-native/IconFolderPlus";
6264
import IconGitBranch from "@tabler/icons-react-native/IconGitBranch";
6365
import IconGitMerge from "@tabler/icons-react-native/IconGitMerge";
@@ -83,6 +85,7 @@ import IconMoon from "@tabler/icons-react-native/IconMoon";
8385
import IconNetwork from "@tabler/icons-react-native/IconNetwork";
8486
import IconPalette from "@tabler/icons-react-native/IconPalette";
8587
import IconPencil from "@tabler/icons-react-native/IconPencil";
88+
import IconPlug from "@tabler/icons-react-native/IconPlug";
8689
import IconPhoto from "@tabler/icons-react-native/IconPhoto";
8790
import IconPin from "@tabler/icons-react-native/IconPin";
8891
import IconPinnedOff from "@tabler/icons-react-native/IconPinnedOff";
@@ -140,13 +143,16 @@ const ANDROID_ICON_BY_SF_SYMBOL = {
140143
"arrow.up.right.circle": IconArrowUpRightCircle,
141144
"arrow.uturn.backward": IconArrowBackUp,
142145
"arrow.uturn.forward": IconArrowForwardUp,
146+
airpods: IconHeadphones,
143147
archivebox: IconArchive,
144148
"archivebox.fill": IconArchive,
145149
"bell.badge": IconBellRinging,
146150
"bolt.circle": IconBolt,
147151
"bolt.horizontal.circle": IconBolt,
148152
brain: IconBrain,
153+
"cable.connector": IconPlug,
149154
camera: IconCamera,
155+
car: IconCar,
150156
"chart.bar.xaxis": IconChartBar,
151157
checkmark: IconCheck,
152158
"checkmark.circle": IconCircleCheck,
@@ -181,6 +187,7 @@ const ANDROID_ICON_BY_SF_SYMBOL = {
181187
house: IconHome,
182188
"info.circle": IconInfoCircle,
183189
internaldrive: IconDatabase,
190+
iphone: IconDeviceMobile,
184191
keyboard: IconKeyboard,
185192
laptopcomputer: IconDeviceLaptop,
186193
link: IconLink,

‎apps/mobile/src/features/settings/EnvironmentRoutesSection.tsx‎

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import { type EnvironmentId, sessionGrantsScope } from "@t3tools/contracts";
1313
import { AUTH_SCOPE_OPTIONS } from "@t3tools/shared/authScopeOptions";
1414
import { AsyncResult } from "effect/reactivity";
1515
import * as Option from "effect/Option";
16-
import { useEffect, useMemo, useRef, useState } from "react";
16+
import { useState } from "react";
1717
import { Alert, Platform, Pressable, View } from "react-native";
18-
import { Gesture, GestureDetector } from "react-native-gesture-handler";
1918
import Reanimated, { ReduceMotion, useAnimatedStyle, withTiming } from "react-native-reanimated";
2019

2120
import { type AppSymbolName, SymbolView } from "../../components/AppSymbol";
@@ -27,6 +26,7 @@ import { environmentSession } from "../../state/session";
2726
import { useAtomCommand } from "../../state/use-atom-command";
2827
import { connectionTone } from "../connection/connectionTone";
2928
import { SettingsActionRow } from "./components/SettingsActionRow";
29+
import { SettingsDragHandle } from "./components/SettingsDragHandle";
3030
import { SettingsSection } from "./components/SettingsSection";
3131

3232
const ICON_SIZE = Platform.OS === "android" ? 24 : 22;
@@ -324,7 +324,7 @@ function RouteRow(props: {
324324
</View>
325325
</View>
326326
{props.editing ? (
327-
<DragHandle
327+
<SettingsDragHandle
328328
title={label}
329329
canMoveUp={props.position > 1}
330330
canMoveDown={props.position < props.count}
@@ -337,62 +337,3 @@ function RouteRow(props: {
337337
</Reanimated.View>
338338
);
339339
}
340-
341-
/** Pan recognition wins over the settings scroll view only inside the handle. */
342-
function DragHandle(props: {
343-
readonly title: string;
344-
readonly canMoveUp: boolean;
345-
readonly canMoveDown: boolean;
346-
readonly onStart: () => void;
347-
readonly onMove: (translation: number) => void;
348-
readonly onEnd: (translation: number, cancelled: boolean) => void;
349-
readonly onStep: (direction: "up" | "down") => void;
350-
}) {
351-
const latest = useRef(props);
352-
useEffect(() => {
353-
latest.current = props;
354-
});
355-
const translation = useRef(0);
356-
const gesture = useMemo(
357-
() =>
358-
Gesture.Pan()
359-
.minDistance(0)
360-
.shouldCancelWhenOutside(false)
361-
.runOnJS(true)
362-
.onStart(() => {
363-
translation.current = 0;
364-
latest.current.onStart();
365-
})
366-
.onUpdate((event) => {
367-
translation.current = event.translationY;
368-
latest.current.onMove(event.translationY);
369-
})
370-
.onFinalize((_, success) => latest.current.onEnd(translation.current, !success)),
371-
[],
372-
);
373-
return (
374-
<GestureDetector gesture={gesture}>
375-
<View
376-
collapsable={false}
377-
accessible
378-
accessibilityRole="adjustable"
379-
accessibilityLabel={`Reorder ${props.title}`}
380-
accessibilityActions={[
381-
...(props.canMoveUp ? [{ name: "decrement", label: "Move up" }] : []),
382-
...(props.canMoveDown ? [{ name: "increment", label: "Move down" }] : []),
383-
]}
384-
onAccessibilityAction={({ nativeEvent }) => {
385-
if (nativeEvent.actionName === "decrement" && props.canMoveUp) props.onStep("up");
386-
if (nativeEvent.actionName === "increment" && props.canMoveDown) props.onStep("down");
387-
}}
388-
style={{ width: 48, alignSelf: "stretch", alignItems: "center", justifyContent: "center" }}
389-
>
390-
<SymbolView
391-
name="line.3.horizontal"
392-
size={20}
393-
tintColorClassName="accent-foreground-muted"
394-
/>
395-
</View>
396-
</GestureDetector>
397-
);
398-
}
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
import { useAtomSet, useAtomValue } from "@effect/atom-react";
2+
import { AsyncResult } from "effect/reactivity";
3+
import { useState } from "react";
4+
import { ScrollView, View } from "react-native";
5+
import Reanimated, { ReduceMotion, useAnimatedStyle, withTiming } from "react-native-reanimated";
6+
import { useSafeAreaInsets } from "react-native-safe-area-context";
7+
8+
import { type AppSymbolName, SymbolView } from "../../components/AppSymbol";
9+
import { AppText as Text } from "../../components/AppText";
10+
import { cn } from "../../lib/cn";
11+
import { type MicrophoneKind, resolveMicrophonePriority } from "../../lib/microphonePriority";
12+
import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
13+
import { SettingsDragHandle } from "./components/SettingsDragHandle";
14+
import { SettingsSection } from "./components/SettingsSection";
15+
16+
const MICROPHONES: Record<
17+
MicrophoneKind,
18+
{ readonly label: string; readonly description: string; readonly icon: AppSymbolName }
19+
> = {
20+
wired: {
21+
label: "Wired",
22+
description: "Headsets and USB microphones",
23+
icon: "cable.connector",
24+
},
25+
bluetooth: {
26+
label: "Bluetooth",
27+
description: "AirPods, headsets, and cars without CarPlay",
28+
icon: "airpods",
29+
},
30+
builtIn: {
31+
label: "iPhone",
32+
description: "The microphone on this device",
33+
icon: "iphone",
34+
},
35+
carPlay: {
36+
label: "CarPlay",
37+
description: "The car’s microphone",
38+
icon: "car",
39+
},
40+
};
41+
42+
/** Voice input records from the first connected microphone in this order. iOS only. */
43+
export function SettingsMicrophoneRouteScreen() {
44+
const insets = useSafeAreaInsets();
45+
const preferencesResult = useAtomValue(mobilePreferencesAtom);
46+
const savePreferences = useAtomSet(updateMobilePreferencesAtom);
47+
const ready = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting;
48+
const order = resolveMicrophonePriority(
49+
AsyncResult.isSuccess(preferencesResult) ? preferencesResult.value.microphonePriority : [],
50+
);
51+
const [drag, setDrag] = useState<{
52+
readonly kind: MicrophoneKind;
53+
readonly translation: number;
54+
} | null>(null);
55+
const [rowHeight, setRowHeight] = useState(0);
56+
// Each drop remounts the rows so the new order and the cleared offsets land in one frame.
57+
const [drops, setDrops] = useState(0);
58+
59+
const move = (from: number, to: number) => {
60+
if (to < 0 || to >= order.length || from === to) return;
61+
const next = [...order];
62+
const [moved] = next.splice(from, 1);
63+
next.splice(to, 0, moved!);
64+
savePreferences({ microphonePriority: next });
65+
};
66+
// A lifted row takes a neighbour's slot once it has moved past half of that row.
67+
const dropIndex = (from: number, translation: number) =>
68+
rowHeight === 0
69+
? from
70+
: Math.min(order.length - 1, Math.max(0, from + Math.round(translation / rowHeight)));
71+
72+
const dragFrom = drag === null ? -1 : order.indexOf(drag.kind);
73+
const dragTo = drag === null ? -1 : dropIndex(dragFrom, drag.translation);
74+
75+
return (
76+
<View collapsable={false} className="flex-1 bg-sheet">
77+
<ScrollView
78+
contentInsetAdjustmentBehavior="automatic"
79+
showsVerticalScrollIndicator={false}
80+
className="flex-1"
81+
contentContainerClassName="gap-3 px-5 pt-4"
82+
contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}
83+
>
84+
<SettingsSection title="Preferred order">
85+
{order.map((kind, index) => {
86+
const shift =
87+
dragFrom === -1 || index === dragFrom
88+
? 0
89+
: dragFrom < dragTo && index > dragFrom && index <= dragTo
90+
? -rowHeight
91+
: dragFrom > dragTo && index < dragFrom && index >= dragTo
92+
? rowHeight
93+
: 0;
94+
return (
95+
<MicrophoneRow
96+
key={`${kind}:${drops}`}
97+
kind={kind}
98+
position={index + 1}
99+
count={order.length}
100+
disabled={!ready}
101+
offset={index === dragFrom ? (drag?.translation ?? 0) : shift}
102+
lifted={index === dragFrom}
103+
onHeight={setRowHeight}
104+
onDragStart={() => setDrag({ kind, translation: 0 })}
105+
onDragMove={(translation) => setDrag({ kind, translation })}
106+
onDragEnd={(translation, cancelled) => {
107+
setDrag(null);
108+
setDrops((count) => count + 1);
109+
if (!cancelled) move(index, dropIndex(index, translation));
110+
}}
111+
onStep={(direction) => move(index, direction === "up" ? index - 1 : index + 1)}
112+
/>
113+
);
114+
})}
115+
</SettingsSection>
116+
<Text className="px-2 text-sm text-foreground-muted">
117+
Voice input records from the first connected microphone in this list. Drag to reorder.
118+
</Text>
119+
</ScrollView>
120+
</View>
121+
);
122+
}
123+
124+
function MicrophoneRow(props: {
125+
readonly kind: MicrophoneKind;
126+
readonly position: number;
127+
readonly count: number;
128+
readonly disabled: boolean;
129+
readonly offset: number;
130+
readonly lifted: boolean;
131+
readonly onHeight: (height: number) => void;
132+
readonly onDragStart: () => void;
133+
readonly onDragMove: (translation: number) => void;
134+
readonly onDragEnd: (translation: number, cancelled: boolean) => void;
135+
readonly onStep: (direction: "up" | "down") => void;
136+
}) {
137+
const { lifted, offset } = props;
138+
const microphone = MICROPHONES[props.kind];
139+
const style = useAnimatedStyle(() => ({
140+
transform: [
141+
{
142+
translateY: lifted
143+
? offset
144+
: withTiming(offset, { duration: 160, reduceMotion: ReduceMotion.System }),
145+
},
146+
],
147+
zIndex: lifted ? 1 : 0,
148+
}));
149+
return (
150+
<Reanimated.View
151+
style={style}
152+
onLayout={(event) => props.onHeight(event.nativeEvent.layout.height)}
153+
className={cn(
154+
"flex-row items-center gap-4 pl-4",
155+
props.position > 1 && !lifted && "border-t border-border-subtle",
156+
lifted && "bg-grouped-card shadow-md",
157+
)}
158+
>
159+
<View
160+
accessible
161+
accessibilityLabel={`${microphone.label}, ${microphone.description}, ${props.position} of ${props.count}`}
162+
className="min-w-0 flex-1 flex-row items-center gap-4 py-4"
163+
>
164+
<SymbolView
165+
name={microphone.icon}
166+
size={22}
167+
tintColorClassName="accent-icon"
168+
type="monochrome"
169+
weight="regular"
170+
/>
171+
<View className="min-w-0 flex-1 gap-0.5">
172+
<Text numberOfLines={1} className="text-lg text-foreground">
173+
{microphone.label}
174+
</Text>
175+
<Text numberOfLines={1} className="text-sm text-foreground-muted">
176+
{microphone.description}
177+
</Text>
178+
</View>
179+
</View>
180+
{props.disabled ? null : (
181+
<SettingsDragHandle
182+
title={microphone.label}
183+
canMoveUp={props.position > 1}
184+
canMoveDown={props.position < props.count}
185+
onStart={props.onDragStart}
186+
onMove={props.onDragMove}
187+
onEnd={props.onDragEnd}
188+
onStep={props.onStep}
189+
/>
190+
)}
191+
</Reanimated.View>
192+
);
193+
}

‎apps/mobile/src/features/settings/SettingsRouteScreen.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ function SettingsIndexSections() {
154154
<SettingsSection title="Interface">
155155
<SettingsRow icon="paintbrush" label="Appearance" target="SettingsAppearance" />
156156
{Platform.OS === "ios" ? (
157-
<SettingsRow icon="keyboard" label="Keyboard" target="SettingsKeyboard" />
157+
<>
158+
<SettingsRow icon="keyboard" label="Keyboard" target="SettingsKeyboard" />
159+
<SettingsRow icon="mic" label="Microphone" target="SettingsMicrophone" />
160+
</>
158161
) : null}
159162
</SettingsSection>
160163

0 commit comments

Comments
 (0)