Is it possible to use stt diarization to create a ...
# ask-ai
c
Is it possible to use stt diarization to create a voice agent that handles well 2 users at the same time?
t
Thanks for reaching out, Guillaume. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're interested in LiveKit's STT diarization! It’s designed to help a voice agent manage conversations with two users by distinguishing between speakers in real time using speaker tags like <s1> and <s2>. It focuses on one active speaker at a time, prioritizing the most active or loudest speaker, so it doesn’t process overlapping speech from both users simultaneously. To get the best results, you can tweak settings such as diarization sensitivity and enable background voice cancellation, which really helps improve accuracy, especially in noisy environments. Also, letting the voice agent know about the speaker tag formats can make handling multi-user conversations smoother. If you’d like, I’m here to help guide you through configuring these settings to fit your specific needs. Just let me know! Sources: livekit-agents/livekit/agents/voice/agent_session.py | Enhanced noise cancellation | LiveKit docs | Speechmatics STT plugin guide | LiveKit Docs | Realtime model plugins | LiveKit Docs | pipeline-stt/diarization.py
c
Is there a code example somewhere?
t
I'm happy to share a code example for using LiveKit STT diarization with a voice agent. Here it is:
Copy code
from livekit.agents.voice import Agent
from livekit.plugins import speechmatics

class DiarizationAgent(Agent):
    def __init__(self):
        super().__init__(
            instructions="""
                You are a helpful assistant communicating through voice. Transcripts will come in with speaker IDs.
                Just have a natural conversation with the user. You can also help set names for different speakers.
            """,
            stt=speechmatics.STT(
                transcription_config=speechmatics.types.TranscriptionConfig(
                    operating_point="enhanced",
                    enable_partials=True,
                    language="en",
                    diarization="speaker",
                ),
                audio_settings=speechmatics.types.AudioSettings(
                    encoding="pcm_s16le",
                    sample_rate=16000,
                )
            )
        )

    async def on_enter(self):
        await self.session.say("Hi there! Is there anything I can help you with?")
This example shows how to set up the Speechmatics STT model with diarization in a LiveKit voice agent. By using the
diarization="speaker"
setting, it can detect and label different speakers during a conversation, making interactions clearer and more natural. If you'd like, I’m here to walk you through any part of this or help you implement it in your project. Just let me know how I can assist! Sources: docs/index.yaml | livekit-plugins/livekit-plugins-speechmatics/README.md
c
Will speaker diarization be consistent across user turn?
t
I'm glad you're exploring speaker diarization in LiveKit! When you use the Speechmatics STT plugin with diarization enabled, it’s designed to keep speaker IDs consistent across the conversation, assigning unique IDs like S1, S2 that stick with each speaker. These IDs show up in your transcription outputs, and you can even customize them to make things clearer for your needs. To help make the diarization even more consistent, you have a couple of handy options to configure: • `prefer_current_speaker`: This helps reduce the switching between speakers who sound alike, making the flow smoother. • `diarization_sensitivity`: You can tweak this to find the right balance between telling speakers apart and keeping things stable. Also, when people talk over each other, the system focuses on the primary speaker and gently suppresses background voices to keep things clear. If you'd like, I’d be happy to walk you through setting these up to fit your specific use case. Just let me know! Sources: Speechmatics STT plugin guide | LiveKit Docs | livekit-agents/livekit/agents/voice/audio_recognition.py | docs/index.yaml | Events and error handling | LiveKit docs
c
TranscriptionConfig and AudioSettings are deprecated?
t
Hi there! I wanted to let you know that both
TranscriptionConfig
and
AudioSettings
are now deprecated in LiveKit's Speechmatics STT integration. Instead, it's best to use individual parameters directly in the STT constructor, like these: •
operating_point
•
language
•
enable_partials
•
enable_diarization
•
sample_rate
•
audio_encoding
These older configurations still work for now to keep things running smoothly, but moving to the new method will really help keep your setup up-to-date and ready for the future. If you'd like, I’m here to help you update your code—just let me know! Sources: livekit-plugins/livekit-plugins-speechmatics/livekit/plugins/speechmatics/s...