breezy-fish-3124
08/20/2025, 5:49 AMon_user_speech_transcribed callback from an Agent session.
session = AgentSession(
llm=realtime.RealtimeModel(
voice="alloy",
turn_detection=TurnDetection(
type="semantic_vad",
eagerness="low",
interrupt_response=False,
),
modalities=["text"],
),
tts=openai.TTS(voice="alloy"),
stt=speechmatics.STT(
language="en",
enable_diarization=True,
diarization_sensitivity=0.7, # Higher sensitivity
speaker_active_format="<{speaker_id}>{text}</{speaker_id}>", # XML format
prefer_current_speaker=False,
end_of_utterance_silence_trigger=0.5,
max_delay=1.0, # More time for diarization processing
enable_partials=True,
),
)
And then in my agent, I register for the transcript call back, but I don't see any speaker tags in the callback. the speaker id is always returning None.
async def on_enter(self) -> None:
self.session.on("user_input_transcribed", self.on_user_speech_transcribed)
def on_user_speech_transcribed(self, event: UserInputTranscribedEvent):
"""🎤 Primary handler for user speech with participant identification"""
try:
logger.info(f"📝 Transcript: {event.transcript}")
# Debug: log all available attributes on the event
logger.info(f"🔍 Event attributes: {dir(event)}")
# Extract speaker info if available
speaker_id = getattr(event, 'speaker_id', None)
# Debug: Log all speaker-related attributes
logger.info(f"🔍 speaker_id attribute: {speaker_id}")loud-beach-79426
08/20/2025, 5:55 AM@session.on("conversation_item_added")
def on_conversation_item_added(evt):
print("evt source conversation_item_added", repr(evt))
try:
item = getattr(evt, "item", None) or ""
if item:
role = getattr(item, "role", None) or ""
content = getattr(item, "content", None) or ""
print ("role: ", role)
print ("content: ", content[0])
except Exception:
passbreezy-fish-3124
08/20/2025, 7:54 AMbreezy-fish-3124
08/20/2025, 9:25 AM