Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

feat(realtime): speaker/output dropdown completes rt-8 device picker (rt-8, Realtime Michael P1)

Chaitanya Giri67aa11b71de6
diff --git a/src/renderer/src/components/SettingsModal.tsx b/src/renderer/src/components/SettingsModal.tsx
index 1182c6e8..c27a44c2 100644
--- a/src/renderer/src/components/SettingsModal.tsx
+++ b/src/renderer/src/components/SettingsModal.tsx
@@ -1201,8 +1201,8 @@ export function SettingsModal({ config, onClose }: SettingsModalProps) {
Voice chat with Michael
</span>
<span style={{ fontSize: 12, lineHeight: '16px', color: 'var(--cth-ink-500)' }}>
- Talk to the orchestrator in real time. Toggle it on from Michael's tab; pick which
- microphone the voice loop uses here.
+ Talk to the orchestrator in real time. Toggle it on from Michael's tab; choose which
+ microphone and speaker the voice loop uses here.
</span>
</div>
<RealtimeDevicePicker />
diff --git a/src/renderer/src/realtime/DevicePicker.tsx b/src/renderer/src/realtime/DevicePicker.tsx
index 1008ed77..a576a3b0 100644
--- a/src/renderer/src/realtime/DevicePicker.tsx
+++ b/src/renderer/src/realtime/DevicePicker.tsx
@@ -1,38 +1,44 @@
/**
- * Realtime Michael — microphone device picker (card rt-8, Phase 1).
+ * Realtime Michael — microphone & speaker device picker (card rt-8, Phase 1).
*
- * Lets the user choose WHICH microphone the voice loop captures. The selection is
- * held in the realtime session store via `setDeviceId()` (see session.ts) and
- * applied on the next connect() — rt-2's getUserMedia passes it as
- * `{ deviceId: { exact } }`, falling back to the system default if it's stale.
+ * Lets the user choose WHICH microphone the voice loop captures and WHICH speaker
+ * it plays Michael's voice through. Selections are held in the realtime session
+ * store via `setDeviceId()` / `setOutputDeviceId()` (see session.ts): the mic is
+ * applied on the next connect() (getUserMedia `{ deviceId: { exact } }`), the
+ * speaker is applied immediately to the live `<audio>` sink via `setSinkId()` (and
+ * re-applied at connect). Both fall back to the system default if a stored id is
+ * stale.
*
* `enumerateDevices()` only returns device LABELS once the page has been granted
* mic access at least once (our main-process gate opens while a voice session or
* Free Flow is live — see src/main/index.ts). Before that we show generic
- * "Microphone N" names and a hint, so the picker is still usable cold.
- *
- * Speaker/output selection is a fast-follow: it needs the session to expose an
- * output setter that calls `audioEl.setSinkId()` (rt-2). Until that lands this
- * picker covers the input side, which is what getUserMedia consumes.
+ * "Microphone N" / "Speaker N" names and a hint, so the picker is usable cold.
*
* Branch feat/realtime-michael. See board.md "🎙 REALTIME MICHAEL".
*/
import { useCallback, useEffect, useState } from 'react';
import { useRealtimeMichael } from './session';
-interface AudioInput {
+interface AudioDevice {
deviceId: string;
label: string;
}
-/** Enumerate audio-input devices, with a generic fallback label when the real
- * label is hidden (no mic permission granted yet this session). */
-async function listMicrophones(): Promise<AudioInput[]> {
+/** Whether this runtime can route audio output to a chosen sink (Chromium/Electron
+ * expose HTMLMediaElement.setSinkId; some lib.dom targets don't). When false we
+ * hide the speaker picker rather than show an inert control. */
+const CAN_PICK_SPEAKER =
+ typeof HTMLMediaElement !== 'undefined' && 'setSinkId' in HTMLMediaElement.prototype;
+
+/** Enumerate audio devices of one kind, with a generic fallback label when the
+ * real label is hidden (no mic permission granted yet this session). */
+async function listDevices(kind: 'audioinput' | 'audiooutput'): Promise<AudioDevice[]> {
if (typeof navigator === 'undefined' || !navigator.mediaDevices?.enumerateDevices) return [];
+ const fallback = kind === 'audioinput' ? 'Microphone' : 'Speaker';
const devices = await navigator.mediaDevices.enumerateDevices();
return devices
- .filter((d) => d.kind === 'audioinput')
- .map((d, i) => ({ deviceId: d.deviceId, label: d.label || `Microphone ${i + 1}` }));
+ .filter((d) => d.kind === kind)
+ .map((d, i) => ({ deviceId: d.deviceId, label: d.label || `${fallback} ${i + 1}` }));
}
const labelStyle: React.CSSProperties = {
@@ -52,20 +58,25 @@ const selectStyle: React.CSSProperties = {
};
export function RealtimeDevicePicker(): React.ReactElement {
- const { deviceId, setDeviceId } = useRealtimeMichael();
- const [mics, setMics] = useState<AudioInput[]>([]);
+ const { deviceId, setDeviceId, outputDeviceId, setOutputDeviceId } = useRealtimeMichael();
+ const [mics, setMics] = useState<AudioDevice[]>([]);
+ const [speakers, setSpeakers] = useState<AudioDevice[]>([]);
/** True once at least one device exposes a real label ⇒ mic permission granted. */
const [labelled, setLabelled] = useState(false);
const refresh = useCallback(async () => {
- const list = await listMicrophones();
- setMics(list);
- setLabelled(list.some((m) => m.label && !/^Microphone \d+$/.test(m.label)));
+ const [ins, outs] = await Promise.all([
+ listDevices('audioinput'),
+ CAN_PICK_SPEAKER ? listDevices('audiooutput') : Promise.resolve<AudioDevice[]>([])
+ ]);
+ setMics(ins);
+ setSpeakers(outs);
+ setLabelled(ins.some((m) => m.label && !/^Microphone \d+$/.test(m.label)));
}, []);
useEffect(() => {
void refresh();
- // Hot-plug / unplug a mic, or a permission grant that reveals labels → re-list.
+ // Hot-plug / unplug a device, or a permission grant that reveals labels → re-list.
const md = typeof navigator !== 'undefined' ? navigator.mediaDevices : undefined;
if (!md) return;
const onChange = (): void => void refresh();
@@ -74,24 +85,45 @@ export function RealtimeDevicePicker(): React.ReactElement {
}, [refresh]);
return (
- <div style={{ display: 'flex', flexDirection: 'column', gap: 6, width: 280 }}>
- <span style={labelStyle}>Microphone</span>
- <select
- value={deviceId ?? ''}
- onChange={(e) => setDeviceId(e.target.value || null)}
- style={selectStyle}
- >
- <option value="">System default</option>
- {mics.map((m) => (
- <option key={m.deviceId} value={m.deviceId}>
- {m.label}
- </option>
- ))}
- </select>
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 12, width: 280 }}>
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
+ <span style={labelStyle}>Microphone</span>
+ <select
+ value={deviceId ?? ''}
+ onChange={(e) => setDeviceId(e.target.value || null)}
+ style={selectStyle}
+ >
+ <option value="">System default</option>
+ {mics.map((m) => (
+ <option key={m.deviceId} value={m.deviceId}>
+ {m.label}
+ </option>
+ ))}
+ </select>
+ </div>
+
+ {CAN_PICK_SPEAKER && (
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
+ <span style={labelStyle}>Speaker</span>
+ <select
+ value={outputDeviceId ?? ''}
+ onChange={(e) => setOutputDeviceId(e.target.value || null)}
+ style={selectStyle}
+ >
+ <option value="">System default</option>
+ {speakers.map((s) => (
+ <option key={s.deviceId} value={s.deviceId}>
+ {s.label}
+ </option>
+ ))}
+ </select>
+ </div>
+ )}
+
{!labelled && (
<span style={{ fontSize: 12, lineHeight: '16px', color: 'var(--cth-ink-500)' }}>
- Microphone names appear after you first start a voice session and grant mic access.
- The choice applies the next time Michael connects. Speaker selection is coming soon.
+ Device names appear after you first start a voice session and grant mic access.
+ The microphone choice applies the next time Michael connects; the speaker switches live.
</span>
)}
</div>