Repository navigation
fix(websocket-demo): resolve Firefox audio stream hang and prevent AudioContext leaks - #29
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the audio handling in AudioStreamer and AudioPlayer to suspend and resume the AudioContext instead of closing and recreating it, and adds cleanup for the audio player on disconnect. The review feedback highlights several potential resource leaks and race conditions: (1) a concurrent initialization race condition in AudioPlayer that can leak contexts, (2) an AudioContext leak in AudioStreamer upon reconnection because suspended contexts are never closed, and (3) a potential leak if AudioStreamer.start() is called while already active, overwriting this.audioSource without disconnecting the previous stream.
|
Ah nice one, thanks @regeter . Could you take a look at the comments from gemini-code-assist and incorporate suggestions? Thanks! |
|
Done |
This PR fixes two issues in the
gemini-live-ephemeral-tokens-websocketexample:[Microphone off]) in Firefox caused the model to stop responding to subsequent text inputs. This occurred because abruptly closing theAudioContextwhile media tracks were active terminated the audio stream in an unclean state. The Gemini server's Voice Activity Detection (VAD) was left waiting for the stream to finish, keeping the turn open. Any subsequent text was appended to this open turn, preventing a response.AudioStreamerto suspend/resume a singleAudioContextinstead of closing and recreating it, allowing the stream to pause cleanly.AudioContextfrom theAudioPlayerevery time.AudioPlayerand close its context on disconnect.Proof of the Issue (Unresponsive text after Mic Off)
As shown below, text messages sent after turning the microphone off received no response. Once the microphone was turned back on and activated, the server finally committed the turn and responded to the queued text query.