Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(voice-controls): handle missing audio context on resume

Steven Enamakelf736b1a60782
diff --git a/app/src/features/human/RealtimeVoiceControls.tsx b/app/src/features/human/RealtimeVoiceControls.tsx
index 2a965de2a5..497e7932aa 100644
--- a/app/src/features/human/RealtimeVoiceControls.tsx
+++ b/app/src/features/human/RealtimeVoiceControls.tsx
@@ -1,4 +1,5 @@
import { ConversationProvider } from '@elevenlabs/react';
+import { LuMic, LuSquare } from 'react-icons/lu';
import { type RefObject, useEffect } from 'react';
import Button from '../../components/ui/Button';
@@ -17,9 +18,11 @@ import { useRealtimeVoiceSession } from './voice/useRealtimeVoiceSession';
function RealtimeVoiceControlsInner({
audioRef,
onSpeakingChange,
+ appearance = 'button',
}: {
audioRef?: RefObject<RealtimeVoiceAudio>;
onSpeakingChange?: (speaking: boolean) => void;
+ appearance?: RealtimeVoiceAppearance;
}) {
const { t } = useT();
const voiceId = useAppSelector(selectEffectiveMascotVoiceId);
@@ -73,15 +76,37 @@ function RealtimeVoiceControlsInner({
: t('voice.mode.listening')
: null;
+ const toggle = () => (active ? session.stop() : void session.start());
+
return (
<div className="flex flex-col items-center gap-2" data-testid="realtime-voice-controls">
- <Button
- analyticsId="human-realtime-voice-toggle"
- disabled={connecting}
- aria-label={label}
- onClick={() => (active ? session.stop() : void session.start())}>
- {label}
- </Button>
+ {appearance === 'icon' ? (
+ // The Human stage's single affordance: one circular mic that starts the
+ // session and becomes a stop square while it runs. Same handler and
+ // same `label` as the text button, so the accessible name still says
+ // which of start/stop/connecting this press does.
+ <Button
+ iconOnly
+ variant={active ? 'secondary' : 'primary'}
+ analyticsId="human-realtime-voice-toggle"
+ data-testid="human-voice-toggle"
+ disabled={connecting}
+ aria-pressed={active}
+ aria-label={label}
+ title={label}
+ className="size-14 rounded-full shadow-float"
+ onClick={toggle}>
+ {active ? <LuSquare className="size-5 fill-current" /> : <LuMic className="size-6" />}
+ </Button>
+ ) : (
+ <Button
+ analyticsId="human-realtime-voice-toggle"
+ disabled={connecting}
+ aria-label={label}
+ onClick={toggle}>
+ {label}
+ </Button>
+ )}
{status && <span className="text-xs text-content-muted">{status}</span>}
{session.error && (
<span className="text-xs text-red-600 dark:text-red-300" role="alert">
@@ -92,18 +117,35 @@ function RealtimeVoiceControlsInner({
);
}
+/**
+ * How the toggle presents itself.
+ *
+ * - `button` — the labelled text button, for surfaces that sit in a row of
+ * other controls.
+ * - `icon` — a circular mic (stop square while running), for the Human stage
+ * where it is the only control on the page.
+ */
+export type RealtimeVoiceAppearance = 'button' | 'icon';
+
export default function RealtimeVoiceControls({
audioRef,
onSpeakingChange,
+ appearance,
}: {
/** Optional sink for the mascot's lip-sync signal (see RealtimeVoiceAudio). */
audioRef?: RefObject<RealtimeVoiceAudio>;
/** Notified with the agent's speaking edge so the page can gate the loop. */
onSpeakingChange?: (speaking: boolean) => void;
+ /** Presentation of the start/stop toggle. Defaults to the labelled button. */
+ appearance?: RealtimeVoiceAppearance;
}) {
return (
<ConversationProvider>
- <RealtimeVoiceControlsInner audioRef={audioRef} onSpeakingChange={onSpeakingChange} />
+ <RealtimeVoiceControlsInner
+ audioRef={audioRef}
+ onSpeakingChange={onSpeakingChange}
+ appearance={appearance}
+ />
</ConversationProvider>
);
}