Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(ui): audio device pickers in Settings (voice output + microphone)

Ruben Lütke557d952be4ec
diff --git a/jarvis/ui/web/frontend/src/hooks/useAudioDevices.ts b/jarvis/ui/web/frontend/src/hooks/useAudioDevices.ts
new file mode 100644
index 0000000000..bbb31474ef
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/hooks/useAudioDevices.ts
@@ -0,0 +1,90 @@
+import { useCallback, useEffect, useState } from "react";
+
+/**
+ * Audio device pickers (Settings): which device Jarvis's voice plays on and
+ * which microphone it listens with. GET /api/settings/audio-devices lists one
+ * entry per physical device plus the current [audio] selection; PUT persists
+ * a device NAME (or the "auto-headset" sentinel for automatic selection) and
+ * live-applies it to the running voice pipeline. Mirrors useTtsVolume.
+ */
+export interface AudioDeviceEntry {
+ name: string;
+ is_default: boolean;
+}
+
+export interface AudioDevicesConfig {
+ available: boolean;
+ auto_value: string;
+ outputs: AudioDeviceEntry[];
+ inputs: AudioDeviceEntry[];
+ selected_output: string;
+ selected_input: string;
+}
+
+export interface AudioDeviceSaveResult {
+ ok: boolean;
+ selected_output: string;
+ selected_input: string;
+ persisted: boolean;
+ applied_live: boolean;
+ restart_required: boolean;
+}
+
+/** Loads /api/settings/audio-devices and exposes select() + refetch(). */
+export function useAudioDevices() {
+ const [config, setConfig] = useState<AudioDevicesConfig | null>(null);
+ const [loading, setLoading] = useState(true);
+ const [error, setError] = useState<string | null>(null);
+
+ const refetch = useCallback(async () => {
+ setError(null);
+ setLoading(true);
+ try {
+ const res = await fetch("/api/settings/audio-devices");
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
+ const data: AudioDevicesConfig = await res.json();
+ setConfig(data);
+ } catch (e) {
+ setError((e as Error).message);
+ } finally {
+ setLoading(false);
+ }
+ }, []);
+
+ useEffect(() => {
+ void refetch();
+ }, [refetch]);
+
+ const select = useCallback(
+ async (
+ kind: "output" | "input",
+ device: string,
+ ): Promise<AudioDeviceSaveResult> => {
+ const body =
+ kind === "output"
+ ? { output_device: device, persist: true }
+ : { input_device: device, persist: true };
+ const res = await fetch("/api/settings/audio-devices", {
+ method: "PUT",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(body),
+ });
+ const payload = await res.json().catch(() => ({}));
+ if (!res.ok) throw new Error(payload.detail ?? `HTTP ${res.status}`);
+ const result = payload as AudioDeviceSaveResult;
+ setConfig((prev) =>
+ prev
+ ? {
+ ...prev,
+ selected_output: result.selected_output,
+ selected_input: result.selected_input,
+ }
+ : prev,
+ );
+ return result;
+ },
+ [],
+ );
+
+ return { config, loading, error, refetch, select };
+}
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index f58ace7ab2..55f660c000 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -971,6 +971,19 @@
"saved_toast": "Lautstärke auf {0} gesetzt.",
"restart_caption": "Gespeichert — wird beim nächsten Start aktiv."
},
+ "audio_devices": {
+ "title": "Audiogeräte",
+ "description": "Lege fest, wo die Stimme von {name} herauskommt und mit welchem Mikrofon {name} zuhört. Automatisch wählt dein Headset für dich und passt sich an, wenn Geräte kommen und gehen.",
+ "output_label": "Sprachausgabe",
+ "input_label": "Mikrofon",
+ "auto_option": "Automatisch (empfohlen)",
+ "default_suffix": "(System-Standard)",
+ "rescan": "Geräte neu suchen",
+ "none_found": "Keine Audiogeräte auf diesem Rechner gefunden — {name} läuft ohne Ton weiter.",
+ "output_saved_toast": "Ausgabegerät gespeichert.",
+ "input_saved_toast": "Mikrofon gespeichert.",
+ "restart_caption": "Gespeichert — wird beim nächsten Start aktiv."
+ },
"title": "Einstellungen",
"subtitle": "Wake-Word, Hotkeys, Safety-Policies, Autostart.",
"overlay_taskbar_group_title": "Leiste & Overlay",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index 00c9fc3b49..8d59198803 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -972,6 +972,19 @@
"saved_toast": "Volume set to {0}.",
"restart_caption": "Saved — applies on next start."
},
+ "audio_devices": {
+ "title": "Audio devices",
+ "description": "Pick where {name}'s voice comes out and which microphone {name} listens with. Automatic picks your headset for you and adapts when devices come and go.",
+ "output_label": "Voice output",
+ "input_label": "Microphone",
+ "auto_option": "Automatic (recommended)",
+ "default_suffix": "(system default)",
+ "rescan": "Rescan devices",
+ "none_found": "No audio devices found on this machine — {name} keeps running without sound.",
+ "output_saved_toast": "Voice output device saved.",
+ "input_saved_toast": "Microphone saved.",
+ "restart_caption": "Saved — applies on next start."
+ },
"title": "Settings",
"subtitle": "Wake-word, hotkeys, safety policies, autostart.",
"overlay_taskbar_group_title": "Bar & Overlay",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index 24e9990659..349680c77a 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -971,6 +971,19 @@
"saved_toast": "Volumen fijado en {0}.",
"restart_caption": "Guardado — se aplica en el próximo inicio."
},
+ "audio_devices": {
+ "title": "Dispositivos de audio",
+ "description": "Elige por dónde sale la voz de {name} y con qué micrófono escucha {name}. Automático elige tu auricular por ti y se adapta cuando los dispositivos van y vienen.",
+ "output_label": "Salida de voz",
+ "input_label": "Micrófono",
+ "auto_option": "Automático (recomendado)",
+ "default_suffix": "(predeterminado del sistema)",
+ "rescan": "Volver a buscar dispositivos",
+ "none_found": "No se encontraron dispositivos de audio en este equipo — {name} sigue funcionando sin sonido.",
+ "output_saved_toast": "Dispositivo de salida guardado.",
+ "input_saved_toast": "Micrófono guardado.",
+ "restart_caption": "Guardado — se aplica en el próximo inicio."
+ },
"title": "Ajustes",
"subtitle": "Palabra de activación, atajos, políticas de seguridad, inicio automático.",
"overlay_taskbar_group_title": "Barra y superposición",
diff --git a/jarvis/ui/web/frontend/src/views/SettingsView.tsx b/jarvis/ui/web/frontend/src/views/SettingsView.tsx
index eb38c9a30e..f10b38c932 100644
--- a/jarvis/ui/web/frontend/src/views/SettingsView.tsx
+++ b/jarvis/ui/web/frontend/src/views/SettingsView.tsx
@@ -14,6 +14,7 @@ import { LanguagesGroup } from "@/views/settings/LanguagesGroup";
import { AppSettingsGroup } from "@/views/settings/AppSettingsGroup";
import { SilenceWindowGroup } from "@/views/settings/SilenceWindowGroup";
import { VolumeGroup } from "@/views/settings/VolumeGroup";
+import { AudioDevicesGroup } from "@/views/settings/AudioDevicesGroup";
import { SystemPromptGroup } from "@/views/settings/SystemPromptGroup";
import {
useWakeWord,
@@ -73,6 +74,7 @@ export function SettingsView() {
<WakeWordPanel />
<SilenceWindowGroup />
<VolumeGroup />
+ <AudioDevicesGroup />
<KeybindsPanel />
<ul className="mt-2 space-y-2">
diff --git a/jarvis/ui/web/frontend/src/views/settings/AudioDevicesGroup.test.tsx b/jarvis/ui/web/frontend/src/views/settings/AudioDevicesGroup.test.tsx
new file mode 100644
index 0000000000..6d5c09b71c
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/views/settings/AudioDevicesGroup.test.tsx
@@ -0,0 +1,132 @@
+import { fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { AudioDevicesGroup } from "./AudioDevicesGroup";
+
+// Mirrors GET /api/settings/audio-devices on a desktop with two outputs and
+// one microphone; the headset output is the persisted pick.
+const DESKTOP = {
+ available: true,
+ auto_value: "auto-headset",
+ outputs: [
+ { name: "Speakers (Realtek HD Audio)", is_default: true },
+ { name: "PRO X Gaming Headset", is_default: false },
+ ],
+ inputs: [{ name: "Microphone (PRO X)", is_default: true }],
+ selected_output: "PRO X Gaming Headset",
+ selected_input: "auto-headset",
+};
+
+// A headless host: no devices at all — the card degrades to a caption.
+const HEADLESS = {
+ available: false,
+ auto_value: "auto-headset",
+ outputs: [],
+ inputs: [],
+ selected_output: "auto-headset",
+ selected_input: "auto-headset",
+};
+
+afterEach(() => vi.restoreAllMocks());
+
+describe("AudioDevicesGroup", () => {
+ it("renders both pickers with the persisted selection", async () => {
+ vi.stubGlobal(
+ "fetch",
+ vi.fn().mockResolvedValue({ ok: true, json: async () => DESKTOP }),
+ );
+ render(<AudioDevicesGroup />);
+
+ expect(screen.getByText("Audio devices")).toBeTruthy();
+
+ await waitFor(() => {
+ const output = screen.getByTestId(
+ "audio-output-select",
+ ) as HTMLSelectElement;
+ expect(output.value).toBe("PRO X Gaming Headset");
+ const input = screen.getByTestId(
+ "audio-input-select",
+ ) as HTMLSelectElement;
+ expect(input.value).toBe("auto-headset");
+ });
+
+ // The OS default entry is labeled, the automatic option is first.
+ expect(screen.getByText(/Speakers \(Realtek HD Audio\)/)).toBeTruthy();
+ const autoOptions = screen.getAllByText("Automatic (recommended)");
+ expect(autoOptions.length).toBe(2);
+ });
+
+ it("PUTs the picked output device", async () => {
+ const fetchMock = vi
+ .fn()
+ // initial GET
+ .mockResolvedValueOnce({ ok: true, json: async () => DESKTOP })
+ // PUT after pick
+ .mockResolvedValueOnce({
+ ok: true,
+ json: async () => ({
+ ok: true,
+ selected_output: "Speakers (Realtek HD Audio)",
+ selected_input: "auto-headset",
+ persisted: true,
+ applied_live: true,
+ restart_required: false,
+ }),
+ });
+ vi.stubGlobal("fetch", fetchMock);
+ render(<AudioDevicesGroup />);
+
+ const output = (await waitFor(() =>
+ screen.getByTestId("audio-output-select"),
+ )) as HTMLSelectElement;
+ fireEvent.change(output, {
+ target: { value: "Speakers (Realtek HD Audio)" },
+ });
+
+ await waitFor(() => {
+ const putCall = fetchMock.mock.calls.find(
+ ([, opts]) => opts?.method === "PUT",
+ );
+ expect(putCall).toBeTruthy();
+ expect(putCall?.[0]).toBe("/api/settings/audio-devices");
+ expect(JSON.parse(putCall?.[1]?.body as string)).toMatchObject({
+ output_device: "Speakers (Realtek HD Audio)",
+ persist: true,
+ });
+ });
+ });
+
+ it("degrades to an honest caption on a headless host", async () => {
+ vi.stubGlobal(
+ "fetch",
+ vi.fn().mockResolvedValue({ ok: true, json: async () => HEADLESS }),
+ );
+ render(<AudioDevicesGroup />);
+
+ await waitFor(() =>
+ expect(screen.getByText(/No audio devices found/i)).toBeTruthy(),
+ );
+ expect(screen.queryByTestId("audio-output-select")).toBeNull();
+ expect(screen.queryByTestId("audio-input-select")).toBeNull();
+ });
+
+ it("keeps an unplugged persisted name visible as the selected value", async () => {
+ vi.stubGlobal(
+ "fetch",
+ vi.fn().mockResolvedValue({
+ ok: true,
+ json: async () => ({
+ ...DESKTOP,
+ selected_output: "Jabra Evolve2 65",
+ }),
+ }),
+ );
+ render(<AudioDevicesGroup />);
+
+ await waitFor(() => {
+ const output = screen.getByTestId(
+ "audio-output-select",
+ ) as HTMLSelectElement;
+ expect(output.value).toBe("Jabra Evolve2 65");
+ });
+ });
+});
diff --git a/jarvis/ui/web/frontend/src/views/settings/AudioDevicesGroup.tsx b/jarvis/ui/web/frontend/src/views/settings/AudioDevicesGroup.tsx
new file mode 100644
index 0000000000..94b9f147c1
--- /dev/null
+++ b/jarvis/ui/web/frontend/src/views/settings/AudioDevicesGroup.tsx
@@ -0,0 +1,168 @@
+import { useState } from "react";
+import { Headphones, Mic, RefreshCw, Volume2 } from "lucide-react";
+import {
+ useAudioDevices,
+ type AudioDeviceEntry,
+} from "@/hooks/useAudioDevices";
+import { useEventStore } from "@/store/events";
+import { useT } from "@/i18n";
+
+/**
+ * "Audio devices" card inside the Settings view: one dropdown for the OUTPUT
+ * device (where Jarvis's voice plays) and one for the MICROPHONE (what Jarvis
+ * listens with). The first option is always "Automatic (recommended)" — the
+ * auto-headset resolver; concrete entries are physical devices by display
+ * name (stable across reboots, unlike device indices). A pick saves
+ * immediately and applies live to the running voice pipeline; the rescan
+ * button re-enumerates after plugging in a headset. On a host without audio
+ * hardware the card degrades to a caption instead of empty dropdowns.
+ */
+export function AudioDevicesGroup() {
+ const t = useT();
+ const { config, loading, error, refetch, select } = useAudioDevices();
+ const pushToast = useEventStore((s) => s.pushToast);
+ const [saving, setSaving] = useState<"output" | "input" | null>(null);
+
+ async function onSelect(kind: "output" | "input", device: string) {
+ setSaving(kind);
+ try {
+ const res = await select(kind, device);
+ pushToast(
+ "success",
+ t(
+ kind === "output"
+ ? "settings_view.audio_devices.output_saved_toast"
+ : "settings_view.audio_devices.input_saved_toast",
+ ),
+ );
+ if (res.restart_required) {
+ pushToast("warning", t("settings_view.audio_devices.restart_caption"));
+ }
+ } catch (e) {
+ pushToast("error", (e as Error).message);
+ } finally {
+ setSaving(null);
+ }
+ }
+
+ const autoValue = config?.auto_value ?? "auto-headset";
+
+ return (
+ <div className="mt-2 rounded-lg border border-border bg-card/60 p-4">
+ <div className="flex items-start gap-3">
+ <Headphones className="mt-0.5 h-4 w-4 shrink-0 text-primary" />
+ <div className="min-w-0 flex-1">
+ <div className="flex items-center justify-between gap-4">
+ <h4 className="font-display text-sm font-semibold">
+ {t("settings_view.audio_devices.title")}
+ </h4>
+ <button
+ type="button"
+ onClick={() => void refetch()}
+ disabled={loading}
+ title={t("settings_view.audio_devices.rescan")}
+ aria-label={t("settings_view.audio_devices.rescan")}
+ className="text-muted-foreground hover:text-foreground disabled:opacity-50"
+ >
+ <RefreshCw
+ className={`h-3.5 w-3.5 ${loading ? "animate-spin" : ""}`}
+ />
+ </button>
+ </div>
+ <p className="mt-1 text-xs text-muted-foreground">
+ {t("settings_view.audio_devices.description")}
+ </p>
+
+ {error && <p className="mt-3 text-xs text-destructive">{error}</p>}
+
+ {config && !config.available ? (
+ <p className="mt-3 text-xs text-muted-foreground">
+ {t("settings_view.audio_devices.none_found")}
+ </p>
+ ) : (
+ <>
+ <DevicePicker
+ icon={<Volume2 className="h-3.5 w-3.5 text-primary" />}
+ label={t("settings_view.audio_devices.output_label")}
+ testId="audio-output-select"
+ devices={config?.outputs ?? []}
+ selected={config?.selected_output ?? autoValue}
+ autoValue={autoValue}
+ autoLabel={t("settings_view.audio_devices.auto_option")}
+ defaultSuffix={t("settings_view.audio_devices.default_suffix")}
+ disabled={loading || saving !== null}
+ onSelect={(device) => void onSelect("output", device)}
+ />
+ <DevicePicker
+ icon={<Mic className="h-3.5 w-3.5 text-primary" />}
+ label={t("settings_view.audio_devices.input_label")}
+ testId="audio-input-select"
+ devices={config?.inputs ?? []}
+ selected={config?.selected_input ?? autoValue}
+ autoValue={autoValue}
+ autoLabel={t("settings_view.audio_devices.auto_option")}
+ defaultSuffix={t("settings_view.audio_devices.default_suffix")}
+ disabled={loading || saving !== null}
+ onSelect={(device) => void onSelect("input", device)}
+ />
+ </>
+ )}
+ </div>
+ </div>
+ </div>
+ );
+}
+
+function DevicePicker({
+ icon,
+ label,
+ testId,
+ devices,
+ selected,
+ autoValue,
+ autoLabel,
+ defaultSuffix,
+ disabled,
+ onSelect,
+}: {
+ icon: React.ReactNode;
+ label: string;
+ testId: string;
+ devices: AudioDeviceEntry[];
+ selected: string;
+ autoValue: string;
+ autoLabel: string;
+ defaultSuffix: string;
+ disabled: boolean;
+ onSelect: (device: string) => void;
+}) {
+ // A persisted name whose device is currently unplugged still shows as the
+ // selected value (an extra option) so the UI never lies about the config;
+ // the backend resolver falls back to automatic until it reappears.
+ const known = devices.some((d) => d.name === selected);
+ const showOrphan = selected !== autoValue && !known;
+
+ return (
+ <>
+ <label className="mt-4 flex items-center gap-1.5 text-xs font-medium text-muted-foreground">
+ {icon}
+ {label}
+ </label>
+ <select
+ data-testid={testId}
+ value={selected}
+ onChange={(e) => onSelect(e.target.value)}
+ disabled={disabled}
+ className="mt-1 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-50"
+ >
+ <option value={autoValue}>{autoLabel}</option>
+ {devices.map((d) => (
+ <option key={d.name} value={d.name}>
+ {d.is_default ? `${d.name} ${defaultSuffix}` : d.name}
+ </option>
+ ))}
+ {showOrphan && <option value={selected}>{selected}</option>}
+ </select>
+ </>
+ );
+}