limited-spring-14213
12/03/2025, 3:46 AMtall-airline-16756
12/03/2025, 3:46 AMtall-airline-16756
12/03/2025, 3:47 AMllm parameter on AgentSession or by overriding the agent's llm in your Agent class.
Examples:
1. Change session LLM:
from livekit.agents import AgentSession
session = AgentSession(
llm="openai/gpt-4.1-mini",
stt="assemblyai/universal-streaming:en",
tts="cartesia/sonic-3:..."
)
1. Override per-agent:
class MyAgent(Agent):
def __init__(self):
super().__init__(llm=openai.LLM(model="gpt-4o-mini"))
If your goal is to avoid dynamic LLM-generated responses, you can simulate “no LLM” behavior by intercepting or suppressing the LLM node (for example, implement an llm_node that returns nothing) or by using session.say() to send static replies — but the LLM will still be part of the session and this approach may break expected agent behaviors.
Would you like help switching to a specific model, or an example of suppressing LLM output in your agent code?
Sources: Models | LiveKit Docs | Large language models (LLM) | LiveKit Docs | Agents and handoffs | LiveKit docs | Agents (Node.js) | livekit/livekit_composite | DeepWikilimited-spring-14213
12/03/2025, 3:55 AMtall-airline-16756
12/03/2025, 3:56 AMlimited-spring-14213
12/03/2025, 3:56 AMtall-airline-16756
12/03/2025, 3:56 AMtrack. Example patterns:
1) In a track-subscribed event handler:
@room.on("track_subscribed")
def on_track_subscribed(track: rtc.Track, publication: rtc.RemoteTrackPublication, participant: rtc.RemoteParticipant):
if track.kind == rtc.TrackKind.KIND_AUDIO:
audio_track = track # rtc.Track (audio)
# Process audio frames with rtc.AudioStream
audio_stream = rtc.AudioStream(audio_track)
async def process():
async for frame in audio_stream:
# handle frame
pass
# schedule/process `process()` as appropriate
2) Pull the current subscribed audio track from a participant's publications:
from livekit import rtc
def get_audio_track(participant: rtc.RemoteParticipant):
for pub in participant.trackPublications.values():
if pub.kind == rtc.TrackKind.KIND_AUDIO and pub.subscribed and not pub.muted:
return pub.track # rtc.Track (audio) or None
return None
Notes:
• The track object is available only after subscription/negotiation.
• For frame-level processing use rtc.AudioStream(track) and iterate async for frames.limited-spring-14213
12/03/2025, 3:59 AMtall-airline-16756
12/03/2025, 3:59 AMkind (audio/video), source, muted/subscribed state.
◦ Exists as a subscribed publication (RemoteTrackPublication) or a Track object after negotiation.
◦ Not suitable for direct frame-by-frame processing.
• AudioStream
◦ A helper that wraps an audio Track and exposes raw PCM frames.
◦ Created with rtc.AudioStream(track).
◦ Provides an async iterator: async for frame in stream: to read AudioFrame data, timestamps, sample rate, etc.
◦ Use it when you need to analyze, transcribe, record, or otherwise process audio frames.
When to use which
• Use the Track to manage subscription, playback, or check participant state (muted/subscribed).
• Use AudioStream when you need raw audio for processing (STT, analysis, saving to file).
Quick example:
@room.on("track_subscribed")
async def on_track_subscribed(track, publication, participant):
if track.kind == rtc.TrackKind.KIND_AUDIO:
stream = rtc.AudioStream(track)
async for frame in stream:
# process raw PCM in frame.data
pass
Would you like an example that decodes frames to WAV or forwards frames to a speech-to-text service?
Sources: Rooms, participants, and tracks | LiveKit docs | Capturing the First Few Seconds of a Call for Processinglimited-spring-14213
12/03/2025, 4:00 AMtall-airline-16756
12/03/2025, 4:00 AMAudioStream from a participant's audio Track in Python:
1. Find the participant's subscribed audio Track (from publications or track_subscribed event).
2. Wrap that Track with rtc.AudioStream(track) and iterate frames.
Example — using the track_subscribed event:
from livekit import rtc
@room.on("track_subscribed")
async def on_track_subscribed(track: rtc.Track, publication: rtc.RemoteTrackPublication, participant: rtc.RemoteParticipant):
if track.kind == rtc.TrackKind.KIND_AUDIO:
stream = rtc.AudioStream(track)
async for frame in stream:
# frame.data is raw PCM bytes; frame.sample_rate, frame.channels available
process(frame)
Example — pulling current audio track from a participant and creating a stream:
def get_audio_stream(participant: rtc.RemoteParticipant):
for pub in participant.trackPublications.values():
if pub.kind == rtc.TrackKind.KIND_AUDIO and pub.subscribed and not pub.muted and pub.track:
return rtc.AudioStream(pub.track)
return None
stream = get_audio_stream(some_participant)
if stream:
async for frame in stream:
process(frame)
Would you like an example that saves frames to WAV or sends them to an STT service?limited-spring-14213
12/03/2025, 4:13 AMtall-airline-16756
12/03/2025, 4:13 AMrtc.AudioStream, and send frames to Deepgram using the LiveKit Deepgram plugin. It also shows handling transcription events.
1) Install and set API key:
• Install plugin: uv add "livekit-agents[deepgram]~=1.2"
• Set env: DEEPGRAM_API_KEY=your_api_key_here
2) Example code (use inside your agent/session or room event handlers):
import os
import asyncio
from livekit import rtc
from livekit.plugins import deepgram
DEEPGRAM_API_KEY = os.getenv("DEEPGRAM_API_KEY")
assert DEEPGRAM_API_KEY, "Set DEEPGRAM_API_KEY in env"
async def handle_transcripts(stt_stream: deepgram.SpeechStream):
async for event in stt_stream:
# event.is_final, event.alternatives[0].text, etc.
if event.is_final:
print("Final transcript:", event.alternatives[0].text)
else:
print("Partial:", event.alternatives[0].text)
async def process_track(track: rtc.Track):
if track.kind != rtc.TrackKind.KIND_AUDIO:
return
# Create STT client and stream
stt = deepgram.STT(model="nova-2-general") # choose model
stt_stream = stt.stream()
# Start task to consume transcriptions
asyncio.create_task(handle_transcripts(stt_stream))
# Wrap track in AudioStream and push frames to Deepgram
audio_stream = rtc.AudioStream(track)
try:
async for frame in audio_stream:
# frame contains raw PCM, sample_rate, channels, etc.
stt_stream.push_frame(frame)
finally:
stt_stream.end_input()
# Example: hook into room track_subscribed event
@room.on("track_subscribed")
def on_track_subscribed(track: rtc.Track, publication: rtc.RemoteTrackPublication, participant: rtc.RemoteParticipant):
if track.kind == rtc.TrackKind.KIND_AUDIO:
asyncio.create_task(process_track(track))
# Example: find existing participant audio and start processing
def start_for_participant(participant: rtc.RemoteParticipant):
for pub in participant.trackPublications.values():
if pub.kind == rtc.TrackKind.KIND_AUDIO and pub.subscribed and pub.track:
asyncio.create_task(process_track(pub.track))
return True
return False
Notes:
• Use push_frame(frame) to stream frames; call end_input() when done.
• handle_transcripts receives partial and final events; inspect event.is_final and event.alternatives.
• Ensure your agent has room access and is receiving subscribed tracks before creating streams.
Would you like a version that writes transcripts to a file, or one that sends frames to Deepgram with specific realtime options (punctuation, interim results, language)?
Sources: Deepgram STT plugin guide | LiveKit docs | An open source stack for real-time multimodal AI