3v324v23 commited on
Commit
b267db5
·
1 Parent(s): 1a02c03

Fix voice session modal closure stale state and echo interruption loops by muting mic during speaking status

Browse files
frontend/src/components/VoiceSessionModal.jsx CHANGED
@@ -6,6 +6,16 @@ export default function VoiceSessionModal({ isOpen, onClose, apiKey }) {
6
  const [errorMessage, setErrorMessage] = useState('');
7
  const [isMuted, setIsMuted] = useState(false);
8
 
 
 
 
 
 
 
 
 
 
 
9
  const wsRef = useRef(null);
10
  const audioContextRef = useRef(null);
11
  const playbackContextRef = useRef(null);
@@ -59,7 +69,8 @@ export default function VoiceSessionModal({ isOpen, onClose, apiKey }) {
59
  processorRef.current = processor;
60
 
61
  processor.onaudioprocess = (e) => {
62
- if (isMuted) return;
 
63
 
64
  const inputData = e.inputBuffer.getChannelData(0);
65
  // Convert Float32 to Int16 PCM
@@ -149,7 +160,7 @@ export default function VoiceSessionModal({ isOpen, onClose, apiKey }) {
149
  if (audioContextRef.current) audioContextRef.current.close();
150
  if (playbackContextRef.current) playbackContextRef.current.close();
151
  };
152
- }, [isOpen, isMuted]);
153
 
154
  if (!isOpen) return null;
155
 
 
6
  const [errorMessage, setErrorMessage] = useState('');
7
  const [isMuted, setIsMuted] = useState(false);
8
 
9
+ const statusRef = useRef(status);
10
+ useEffect(() => {
11
+ statusRef.current = status;
12
+ }, [status]);
13
+
14
+ const isMutedRef = useRef(isMuted);
15
+ useEffect(() => {
16
+ isMutedRef.current = isMuted;
17
+ }, [isMuted]);
18
+
19
  const wsRef = useRef(null);
20
  const audioContextRef = useRef(null);
21
  const playbackContextRef = useRef(null);
 
69
  processorRef.current = processor;
70
 
71
  processor.onaudioprocess = (e) => {
72
+ if (isMutedRef.current) return;
73
+ if (statusRef.current === 'speaking' || statusRef.current === 'connecting') return;
74
 
75
  const inputData = e.inputBuffer.getChannelData(0);
76
  // Convert Float32 to Int16 PCM
 
160
  if (audioContextRef.current) audioContextRef.current.close();
161
  if (playbackContextRef.current) playbackContextRef.current.close();
162
  };
163
+ }, [isOpen]);
164
 
165
  if (!isOpen) return null;
166