From e807ade45dd402b322a2facef728fc1d9d3de259 Mon Sep 17 00:00:00 2001 From: Shane Date: Sat, 22 Aug 2026 08:24:42 -0400 Subject: [PATCH] fix: agent data_received handler + livekit config --- agent/agent.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/agent/agent.py b/agent/agent.py index ba614cd..4e98ac4 100644 --- a/agent/agent.py +++ b/agent/agent.py @@ -1,10 +1,11 @@ """ Voice Agent — real-time voice assistant. -Pipeline: Azure STT → Gemma LLM (xNAS, OpenAI-compatible) → Azure TTS (DragonHD) +Pipeline: Azure STT → Gemma LLM (xNAS, OpenAI-compatible) → Azure TTS Runs inside the single Docker container alongside LiveKit server and web frontend. """ +import json import logging import os import textwrap @@ -119,6 +120,9 @@ async def handle_job(ctx: JobContext) -> None: _active_session = session + # Listen for data messages (voice switching) from the web UI + ctx.room.on("data_received", _on_room_data) + await session.start( agent=VoiceAssistant(), room=ctx.room, @@ -138,13 +142,10 @@ async def handle_job(ctx: JobContext) -> None: # We listen on the room's data channel and update the TTS voice live. -@server.event("room.data_received") -async def on_room_data(ctx: JobContext, payload: bytes) -> None: +def _on_room_data(packet) -> None: """Handle data messages from the web UI (voice selection).""" - import json - try: - msg = json.loads(payload.decode("utf-8")) + msg = json.loads(packet.data.decode("utf-8")) except (json.JSONDecodeError, UnicodeDecodeError): return @@ -153,8 +154,7 @@ async def on_room_data(ctx: JobContext, payload: bytes) -> None: if voice and _active_session: logger.info("Switching TTS voice to %s", voice) try: - # AgentSession exposes the TTS; update its options - tts = _active_session._tts # internal, but stable in 1.7 + tts = _active_session.tts if hasattr(tts, "update_options"): tts.update_options(voice=voice) logger.info("Voice updated to %s", voice)