Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

feat(voice): surface narration state in the side panel

Luis Ortiz62c973f8595c
diff --git a/src/ui/sidepanel/App.tsx b/src/ui/sidepanel/App.tsx
index c574f0f..ea11037 100644
--- a/src/ui/sidepanel/App.tsx
+++ b/src/ui/sidepanel/App.tsx
@@ -15,7 +15,8 @@ import {
} from '@/lib/browser-api';
import { logger } from '@/lib/logger';
import { sendMessage } from '@/lib/messaging';
-import { connectToBackground } from '@/lib/port';
+import { getVoiceStatus } from '@/lib/offscreen';
+import { connectToBackground, type PanelVoiceUpdate } from '@/lib/port';
import { Button } from '@/ui/components/ui/button';
import { Input } from '@/ui/components/ui/input';
import SettingsView from '@/ui/shared/SettingsView';
@@ -24,6 +25,7 @@ import GuideMeCompletion from './GuideMeCompletion';
import GuideMeView from './GuideMeView';
import LibraryView from './LibraryView';
import RecordingView from './RecordingView';
+import VoiceToast from './VoiceToast';
type View =
| { name: 'library' }
@@ -87,10 +89,22 @@ export default function App() {
const [_isRecording, setIsRecording] = useState(false);
const [view, setView] = useState<View>({ name: 'library' });
const [search, setSearch] = useState('');
+ const [voice, setVoice] = useState<PanelVoiceUpdate>({ type: 'VOICE_UPDATE', phase: 'idle' });
+ const [voiceStarted, setVoiceStarted] = useState(false);
useEffect(() => {
const disconnect = connectToBackground({
- onConnect: () => setIsAlive(true),
+ onConnect: () => {
+ setIsAlive(true);
+ if (import.meta.env.BROWSER === 'firefox') return;
+ getVoiceStatus()
+ .then((status) => {
+ if (!status?.transcribing) return;
+ setVoiceStarted(true);
+ setVoice({ type: 'VOICE_UPDATE', phase: 'transcribing' });
+ })
+ .catch(() => undefined);
+ },
onDisconnect: () => setIsAlive(false),
onStateUpdate: (update) => {
if (update.state === CaptureState.RECORDING) {
@@ -99,6 +113,10 @@ export default function App() {
setIsRecording(false);
}
},
+ onVoiceUpdate: (update) => {
+ if (update.phase !== 'idle') setVoiceStarted(true);
+ setVoice(update);
+ },
});
return disconnect;
@@ -167,114 +185,125 @@ export default function App() {
}
}, []);
- if (view.name === 'recording') {
- return <RecordingView guideId={view.guideId} onStop={handleStopRecording} />;
- }
+ function renderView() {
+ if (view.name === 'recording') {
+ return <RecordingView guideId={view.guideId} onStop={handleStopRecording} voice={voice} />;
+ }
- if (view.name === 'guideme') {
- return (
- <GuideMeView
- guideId={view.guideId}
- onExit={() => {
- sendMessage('guideMeCancel', undefined).catch(() => {});
- setView({ name: 'library' });
- }}
- onComplete={(id) => setView({ name: 'guideme-done', guideId: id })}
- />
- );
- }
+ if (view.name === 'guideme') {
+ return (
+ <GuideMeView
+ guideId={view.guideId}
+ onExit={() => {
+ sendMessage('guideMeCancel', undefined).catch(() => {});
+ setView({ name: 'library' });
+ }}
+ onComplete={(id) => setView({ name: 'guideme-done', guideId: id })}
+ />
+ );
+ }
- if (view.name === 'guideme-done') {
- return (
- <GuideMeCompletion
- guideId={view.guideId}
- onDone={() => setView({ name: 'library' })}
- onRunAgain={async (id) => {
- await sendMessage('startGuideMe', { guideId: id });
- setView({ name: 'guideme', guideId: id });
- }}
- />
- );
- }
+ if (view.name === 'guideme-done') {
+ return (
+ <GuideMeCompletion
+ guideId={view.guideId}
+ onDone={() => setView({ name: 'library' })}
+ onRunAgain={async (id) => {
+ await sendMessage('startGuideMe', { guideId: id });
+ setView({ name: 'guideme', guideId: id });
+ }}
+ />
+ );
+ }
- if (view.name === 'editor') {
- return (
- <GuideEditor
- guideId={view.guideId}
- onBack={() => setView({ name: 'library' })}
- onGuideMe={(id) => setView({ name: 'guideme', guideId: id })}
- />
- );
- }
+ if (view.name === 'editor') {
+ return (
+ <GuideEditor
+ guideId={view.guideId}
+ onBack={() => setView({ name: 'library' })}
+ onGuideMe={(id) => setView({ name: 'guideme', guideId: id })}
+ />
+ );
+ }
- if (view.name === 'settings') {
- return <SettingsView onBack={() => setView({ name: 'library' })} />;
- }
+ if (view.name === 'settings') {
+ return <SettingsView onBack={() => setView({ name: 'library' })} />;
+ }
- return (
- <div className="min-h-screen bg-card flex flex-col">
- {/* Header */}
- <div className="relative overflow-hidden px-6 pt-6 pb-7 bg-gradient-to-br from-violet to-violet-light">
- <div className="absolute -top-12 -right-8 w-44 h-44 rounded-full opacity-15 blur-[40px] bg-gradient-to-br from-lavender to-white" />
+ return (
+ <div className="min-h-screen bg-card flex flex-col">
+ {/* Header */}
+ <div className="relative overflow-hidden px-6 pt-6 pb-7 bg-gradient-to-br from-violet to-violet-light">
+ <div className="absolute -top-12 -right-8 w-44 h-44 rounded-full opacity-15 blur-[40px] bg-gradient-to-br from-lavender to-white" />
- <div className="relative flex items-center justify-between mb-6">
- <span className="text-[17px] font-bold tracking-tight text-foreground">{i18n.t('app.name')}</span>
- <div className="flex items-center gap-2">
- <span
- className={`text-[10px] font-medium px-2.5 py-0.5 rounded-full ${isAlive ? 'text-foreground bg-white/30' : 'text-deep/50 bg-white/15'}`}
- >
- {isAlive ? i18n.t('sidepanel.connected') : i18n.t('sidepanel.connecting')}
- </span>
- <button
- onClick={() => setView({ name: 'settings' })}
- className="w-7 h-7 rounded-lg flex items-center justify-center text-foreground/60 hover:text-foreground hover:bg-white/20 transition-colors"
- >
- <Settings size={15} />
- </button>
+ <div className="relative flex items-center justify-between mb-6">
+ <span className="text-[17px] font-bold tracking-tight text-foreground">{i18n.t('app.name')}</span>
+ <div className="flex items-center gap-2">
+ <span
+ className={`text-[10px] font-medium px-2.5 py-0.5 rounded-full ${isAlive ? 'text-foreground bg-white/30' : 'text-deep/50 bg-white/15'}`}
+ >
+ {isAlive ? i18n.t('sidepanel.connected') : i18n.t('sidepanel.connecting')}
+ </span>
+ <button
+ onClick={() => setView({ name: 'settings' })}
+ className="w-7 h-7 rounded-lg flex items-center justify-center text-foreground/60 hover:text-foreground hover:bg-white/20 transition-colors"
+ >
+ <Settings size={15} />
+ </button>
+ </div>
</div>
- </div>
- <div className="relative text-center mb-5">
- <div className="flex justify-center mb-2">
- <MascotIcon size={44} />
+ <div className="relative text-center mb-5">
+ <div className="flex justify-center mb-2">
+ <MascotIcon size={44} />
+ </div>
+ <h3 className="text-base font-medium text-foreground">{i18n.t('sidepanel.heroTitle')}</h3>
+ <p className="text-xs mt-1 text-violet-dark">{i18n.t('sidepanel.heroSubtitle')}</p>
</div>
- <h3 className="text-base font-medium text-foreground">{i18n.t('sidepanel.heroTitle')}</h3>
- <p className="text-xs mt-1 text-violet-dark">{i18n.t('sidepanel.heroSubtitle')}</p>
+
+ <Button
+ onClick={handleStartRecording}
+ disabled={!isAlive}
+ className="w-full py-3 px-4 h-auto rounded-lg font-semibold text-sm hover:-translate-y-px shadow-lg"
+ >
+ <Video size={18} />
+ {i18n.t('sidepanel.startCapture')}
+ </Button>
</div>
- <Button
- onClick={handleStartRecording}
- disabled={!isAlive}
- className="w-full py-3 px-4 h-auto rounded-lg font-semibold text-sm hover:-translate-y-px shadow-lg"
- >
- <Video size={18} />
- {i18n.t('sidepanel.startCapture')}
- </Button>
- </div>
+ {/* Body */}
+ <div className="flex-1 px-5 pt-5">
+ <div className="relative mb-5">
+ <Search size={15} className="absolute left-3.5 top-1/2 -translate-y-1/2 text-purple" />
+ <Input
+ type="text"
+ placeholder={i18n.t('sidepanel.searchPlaceholder')}
+ value={search}
+ onChange={(e) => setSearch(e.target.value)}
+ className="w-full pl-10 pr-3 rounded-xl border-border bg-card !text-[13px]"
+ />
+ </div>
+
+ <p className="text-[11px] font-semibold uppercase tracking-wider mb-2.5 text-muted-foreground">
+ {i18n.t('sidepanel.recentLabel')}
+ </p>
- {/* Body */}
- <div className="flex-1 px-5 pt-5">
- <div className="relative mb-5">
- <Search size={15} className="absolute left-3.5 top-1/2 -translate-y-1/2 text-purple" />
- <Input
- type="text"
- placeholder={i18n.t('sidepanel.searchPlaceholder')}
- value={search}
- onChange={(e) => setSearch(e.target.value)}
- className="w-full pl-10 pr-3 rounded-xl border-border bg-card !text-[13px]"
+ <LibraryView
+ onOpen={(guideId) => setView({ name: 'editor', guideId })}
+ isAlive={isAlive}
+ searchQuery={search}
/>
</div>
-
- <p className="text-[11px] font-semibold uppercase tracking-wider mb-2.5 text-muted-foreground">
- {i18n.t('sidepanel.recentLabel')}
- </p>
-
- <LibraryView
- onOpen={(guideId) => setView({ name: 'editor', guideId })}
- isAlive={isAlive}
- searchQuery={search}
- />
</div>
- </div>
+ );
+ }
+
+ return (
+ <>
+ {renderView()}
+ {import.meta.env.BROWSER !== 'firefox' && view.name !== 'recording' && (
+ <VoiceToast update={voice} confirmable={voiceStarted} onOpenSettings={() => setView({ name: 'settings' })} />
+ )}
+ </>
);
}
diff --git a/src/ui/sidepanel/MicMeter.tsx b/src/ui/sidepanel/MicMeter.tsx
new file mode 100644
index 0000000..2c8cc31
--- /dev/null
+++ b/src/ui/sidepanel/MicMeter.tsx
@@ -0,0 +1,84 @@
+import { useEffect, useRef, useState } from 'react';
+import { browser, i18n } from '#imports';
+import { isVoiceMessageFor, VOICE_SIDEPANEL_TARGET, type VoiceLevelEvent, VoiceMessage } from '@/lib/voice-messages';
+import {
+ LEVEL_STALE_MS,
+ MIC_BAR_MIN_SCALE,
+ MIC_BARS,
+ type MicActivity,
+ micActivity,
+ micActivityKey,
+ micBarScale,
+} from './voice-status';
+
+const SWEEP_MS = 300;
+
+export default function MicMeter() {
+ const bars = useRef<Array<HTMLSpanElement | null>>([]);
+ const levelAt = useRef<number | null>(null);
+ const speakingAt = useRef<number | null>(null);
+ const [activity, setActivity] = useState<MicActivity>('waiting');
+
+ useEffect(() => {
+ const paint = (level: number) => {
+ MIC_BARS.forEach((bar, index) => {
+ const node = bars.current[index];
+ if (node) node.style.transform = `scaleY(${micBarScale(level, bar.weight).toFixed(3)})`;
+ });
+ };
+
+ const settle = (now: number) => {
+ setActivity((previous) => {
+ const next = micActivity(levelAt.current, speakingAt.current, now);
+ return next === previous ? previous : next;
+ });
+ };
+
+ const listener = (message: unknown) => {
+ if (!isVoiceMessageFor(VOICE_SIDEPANEL_TARGET, message)) return;
+ const event = message as VoiceLevelEvent;
+ if (event.type !== VoiceMessage.VOICE_LEVEL) return;
+ const now = Date.now();
+ levelAt.current = now;
+ if (event.speaking) speakingAt.current = now;
+ paint(event.level);
+ settle(now);
+ };
+
+ browser.runtime.onMessage.addListener(listener);
+ const sweep = setInterval(() => {
+ const now = Date.now();
+ if (levelAt.current !== null && now - levelAt.current > LEVEL_STALE_MS) paint(0);
+ settle(now);
+ }, SWEEP_MS);
+
+ return () => {
+ browser.runtime.onMessage.removeListener(listener);
+ clearInterval(sweep);
+ };
+ }, []);
+
+ const speaking = activity === 'speaking';
+
+ return (
+ <div className="flex items-center gap-2" role="status" aria-live="polite">
+ <span className="flex items-center gap-[3px] h-4" aria-hidden="true">
+ {MIC_BARS.map((bar, index) => (
+ <span
+ key={bar.id}
+ ref={(node) => {
+ bars.current[index] = node;
+ }}
+ style={{ transform: `scaleY(${MIC_BAR_MIN_SCALE})` }}
+ className={`w-[3px] h-4 rounded-full origin-center transition-transform duration-300 ease-out motion-reduce:transition-none ${
+ speaking ? 'bg-accent' : 'bg-border'
+ }`}
+ />
+ ))}
+ </span>
+ <span className={`text-[11px] font-medium ${speaking ? 'text-accent' : 'text-muted-foreground'}`}>
+ {i18n.t(micActivityKey(activity))}
+ </span>
+ </div>
+ );
+}
diff --git a/src/ui/sidepanel/MicToggle.tsx b/src/ui/sidepanel/MicToggle.tsx
new file mode 100644
index 0000000..689bdb0
--- /dev/null
+++ b/src/ui/sidepanel/MicToggle.tsx
@@ -0,0 +1,56 @@
+import { Mic, MicOff } from 'lucide-react';
+import { useCallback } from 'react';
+import { i18n } from '#imports';
+import { getActiveTab, localStorage } from '@/lib/browser-api';
+import { abortVoiceCapture, openMicPermissionPage } from '@/lib/offscreen';
+
+interface MicToggleProps {
+ enabled: boolean;
+ live: boolean;
+ onChange: (enabled: boolean) => void;
+}
+
+const MICROPHONE: PermissionDescriptor = { name: 'microphone' as PermissionName };
+
+async function microphoneGranted(): Promise<boolean> {
+ try {
+ const status = await navigator.permissions.query(MICROPHONE);
+ return status.state === 'granted';
+ } catch {
+ return false;
+ }
+}
+
+export default function MicToggle({ enabled, live, onChange }: MicToggleProps) {
+ const toggle = useCallback(async () => {
+ const next = !enabled;
+ onChange(next);
+ await localStorage.set({ voiceEnabled: next });
+
+ if (!next) {
+ if (live) await abortVoiceCapture().catch(() => undefined);
+ return;
+ }
+
+ if (await microphoneGranted()) return;
+ const tab = await getActiveTab();
+ await openMicPermissionPage(tab?.id).catch(() => undefined);
+ }, [enabled, live, onChange]);
+
+ const Icon = enabled ? Mic : MicOff;
+
+ return (
+ <button
+ onClick={() => void toggle()}
+ aria-pressed={enabled}
+ className={`w-10 h-10 rounded-full border flex items-center justify-center transition-colors ${
+ enabled
+ ? 'border-accent bg-secondary text-accent'
+ : 'border-border text-muted-foreground hover:border-accent hover:text-accent'
+ }`}
+ title={i18n.t(enabled ? 'voice.turnOff' : 'voice.turnOn')}
+ >
+ <Icon size={16} />
+ </button>
+ );
+}
diff --git a/src/ui/sidepanel/RecordingView.tsx b/src/ui/sidepanel/RecordingView.tsx
index 1e118c1..b9f1afa 100644
--- a/src/ui/sidepanel/RecordingView.tsx
+++ b/src/ui/sidepanel/RecordingView.tsx
@@ -3,15 +3,19 @@ import { useCallback, useEffect, useRef, useState } from 'react';
import { i18n } from '#imports';
import { deleteStep, getScreenshotsForSteps, getStepsForGuide } from '@/core/guides/service';
import type { Screenshot, Step } from '@/core/guides/types';
-import { getActiveTab } from '@/lib/browser-api';
+import { getActiveTab, localStorage } from '@/lib/browser-api';
import { sendMessage } from '@/lib/messaging';
+import type { PanelVoiceUpdate } from '@/lib/port';
import { extractDomain } from '@/lib/utils';
import { Button } from '@/ui/components/ui/button';
+import MicToggle from './MicToggle';
+import VoiceStatus from './VoiceStatus';
import ZoomScreenshot from './ZoomScreenshot';
interface RecordingViewProps {
guideId: string;
onStop: () => void;
+ voice: PanelVoiceUpdate;
}
function timeAgo(createdAt: number): string {
@@ -26,10 +30,11 @@ interface LiveStep {
screenshot?: Screenshot;
}
-export default function RecordingView({ guideId, onStop }: RecordingViewProps) {
+export default function RecordingView({ guideId, onStop, voice }: RecordingViewProps) {
const [steps, setSteps] = useState<LiveStep[]>([]);
const [siteUrl, setSiteUrl] = useState('');
const [isBlurring, setIsBlurring] = useState(false);
+ const [voiceEnabled, setVoiceEnabled] = useState(false);
const [, setTick] = useState(0);
const bottomRef = useRef<HTMLDivElement>(null);
@@ -75,6 +80,11 @@ export default function RecordingView({ guideId, onStop }: RecordingViewProps) {
});
}, []);
+ useEffect(() => {
+ if (import.meta.env.BROWSER === 'firefox') return;
+ localStorage.get(['voiceEnabled']).then((stored) => setVoiceEnabled(stored.voiceEnabled === true));
+ }, []);
+
const handleBlur = useCallback(async () => {
await sendMessage('enterBlurMode', undefined);
setIsBlurring(true);
@@ -182,26 +192,32 @@ export default function RecordingView({ guideId, onStop }: RecordingViewProps) {
</div>
{/* Bottom bar */}
- <div className="shrink-0 border-t border-border px-4 py-2.5 flex items-center gap-2">
- <Button onClick={onStop} className="flex-1 h-10 rounded-full font-semibold text-[13px]">
- <Check size={16} strokeWidth={3} />
- {i18n.t('recording.finishRecording')}
- </Button>
- <button
- onClick={handleBlur}
- disabled={isBlurring}
- className="w-10 h-10 rounded-full border border-border flex items-center justify-center transition-colors text-muted-foreground hover:border-accent hover:text-accent disabled:opacity-50 disabled:cursor-not-allowed"
- title={i18n.t('recording.smartBlur')}
- >
- <EyeOff size={16} />
- </button>
- <button
- onClick={onStop}
- className="w-10 h-10 rounded-full border border-border flex items-center justify-center transition-colors text-purple hover:border-destructive/30 hover:text-destructive"
- title={i18n.t('recording.discard')}
- >
- <X size={16} />
- </button>
+ <div className="shrink-0 border-t border-border">
+ {import.meta.env.BROWSER !== 'firefox' && <VoiceStatus update={voice} enabled={voiceEnabled} />}
+ <div className="px-4 py-2.5 flex items-center gap-2">
+ <Button onClick={onStop} className="flex-1 h-10 rounded-full font-semibold text-[13px]">
+ <Check size={16} strokeWidth={3} />
+ {i18n.t('recording.finishRecording')}
+ </Button>
+ {import.meta.env.BROWSER !== 'firefox' && (
+ <MicToggle enabled={voiceEnabled} live={voice.phase === 'recording'} onChange={setVoiceEnabled} />
+ )}
+ <button
+ onClick={handleBlur}
+ disabled={isBlurring}
+ className="w-10 h-10 rounded-full border border-border flex items-center justify-center transition-colors text-muted-foreground hover:border-accent hover:text-accent disabled:opacity-50 disabled:cursor-not-allowed"
+ title={i18n.t('recording.smartBlur')}
+ >
+ <EyeOff size={16} />
+ </button>
+ <button
+ onClick={onStop}
+ className="w-10 h-10 rounded-full border border-border flex items-center justify-center transition-colors text-purple hover:border-destructive/30 hover:text-destructive"
+ title={i18n.t('recording.discard')}
+ >
+ <X size={16} />
+ </button>
+ </div>
</div>
</div>
);
diff --git a/src/ui/sidepanel/VoiceStatus.tsx b/src/ui/sidepanel/VoiceStatus.tsx
new file mode 100644
index 0000000..e68dc48
--- /dev/null
+++ b/src/ui/sidepanel/VoiceStatus.tsx
@@ -0,0 +1,40 @@
+import { TriangleAlert } from 'lucide-react';
+import { i18n } from '#imports';
+import type { PanelVoiceUpdate } from '@/lib/port';
+import MicMeter from './MicMeter';
+import { voiceErrorKey } from './voice-status';
+
+interface VoiceStatusProps {
+ update: PanelVoiceUpdate;
+ enabled: boolean;
+}
+
+export default function VoiceStatus({ update, enabled }: VoiceStatusProps) {
+ if (update.phase === 'error') {
+ return (
+ <div className="px-4 pt-2.5 flex items-start gap-2" role="status">
+ <TriangleAlert size={13} className="shrink-0 mt-0.5 text-destructive" />
+ <p className="text-[10px] leading-relaxed text-muted-foreground">
+ <span className="font-semibold text-foreground">{i18n.t(voiceErrorKey(update.reason))}</span>{' '}
+ {i18n.t('voice.guideSafe')}
+ </p>
+ </div>
+ );
+ }
+
+ if (update.phase === 'recording') {
+ return (
+ <div className="px-4 pt-2.5">
+ <MicMeter />
+ </div>
+ );
+ }
+
+ if (!enabled || update.phase !== 'idle') return null;
+
+ return (
+ <div className="px-4 pt-2.5" role="status">
+ <p className="text-[10px] leading-relaxed text-muted-foreground">{i18n.t('voice.nextRecording')}</p>
+ </div>
+ );
+}
diff --git a/src/ui/sidepanel/VoiceToast.tsx b/src/ui/sidepanel/VoiceToast.tsx
new file mode 100644
index 0000000..d71f5a0
--- /dev/null
+++ b/src/ui/sidepanel/VoiceToast.tsx
@@ -0,0 +1,84 @@
+import { Check, Loader2, TriangleAlert, X } from 'lucide-react';
+import { useEffect, useState } from 'react';
+import { i18n } from '#imports';
+import type { PanelVoiceUpdate } from '@/lib/port';
+import { narratedKey, voiceErrorKey } from './voice-status';
+
+const CONFIRM_MS = 7000;
+
+interface VoiceToastProps {
+ update: PanelVoiceUpdate;
+ confirmable: boolean;
+ onOpenSettings: () => void;
+}
+
+function signatureOf(update: PanelVoiceUpdate): string {
+ return `${update.phase}:${update.reason ?? ''}:${update.narrated ?? ''}`;
+}
+
+export default function VoiceToast({ update, confirmable, onOpenSettings }: VoiceToastProps) {
+ const [dismissed, setDismissed] = useState<string | null>(null);
+ const signature = signatureOf(update);
+ const confirming = update.phase === 'idle' && update.narrated !== undefined && confirmable;
+
+ useEffect(() => {
+ if (!confirming) return;
+ const timer = setTimeout(() => setDismissed(signature), CONFIRM_MS);
+ return () => clearTimeout(timer);
+ }, [confirming, signature]);
+
+ const visible = update.phase === 'transcribing' || update.phase === 'error' || confirming;
+ if (!visible || dismissed === signature) return null;
+
+ const narrated = update.narrated ?? 0;
+
+ return (
+ <div
+ role="status"
+ className="fixed bottom-3 left-1/2 -translate-x-1/2 z-50 w-[calc(100%-1.5rem)] max-w-sm rounded-xl border border-border bg-card shadow-lg px-3 py-2.5 flex items-start gap-2.5"
+ >
+ {update.phase === 'transcribing' && (
+ <Loader2 size={14} className="shrink-0 mt-0.5 text-accent animate-spin motion-reduce:animate-none" />
+ )}
+ {update.phase === 'error' && <TriangleAlert size={14} className="shrink-0 mt-0.5 text-destructive" />}
+ {confirming && <Check size={14} className="shrink-0 mt-0.5 text-success" />}
+
+ <div className="flex-1 min-w-0">
+ {update.phase === 'transcribing' && (
+ <>
+ <p className="text-[11px] font-semibold text-foreground">{i18n.t('voice.transcribing')}</p>
+ <p className="text-[10px] text-muted-foreground leading-relaxed">{i18n.t('voice.transcribingHint')}</p>
+ </>
+ )}
+
+ {update.phase === 'error' && (
+ <>
+ <p className="text-[11px] font-semibold text-foreground leading-relaxed">
+ {i18n.t(voiceErrorKey(update.reason))}
+ </p>
+ <p className="text-[10px] text-muted-foreground leading-relaxed">{i18n.t('voice.guideSafe')}</p>
+ {update.reason === 'missing-api-key' && (
+ <button onClick={onOpenSettings} className="mt-1.5 text-[10px] font-semibold text-accent hover:underline">
+ {i18n.t('voice.openSettings')}
+ </button>
+ )}
+ </>
+ )}
+
+ {confirming && (
+ <p className="text-[11px] font-semibold text-foreground">
+ {narrated === 0 ? i18n.t('voice.narratedNone') : i18n.t(narratedKey(narrated), [String(narrated)])}
+ </p>
+ )}
+ </div>
+
+ <button
+ onClick={() => setDismissed(signature)}
+ title={i18n.t('common.close')}
+ className="shrink-0 p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors"
+ >
+ <X size={13} />
+ </button>
+ </div>
+ );
+}
diff --git a/src/ui/sidepanel/__tests__/voice-status.test.ts b/src/ui/sidepanel/__tests__/voice-status.test.ts
new file mode 100644
index 0000000..920c492
--- /dev/null
+++ b/src/ui/sidepanel/__tests__/voice-status.test.ts
@@ -0,0 +1,128 @@
+import { readFileSync } from 'node:fs';
+import { join } from 'node:path';
+import { describe, expect, it } from 'vitest';
+import type { VoiceErrorReason } from '@/lib/voice-messages';
+import {
+ LEVEL_STALE_MS,
+ MIC_ACTIVITIES,
+ MIC_BAR_MIN_SCALE,
+ MIC_BARS,
+ micActivity,
+ micActivityKey,
+ micBarScale,
+ narratedKey,
+ SPEAKING_HOLD_MS,
+ voiceErrorKey,
+} from '../voice-status';
+
+const LOCALES = ['en', 'es', 'fr', 'pt-BR'];
+
+function voiceKeysIn(locale: string): string[] {
+ const lines = readFileSync(join(process.cwd(), 'src/locales', `${locale}.yml`), 'utf8').split('\n');
+ const start = lines.indexOf('voice:');
+ const keys: string[] = [];
+ for (const line of lines.slice(start + 1)) {
+ if (line.trim() === '') continue;
+ if (!line.startsWith(' ')) break;
+ const match = /^ {2}([\w-]+):/.exec(line);
+ if (match) keys.push(`voice.${match[1]}`);
+ }
+ return keys;
+}
+
+const ALL_REASONS: VoiceErrorReason[] = [
+ 'permission-denied',
+ 'no-device',
+ 'no-audio',
+ 'not-recording',
+ 'already-recording',
+ 'missing-api-key',
+ 'stream-ended',
+ 'unsupported',
+ 'unknown',
+];
+
+describe('voiceErrorKey', () => {
+ it('gives every reason its own message', () => {
+ const keys = ALL_REASONS.map(voiceErrorKey);
+ expect(new Set(keys).size).toBe(ALL_REASONS.length);
+ });
+
+ it('points a missing transcription key at settings', () => {
+ expect(voiceErrorKey('missing-api-key')).toBe('voice.errorMissingApiKey');
+ });
+
+ it('falls back to the unknown message for an absent or unrecognised reason', () => {
+ expect(voiceErrorKey(undefined)).toBe('voice.errorUnknown');
+ expect(voiceErrorKey('teleported-away' as VoiceErrorReason)).toBe('voice.errorUnknown');
+ });
+});
+
+describe('micActivity', () => {
+ it('waits until the first level arrives', () => {
+ expect(micActivity(null, null, 1000)).toBe('waiting');
+ });
+
+ it('reports speaking while the hold window is open', () => {
+ expect(micActivity(1000, 1000, 1000 + SPEAKING_HOLD_MS)).toBe('speaking');
+ });
+
+ it('falls back to quiet once the hold window closes', () => {
+ expect(micActivity(1000, 1000, 1000 + SPEAKING_HOLD_MS + 1)).toBe('quiet');
+ });
+
+ it('stays quiet when levels arrive but nothing is spoken', () => {
+ expect(micActivity(2000, null, 2000)).toBe('quiet');
+ });
+
+ it('holds through a pause shorter than the level feed interval', () => {
+ expect(SPEAKING_HOLD_MS).toBeLessThan(LEVEL_STALE_MS * 2);
+ });
+});
+
+describe('micBarScale', () => {
+ it('never collapses a bar to nothing and never overshoots', () => {
+ for (const bar of MIC_BARS) {
+ for (const level of [-1, 0, 0.5, 1, 2, Number.NaN]) {
+ const scale = micBarScale(level, bar.weight);
+ expect(scale).toBeGreaterThanOrEqual(MIC_BAR_MIN_SCALE);
+ expect(scale).toBeLessThanOrEqual(1);
+ }
+ }
+ });
+
+ it('grows with the level', () => {
+ expect(micBarScale(0.8, 1)).toBeGreaterThan(micBarScale(0.2, 1));
+ });
+
+ it('keeps the outer bars shorter than the centre one', () => {
+ expect(micBarScale(1, MIC_BARS[0].weight)).toBeLessThan(micBarScale(1, MIC_BARS[2].weight));
+ });
+});
+
+describe('narratedKey', () => {
+ it('distinguishes none, one and many', () => {
+ expect(narratedKey(0)).toBe('voice.narratedNone');
+ expect(narratedKey(1)).toBe('voice.narrated');
+ expect(narratedKey(4)).toBe('voice.narratedPlural');
+ });
+});
+
+describe('locale coverage', () => {
+ const emitted = [
+ ...ALL_REASONS.map(voiceErrorKey),
+ ...MIC_ACTIVITIES.map(micActivityKey),
+ ...[0, 1, 5].map(narratedKey),
+ ];
+
+ it('en defines every key the mappings can emit', () => {
+ const keys = voiceKeysIn('en');
+ for (const key of emitted) expect(keys).toContain(key);
+ });
+
+ it('every locale carries the same voice keys', () => {
+ const reference = voiceKeysIn('en');
+ expect(reference.length).toBeGreaterThan(0);
+ for (const locale of LOCALES) expect(voiceKeysIn(locale).sort()).toEqual([...reference].sort());
+ });
+});
diff --git a/src/ui/sidepanel/voice-status.ts b/src/ui/sidepanel/voice-status.ts
new file mode 100644
index 0000000..2974e37
--- /dev/null
+++ b/src/ui/sidepanel/voice-status.ts
@@ -0,0 +1,65 @@
+import type { VoiceErrorReason } from '@/lib/voice-messages';
+
+export const SPEAKING_HOLD_MS = 1200;
+export const LEVEL_STALE_MS = 1500;
+export const MIC_BAR_MIN_SCALE = 0.14;
+
+export interface MicBar {
+ id: string;
+ weight: number;
+}
+
+export const MIC_BARS: MicBar[] = [
+ { id: 'far-left', weight: 0.45 },
+ { id: 'left', weight: 0.75 },
+ { id: 'center', weight: 1 },
+ { id: 'right', weight: 0.75 },
+ { id: 'far-right', weight: 0.45 },
+];
+
+export type MicActivity = 'waiting' | 'speaking' | 'quiet';
+
+export const MIC_ACTIVITIES: MicActivity[] = ['waiting', 'speaking', 'quiet'];
+
+const MIC_ACTIVITY_KEYS: Record<MicActivity, string> = {
+ waiting: 'voice.micStarting',
+ speaking: 'voice.micHearing',
+ quiet: 'voice.micQuiet',
+};
+
+export function micActivityKey(activity: MicActivity): string {
+ return MIC_ACTIVITY_KEYS[activity];
+}
+
+export function micActivity(levelAt: number | null, speakingAt: number | null, now: number): MicActivity {
+ if (levelAt === null) return 'waiting';
+ if (speakingAt !== null && now - speakingAt <= SPEAKING_HOLD_MS) return 'speaking';
+ return 'quiet';
+}
+
+export function micBarScale(level: number, weight: number): number {
+ const bounded = Number.isFinite(level) ? Math.min(1, Math.max(0, level)) : 0;
+ return MIC_BAR_MIN_SCALE + (1 - MIC_BAR_MIN_SCALE) * bounded * weight;
+}
+
+const VOICE_ERROR_KEYS: Record<VoiceErrorReason, string> = {
+ 'permission-denied': 'voice.errorPermissionDenied',
+ 'no-device': 'voice.errorNoDevice',
+ 'no-audio': 'voice.errorNoAudio',
+ 'missing-api-key': 'voice.errorMissingApiKey',
+ 'stream-ended': 'voice.errorStreamEnded',
+ 'not-recording': 'voice.errorNotRecording',
+ 'already-recording': 'voice.errorAlreadyRecording',
+ unsupported: 'voice.errorUnsupported',
+ unknown: 'voice.errorUnknown',
+};
+
+export function voiceErrorKey(reason: VoiceErrorReason | undefined): string {
+ const key = reason === undefined ? undefined : VOICE_ERROR_KEYS[reason];
+ return key ?? VOICE_ERROR_KEYS.unknown;
+}
+
+export function narratedKey(narrated: number): string {
+ if (narrated <= 0) return 'voice.narratedNone';
+ return narrated === 1 ? 'voice.narrated' : 'voice.narratedPlural';
+}