Is it possible to also use stt node, tts node and ...
# ask-ai
c
Is it possible to also use stt node, tts node and llm node with the realtime models?
t
Thanks for reaching out, Vahid. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking whether you can use
stt_node
,
tts_node
, and
llm_node
with realtime models — thanks for the clear question. No —
stt_node
,
tts_node
, and
llm_node
cannot be used with realtime models. Realtime models consume and produce audio directly and bypass the STT→LLM→TTS pipeline, so those pipeline nodes are not available for realtime models. If you need customizable STT or TTS behavior, you have two options: • Use a full STT‑LLM‑TTS pipeline (which supports
stt_node
,
llm_node
, and
tts_node
). • Keep a realtime model but set responses to text and attach a separate TTS plugin/instance for synthesis (this allows TTS customization but does not expose the pipeline nodes). Would you like guidance on switching to a pipeline model or configuring a realtime model with a TTS plugin? Sources: Turn detection and interruptions | LiveKit Docs | Realtime model plugins | LiveKit Docs | Pipeline nodes and hooks | LiveKit docs | Models | LiveKit Docs | Gemini Live API plugin | LiveKit docs
c
This means that I cannot influence stt and tts streams with realtime models at all>?
t
You're correct — you cannot influence the internal STT and TTS processing of realtime models. Realtime models handle audio end-to-end (they consume and emit audio directly), so you can't attach or modify
stt_node
or
tts_node
behavior inside that flow. Options you can use instead: • Use the STT‑LLM‑TTS pipeline model to apply
stt_node
,
llm_node
, and
tts_node
for full control. • Keep a realtime model but set responses to text and run a separate TTS step/plugin for synthesis (this lets you control TTS behavior, but still does not expose internal STT or LLM nodes). Which option fits your use case — full pipeline control or realtime with external TTS?
c
How does it work with transcriptions being written etc. That still happens through normal events in livekit agents?
t
You're asking whether transcriptions still get emitted through LiveKit Agents' normal events when using realtime models — yes, they do, with a few important caveats. • User speech transcriptions are delivered via the
user_input_transcribed
event. • Agent speech and committed transcription text appear through the
conversation_item_added
and
speech_created
events. • Real‑time frontend delivery uses the
lk.transcription
text stream topic (clients can register a handler to receive these messages). • Timing differs for realtime models: transcriptions may be delayed or returned after the agent response because realtime models often don't provide interim results. • If you need immediate/interim transcriptions, add a separate STT plugin to the AgentSession (this provides real‑time STT while still using a realtime model). Would you like steps to add an STT plugin or an example showing how to register a
lk.transcription
handler in your client? Sources: Realtime model plugins | LiveKit Docs | Agents v0.x migration guide - Node.js | LiveKit Docs | Text and transcriptions | LiveKit docs | Events and error handling | LiveKit docs | Pipeline nodes and hooks | LiveKit docs
c
So if I want to modify transcriptions from user, I want the original stream that is written to the transcripts, than it’s through the user_input_transcribed event or other event?
t
You’re asking which event provides the original user transcription stream so you can modify what’s written to transcripts. • The original user transcriptions are emitted via the
user_input_transcribed
event. • To modify those transcriptions before they’re committed: ◦ Implement a
transcription_node
to intercept and transform the transcription stream (this gives you access to the streaming text deltas and lets you yield modified text). ◦ Alternatively, you can read from the
lk.transcription
text stream on the client and apply post-processing, but
transcription_node
is the place to alter the canonical transcription that gets written into transcripts. Would you like a short code example for a
transcription_node
implementation (Python or TypeScript)?
c
Yes, show me the transcription_node example with a realtime model please
t
You asked for a concrete
transcription_node
example when using a realtime model. Below is a concise Python example showing how to intercept and modify user transcription deltas in an Agent while using an OpenAI Realtime model. It yields cleaned transcription text back into the pipeline so the modified text is what gets written to transcripts.
Copy code
from typing import AsyncIterable
from livekit.agents import Agent, AgentSession
from livekit.plugins import openai

class MyAssistant(Agent):
    async def transcription_node(
        self,
        text: AsyncIterable[str],
        model_settings,  # keep typing simple; adapt if you use a specific ModelSettings type
    ) -> AsyncIterable[str]:
        """
        Example transcription_node:
        - Receives incremental transcription deltas from the realtime model.
        - Cleans / filters text and yields modified deltas back to the pipeline.
        """
        async for delta in text:
            # simple cleaning example: remove unwanted tokens and trim whitespace
            cleaned = delta.replace("❌", "").replace("👍", "").strip()

            # example: redact phone numbers (very simple pattern; adapt as needed)
            import re
            cleaned = re.sub(r"\b\d{3}[-.\s]?\d{3}[-.\s]?\d{4}\b", "[REDACTED_PHONE]", cleaned)

            # yield the modified delta so downstream (transcripts, conversation) gets the changed text
            yield cleaned

    async def on_enter(self, session: AgentSession):
        await session.generate_reply(instructions="Greet the user.")

async def run():
    # create a realtime LLM model (OpenAI Realtime example)
    llm = openai.realtime.RealtimeModel(
        voice="alloy",
        instructions="You are a helpful assistant."
    )

    session = AgentSession(
        llm=llm,
        agent=MyAssistant(),
    )

    await session.start()
Notes: •
transcription_node
receives an
AsyncIterable[str]
of transcription deltas and must yield strings; yielding modified deltas makes those modifications the canonical text used for transcripts and conversation context. • Realtime models still emit those transcription streams, so this node works with them. If you need interim/transitional behavior, consider adding a separate STT plugin for faster interim results. • Adjust cleaning/redaction logic to suit your needs (more robust regexes, language-aware filters, or external PII libraries). Would you like the same example in TypeScript or a variant that logs deltas with timestamps? Sources: Events and error handling | LiveKit docs | Pipeline nodes and hooks | LiveKit docs