sparse-artist-79061
11/03/2025, 5:46 PMtall-airline-16756
11/03/2025, 5:46 PMtall-airline-16756
11/03/2025, 5:46 PMDEEPGRAM_API_KEY is set in your environment — this is key to getting everything running smoothly.
2. Override the stt_node Method: In your custom agent, you’ll want to override the stt_node method. This is where you can add your own special touches like keyword detection or tweaking transcripts, all while leveraging Deepgram’s transcription capabilities.
3. Pass STT Instance to AgentSession: When you create an AgentSession, don’t forget to pass the Deepgram STT instance along. This step ensures transcription works seamlessly during your session.
If you’d like to dive deeper or explore more customization options, I highly recommend checking out the Deepgram Plugin Guide and the Custom STT Node Documentation. They have some great examples that can really help you tailor things to your needs.
Sources: docs/index.yaml | livekit-agents/livekit/agents/voice/agent.py | examples/src/cartersia_tts.ts | Speech-to-text (STT) models | LiveKit Docs | Deepgram STT plugin guide | LiveKit Docssparse-artist-79061
11/03/2025, 5:47 PMtall-airline-16756
11/03/2025, 5:47 PMfrom livekit.plugins.deepgram import STT
from livekit.agents import rtc
from livekit.agents.models import ModelSettings
import logging
logger = logging.getLogger(__name__)
class CustomAgent:
def __init__(self):
self.default_stt = STT()
async def stt_node(self, audio: rtc.AsyncIterable[rtc.AudioFrame], model_settings: ModelSettings):
# Use the default STT stream (Deepgram)
async for event in self.default_stt.stt_node(audio, model_settings):
if event.type == STT.SpeechEventType.FINAL_TRANSCRIPT:
transcript = event.alternatives[0].text.lower()
keywords = ["hello", "thanks", "bye"]
if any(keyword in transcript for keyword in keywords):
logger.info(f"Keyword detected: '{transcript}'")
yield event
# Example usage
async def main():
agent = CustomAgent()
# Pass audio and model settings to the stt_node method
# Example: await agent.stt_node(audio_stream, model_settings)
This snippet gently guides you through overriding the stt_node method to leverage Deepgram for transcription, while also adding a personal touch with keyword detection. When you're ready, just swap out the audio_stream and model_settings with your actual inputs. If you have any questions or want to explore this further, I'm here to help!sparse-artist-79061
11/05/2025, 9:04 AMtall-airline-16756
11/05/2025, 9:05 AMstt_node to post-process transcripts as they’re produced
• Use on_user_turn_completed to edit the final user message before it’s added to chat context
Below is a minimal Python example using Deepgram STT and filtering in both places (pick one).
from typing import AsyncIterable
from livekit.agents import Agent
from livekit.agents import rtc
from livekit.agents.types import ChatMessage, ChatContext, ModelSettings
from livekit.plugins.deepgram import STT
from livekit.plugins.openai import LLM, TTS
FILTER_WORDS = {"um", "uh", "like"} # example fillers
def _filter_text(text: str) -> str:
tokens = text.split()
return " ".join(t for t in tokens if t.lower() not in FILTER_WORDS)
class MyAgent(Agent):
def __init__(self):
super().__init__(stt=STT(), tts=TTS(), llm=LLM())
# Option A: Filter during STT streaming (affects what reaches the LLM)
async def stt_node(self, audio: AsyncIterable[rtc.AudioFrame], model_settings: ModelSettings):
async for evt in self.default.stt_node(audio, model_settings):
if hasattr(evt, "alternatives") and evt.alternatives:
alt = evt.alternatives[0]
alt.text = _filter_text(alt.text)
yield evt
# Option B: Filter once per user turn (right before LLM sees it)
async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatMessage):
if new_message.role == "user" and new_message.content:
new_message.content = _filter_text(new_message.content)
return await self.default.on_user_turn_completed(turn_ctx, new_message)
If you want the smallest change and clean, per-turn control, use on_user_turn_completed. If you need word-level cleanup as transcripts stream in, use stt_node.
For reference: see pipeline nodes and hooks in the docs: Pipeline nodes and hooks | LiveKit docs. Would you like a version that only uses one of these paths and includes your specific word list?
Sources: Pipeline nodes and hooks | LiveKit docs