fix: agent data_received handler + livekit config
This commit is contained in:
+8
-8
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user