This message was deleted.
# ask-ai
s
This message was deleted.
t
Thanks for reaching out, vnnicius. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking about the placeholder "<|audio_text|>" appearing in assistant messages. That placeholder means the model produced audio (or an audio-only event) without a text transcript, so the agent emitted a token to indicate speech was generated but no transcribed text was returned. What you can do next: • Confirm you're truly requesting text-only from the Realtime model: keep
modalities=["text"]
and ensure no system/prompt instructions ask the model to speak. • Keep using a separate TTS (you already use ElevenLabs). Route model responses through your TTS so you control when audio is generated. • Add a small post-processing filter to remove or replace the placeholder before sending messages to the frontend. Example idea:
Copy code
clean = message.replace("<|audio_text|>", "").strip()
Yield or send only if
clean
is non-empty. If you'd like, tell me: • which Realtime model/version you’re calling (Azure model name), and • whether you ever set modalities to include
audio
or use any system prompt that asks the model to speak. I can recommend a specific filter hook or show how to override
transcription_node
for your AgentSession. Sources: Realtime model plugins | LiveKit Docs | Azure OpenAI Realtime API and LiveKit | LiveKit docs | Pipeline nodes and hooks | LiveKit docs
Good—you're using SIP calls. Below is a concise example showing how to implement a filter hook by overriding
transcription_node
to remove the "<|audio_text|>" placeholder. This works for SIP participants because SIP callers appear as room participants and their transcriptions flow through the same pipeline.
Copy code
from livekit.agents import Agent, AgentSession
from typing import AsyncIterable

class CleanAgent(Agent):
    async def transcription_node(
        self, text_stream: AsyncIterable[str], model_settings=None
    ) -> AsyncIterable[str]:
        async for delta in text_stream:
            cleaned = delta.replace("<|audio_text|>", "").strip()
            if cleaned:  # only forward non-empty text
                yield cleaned

# When creating the session (example)
session = AgentSession(
    userdata=userdata,
    llm=openai.realtime.RealtimeModel.with_azure(modalities=["text"]),
    tts=elevenlabs.TTS(
        voice_settings=VoiceSettings(
            stability=0.5, similarity_boost=0.75, style=0.0, speed=1.0, use_speaker_boost=True
        )
    ),
)

# Start the agent with your SIP-connected room context:
await session.start(agent=CleanAgent(), room=your_sip_room)
If you want different behavior, you can: • Replace the placeholder with a custom message instead of removing it. • Log occurrences for debugging (e.g., count placeholders per call). • Only apply filtering for SIP participant IDs if you want it scoped. Do you want the example scoped to only SIP participants or to include logging/counting of placeholders? Sources: Pipeline nodes and hooks | LiveKit docs | Using Noise Cancellation for SIP and WebRTC Participants
Short answer: yes — the
transcription_node
filter prevents the
<|audio_text|>
placeholder from reaching your TTS. Explanation and caveats: • Overriding
transcription_node
runs before downstream components, so removing/replacing
<|audio_text|>
there ensures the TTS only receives cleaned text. • The LLM may still internally generate audio events, but with
modalities=["text"]
and this filter in place, those audio-only tokens will not be forwarded to your ElevenLabs TTS. • If the model sometimes emits only that placeholder (no other text), you should skip sending empty results to TTS (the example used
if cleaned:
for that reason). If you want, I can: • Provide a version that logs occurrences or • Scope the filter so it only strips placeholders for SIP participants. Which would you prefer?
You're asking whether the cleaned text will be sent to the LLM. Short answer: no — the
transcription_node
filter runs on the model's outgoing text stream (what the Agent receives/forwards), not on what you send into the LLM. Clarifying data flow: • Incoming audio (SIP caller) → STT → text input to the LLM. • LLM generates a response (may include "<|audio_text|>" placeholders). •
transcription_node
runs on that outgoing text stream and can remove/replace placeholders. • The cleaned text from
transcription_node
is what gets forwarded to downstream components (e.g., your TTS and chat/context storage). So the LLM still receives your original prompt/conversation history unchanged; the filter only prevents placeholder tokens from being sent onward to TTS or the user. If you want to modify what the LLM sees, you must change the input sent to the LLM (prompts, system instructions, or upstream processing).
g
My problem is that this <|audio_text|> is being sent to my user (the person interacting with the agent). I don't just want to remove it from the history; I want it to never be spoken again.
t
You're right — to ensure "<|audio_text|>" is never spoken or shown to the user you must filter it from the agent's outbound path (not just the transcription pipeline). Override the agent's outbound/message node so any outgoing assistant content is cleaned before it reaches TTS or the user, and also ensure the cleaned text is what's stored in context/history. Example — override an outbound node that sanitizes assistant messages:
Copy code
from livekit.agents import Agent, AgentSession
from typing import AsyncIterable, Dict, Any

class NoAudioPlaceholderAgent(Agent):
    async def outbound_node(
        self, messages: AsyncIterable[Dict[str, Any]], model_settings=None
    ) -> AsyncIterable[Dict[str, Any]]:
        async for msg in messages:
            # Only process assistant messages with `content`
            if msg.get("role") == "assistant" and "content" in msg:
                # content may be a list of strings; clean each entry
                cleaned_content = []
                for part in msg["content"]:
                    cleaned = part.replace("<|audio_text|>", "").strip()
                    if cleaned:
                        cleaned_content.append(cleaned)
                # if nothing remains, skip sending/speaking
                if not cleaned_content:
                    continue
                msg["content"] = cleaned_content
            yield msg
Where to apply: • Use this agent when starting the session:
await session.start(agent=NoAudioPlaceholderAgent(), room=your_sip_room)
• This prevents the placeholder from being forwarded to TTS or the user and ensures only cleaned text is appended to history. Extra safeguards (recommendations): • Keep
modalities=["text"]
for the LLM. • Log or count skipped messages so you can detect if the model frequently emits audio-only responses. • If you want to scope filtering only for SIP participants, check the message metadata (participant id) inside
outbound_node
before cleaning. Would you like this scoped to SIP-only messages or to include logging for skipped messages?