jolly-eve-3916
08/09/2025, 6:20 AMtall-airline-16756
08/09/2025, 6:20 AMtall-airline-16756
08/09/2025, 6:21 AMstt_node
method in your Agent class. This way, you can preprocess the STT output and tag each speaker nicely. Here’s a friendly walkthrough:
• Enable Speaker Diarization: Make sure your STT setup supports speaker diarization so you get those speaker IDs.
• Override the stt_node
Method: Use this to handle each transcript event and add the speaker’s name or ID right before the text.
• Map Speaker IDs to Names: Keep a mapping of speaker IDs to names in session.userdata
so you can customize it however you like.
Here’s a handy example to get you started:
from livekit.agents.voice import Agent
from livekit.plugins import speechmatics
class YourAgent(Agent):
def __init__(self):
super().__init__(
stt=speechmatics.STT(
transcription_config=speechmatics.types.TranscriptionConfig(
diarization="speaker",
)
)
)
async def stt_node(self, text, model_settings=None):
async def process_transcript(transcript_stream):
async for event in transcript_stream:
if hasattr(event, 'type') and str(event.type) == "SpeechEventType.FINAL_TRANSCRIPT":
if event.alternatives and event.alternatives[0].speaker_id:
speaker_id = event.alternatives[0].speaker_id
speaker_name = self.session.userdata.speaker_names.get(speaker_id, speaker_id)
event.alternatives[0].text = f"[{speaker_name}] {event.alternatives[0].text}"
yield event
return process_transcript(super().stt_node(text, model_settings))
With this in place, the LLM will get transcripts that look like this:
[Albert] I think we should talk about...
[Dad] I disagree because...
If you have any questions or want to dive deeper, just let me know—I’m here to help! Sources: Speechmatics STT integration guide | LiveKit Docs | pipeline-llm/transcription_node.py