brash-barista-66564
07/29/2025, 8:39 AMtall-airline-16756
07/29/2025, 8:39 AMtall-airline-16756
07/29/2025, 8:40 AMclass CustomTurnDetector:
def __init__(self, userdata: TurnTakingUserData = None):
self._model = MultilingualModel()
self.last_eou_probability = None
self.userdata = userdata
async def predict_end_of_turn(self, chat_ctx: llm.ChatContext) -> float:
probability = await self._model.predict_end_of_turn(chat_ctx)
self.last_eou_probability = probability
# Send to frontend via RPC
await self._send_eou_to_frontend(probability)
return probability
2. RPC Communication for Real-time Updates:
• Send EOU updates to a frontend using RPC. Example:
await room.local_participant.perform_rpc(
destination_identity=client_participant.identity,
method="client.eou_update",
payload=json.dumps({
"eou_probability": probability,
"percentage": probability * 100
})
)
• The frontend can register an RPC handler to receive these updates:
const handleEouUpdateRpc = async (rpcInvocation) => {
const payload = JSON.parse(rpcInvocation.payload);
if (payload && typeof payload.percentage === 'number') {
setEouProbability(payload.percentage);
}
};
room.localParticipant.registerRpcMethod("client.eou_update", handleEouUpdateRpc);
3. Turn Detection Model Confidence Scores:
• The turn detection models return probability scores directly from their predict_end_of_turn method. These scores can be logged or sent to a frontend for debugging.
4. Metrics Access:
• Metrics like eou.end_of_utterance_delay are available through the telemetry system. These include:
◦ `ATTR_EOU_PROBABILITY`: The end-of-turn probability
◦ `ATTR_EOU_DELAY`: The endpointing delay applied
◦ `ATTR_END_OF_UTTERANCE_DELAY`: Time from end of speech to turn completion
• These metrics are captured during EOU detection spans and can be accessed for debugging.
By combining these methods, you can monitor and debug EOU probabilities and turn detection decisions effectively in real-time.
Sources: livekit-agents/livekit/agents/telemetry/trace_types.py | Logs, metrics, and telemetry | LiveKit Docs | complex-agents/turn-taking/turn-taking-frontend/app/page.tsx