From f74a11fde8c505eda8c55c673b28bc101a269ab2 Mon Sep 17 00:00:00 2001 From: Christian Gick Date: Sun, 22 Feb 2026 11:15:46 +0200 Subject: [PATCH] fix(voice): separate aiohttp sessions for STT and TTS Sharing one session between ElevenLabs STT (WebSocket) and TTS (HTTP) can cause connection conflicts. Use dedicated sessions for each. Co-Authored-By: Claude Sonnet 4.6 --- voice.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/voice.py b/voice.py index 15a4f39..14efb71 100644 --- a/voice.py +++ b/voice.py @@ -113,6 +113,7 @@ class VoiceSession: self.session = None self._task = None self._http_session = None + self._stt_session = None self._caller_key: bytes | None = None self._caller_identity: str | None = None self._caller_all_keys: dict = {} # {index: bytes} — all caller keys by index @@ -196,7 +197,7 @@ class VoiceSession: self._task = asyncio.create_task(self._run()) async def stop(self): - for obj in [self.session, self.lk_room, self._http_session]: + for obj in [self.session, self.lk_room, self._http_session, self._stt_session]: if obj: try: if hasattr(obj, "aclose"): @@ -344,9 +345,10 @@ class VoiceSession: # Voice pipeline — George (British male, multilingual DE/EN) self._http_session = aiohttp.ClientSession() + self._stt_session = aiohttp.ClientSession() # separate session avoids WS/HTTP conflicts voice_id = os.environ.get("ELEVENLABS_VOICE_ID", DEFAULT_VOICE_ID) self.session = AgentSession( - stt=elevenlabs.STT(api_key=ELEVENLABS_KEY, http_session=self._http_session), + stt=elevenlabs.STT(api_key=ELEVENLABS_KEY, http_session=self._stt_session), llm=lk_openai.LLM(base_url=LITELLM_URL, api_key=LITELLM_KEY, model=self.model), tts=elevenlabs.TTS(voice_id=voice_id, model="eleven_multilingual_v2", api_key=ELEVENLABS_KEY, http_session=self._http_session),