From 5efd696ef2d7cb8532dcd62a519492050a763758 Mon Sep 17 00:00:00 2001 From: Sergei Date: Tue, 27 Jan 2026 16:43:53 -0800 Subject: [PATCH] Auto-restart STT after TTS finishes speaking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app/(tabs)/_layout.tsx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/(tabs)/_layout.tsx b/app/(tabs)/_layout.tsx index fcf4c00..6e690e6 100644 --- a/app/(tabs)/_layout.tsx +++ b/app/(tabs)/_layout.tsx @@ -122,6 +122,27 @@ export default function TabLayout() { } }, [sttIsListening, startListening]); + // Track previous status to detect transition from speaking to listening + const prevStatusRef = useRef('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 const handleVoiceFABPress = useCallback(() => { if (isListening) {