Has anyone been able to get diarization to work wi...
# agents
b
Has anyone been able to get diarization to work with speechmatics? I've been following the README for the latest 1.2.6 version and I'm having no luck getting the speaker tag or speaker ids to show up in
on_user_speech_transcribed
callback from an Agent session.
Copy code
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.
Copy code
async def on_enter(self) -> None:
        self.session.on("user_input_transcribed", self.on_user_speech_transcribed)
Copy code
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}")
l
hi @breezy-fish-3124 it works for me when you use @session.on("conversation_item_added")
Copy code
@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:
            pass
b
Thank you @loud-beach-79426 ... The transcription works, and I can get the text. But I'm missing the speaker tags. I'm getting speaker tags as None
I started changing my model to a non-realtime openai model and the diarization started working with Speecmatic. strange, but I think i'll have to stick with not using the realtime models for now