fix: agent data_received handler + livekit config

This commit is contained in:
Shane
2026-08-22 08:24:42 -04:00
parent 18bbc75216
commit e807ade45d
+8 -8
View File
@@ -1,10 +1,11 @@
""" """
Voice Agent — real-time voice assistant. 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. Runs inside the single Docker container alongside LiveKit server and web frontend.
""" """
import json
import logging import logging
import os import os
import textwrap import textwrap
@@ -119,6 +120,9 @@ async def handle_job(ctx: JobContext) -> None:
_active_session = session _active_session = session
# Listen for data messages (voice switching) from the web UI
ctx.room.on("data_received", _on_room_data)
await session.start( await session.start(
agent=VoiceAssistant(), agent=VoiceAssistant(),
room=ctx.room, 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. # We listen on the room's data channel and update the TTS voice live.
@server.event("room.data_received") def _on_room_data(packet) -> None:
async def on_room_data(ctx: JobContext, payload: bytes) -> None:
"""Handle data messages from the web UI (voice selection).""" """Handle data messages from the web UI (voice selection)."""
import json
try: try:
msg = json.loads(payload.decode("utf-8")) msg = json.loads(packet.data.decode("utf-8"))
except (json.JSONDecodeError, UnicodeDecodeError): except (json.JSONDecodeError, UnicodeDecodeError):
return return
@@ -153,8 +154,7 @@ async def on_room_data(ctx: JobContext, payload: bytes) -> None:
if voice and _active_session: if voice and _active_session:
logger.info("Switching TTS voice to %s", voice) logger.info("Switching TTS voice to %s", voice)
try: try:
# AgentSession exposes the TTS; update its options tts = _active_session.tts
tts = _active_session._tts # internal, but stable in 1.7
if hasattr(tts, "update_options"): if hasattr(tts, "update_options"):
tts.update_options(voice=voice) tts.update_options(voice=voice)
logger.info("Voice updated to %s", voice) logger.info("Voice updated to %s", voice)