Merge pull request #4028 from inworld-ai/ian/close-on-turn-complete

fix(inworld): close context at end of turn instead of relying on idle timeout
This commit is contained in:
Filipi da Silva Fuchter
2026-03-24 12:07:51 -04:00
committed by GitHub
2 changed files with 11 additions and 4 deletions

View File

@@ -0,0 +1 @@
- Modeified `InworldTTSService` to close context at end of turn instead of relying on idle timeout

View File

@@ -791,14 +791,20 @@ class InworldTTSService(WebsocketTTSService):
self._cumulative_time = 0.0
self._generation_end_time = 0.0
async def on_turn_context_completed(self):
"""Close the server-side context at end of turn.
Sends close_context so contextClosed arrives immediately after the
last audio byte.
"""
ctx_id = self._turn_context_id
await super().on_turn_context_completed()
await self._close_context(ctx_id)
async def on_audio_context_interrupted(self, context_id: str):
"""Callback invoked when an audio context has been interrupted."""
await self._close_context(context_id)
async def on_audio_context_completed(self, context_id: str):
"""Callback invoked when an audio context has been completed."""
await self._close_context(context_id)
def _get_websocket(self):
"""Get the websocket for the Inworld WebSocket TTS service.