Auto-restart STT after TTS finishes speaking

Adds logic to detect when voice status transitions from 'speaking' to
'listening' and automatically restarts the speech recognition. This
enables continuous voice conversation flow - after Julia speaks her
response, the app immediately starts listening for the next user input.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Sergei 2026-01-27 16:43:53 -08:00
parent 45f2b676e0
commit 5efd696ef2

View File

@ -122,6 +122,27 @@ export default function TabLayout() {
} }
}, [sttIsListening, startListening]); }, [sttIsListening, startListening]);
// Track previous status to detect transition from speaking to listening
const prevStatusRef = useRef<typeof status>('idle');
// Auto-restart STT when TTS finishes (status changes from 'speaking' to 'listening')
useEffect(() => {
const prevStatus = prevStatusRef.current;
prevStatusRef.current = status;
// When transitioning from speaking to listening, restart STT
if (prevStatus === 'speaking' && status === 'listening' && sessionActiveRef.current) {
console.log('[TabLayout] TTS finished - auto-restarting STT');
// Small delay to ensure TTS cleanup is complete
const timer = setTimeout(() => {
if (sessionActiveRef.current && !sttIsListening) {
startListening();
}
}, 200);
return () => clearTimeout(timer);
}
}, [status, sttIsListening, startListening]);
// Handle voice FAB press - toggle listening mode // Handle voice FAB press - toggle listening mode
const handleVoiceFABPress = useCallback(() => { const handleVoiceFABPress = useCallback(() => {
if (isListening) { if (isListening) {