From b3d5dcd94e22a529bfc1e3ca29a0fd5660c03533 Mon Sep 17 00:00:00 2001 From: Sergei Date: Wed, 28 Jan 2026 19:50:44 -0800 Subject: [PATCH] Stop voice session when changing API type Changes: - Add stopSession and isActive from VoiceContext to Profile - Stop active voice session before saving new API type - Prevents mid-session API type changes Now when user switches between voice_ask and ask_wellnuo_ai in Profile settings, any active voice session will be stopped automatically. --- app/(tabs)/profile.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/(tabs)/profile.tsx b/app/(tabs)/profile.tsx index fedcf2b..bcb0164 100644 --- a/app/(tabs)/profile.tsx +++ b/app/(tabs)/profile.tsx @@ -56,7 +56,7 @@ function MenuItem({ export default function ProfileScreen() { const { user, logout } = useAuth(); - const { updateVoiceApiType } = useVoice(); + const { updateVoiceApiType, stopSession, isActive } = useVoice(); const [deploymentId, setDeploymentId] = useState(''); const [deploymentName, setDeploymentName] = useState(''); const [showDeploymentModal, setShowDeploymentModal] = useState(false); @@ -150,11 +150,17 @@ export default function ProfileScreen() { }, [tempDeploymentId]); const saveVoiceApiType = useCallback(async () => { + // Stop active voice session if any before changing API type + if (isActive) { + console.log('[Profile] Stopping active voice session before API type change'); + stopSession(); + } + await api.setVoiceApiType(tempVoiceApiType); setVoiceApiType(tempVoiceApiType); updateVoiceApiType(tempVoiceApiType); setShowVoiceApiModal(false); - }, [tempVoiceApiType, updateVoiceApiType]); + }, [tempVoiceApiType, updateVoiceApiType, isActive, stopSession]); const openTerms = () => { router.push('/terms');