big-breakfast-84263
03/01/2026, 1:53 PMtall-airline-16756
03/01/2026, 1:54 PMtall-airline-16756
03/01/2026, 1:54 PMllm_node (pass-through for TTS) and transcription_node (strip tags for UI).
Recommended implementation (Python example)
1. Use a regex to remove XML/SSML tags when streaming text to the UI/chat.
2. Preserve the raw LLM stream for the TTS plugin.
import re
from livekit.agents import Agent
from typing import AsyncIterable
class MyAgent(Agent):
async def llm_node(self, chat_ctx, tools, model_settings=None):
# Pass raw LLM output (with SSML) through so TTS can use it
async with self.llm.chat(chat_ctx=chat_ctx, tools=tools) as stream:
async for chunk in stream:
yield chunk
async def transcription_node(self, text: AsyncIterable[str], model_settings=None) -> AsyncIterable[str]:
# Regex to remove SSML/XML tags like <prosody>, <break>, etc.
ssml_regex = re.compile(r'<[^>]+>')
async for chunk in text:
clean_text = ssml_regex.sub('', chunk)
yield clean_text
Behavior summary
• TTS receives the original text with SSML (so prosody, pauses, etc. work).
• UI and chat history receive cleaned text without SSML tags.
Notes and tips
• The regex above strips all XML-like tags. If you need to preserve specific tags or attributes, adjust the regex or implement an XML parser to remove only SSML namespaces/tags.
• Test edge cases where the LLM might generate malformed tags; consider using an XML parser (like Python’s xml.etree) for stricter handling if needed.
• This pattern is intended for agent pipelines that support llm_node and transcription_node.
If you share which agent architecture or language/runtime you’re using (or an example LLM/TTS stack), I can give a tailored snippet or a parser-based variant that preserves allowed tags and removes everything else.
Sources: Modifying LLM output before TTS | LiveKit Documentation | LLM Output Replacement | LiveKit Documentation | Pipeline nodes and hooks | LiveKit Documentation | How to build an agent with speech-to-text input and text-only output | Live...big-breakfast-84263
03/01/2026, 1:55 PMtall-airline-16756
03/01/2026, 1:55 PM