Is there any way i can exclude xml tags in livekit...
# ask-ai
b
Is there any way i can exclude xml tags in livekit-client transcripts
✅ 1
t
Thanks for reaching out, G. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about excluding XML tags from livekit-client transcripts. Yes — you can remove XML tags before they reach clients by intercepting and filtering transcription text on the agent side. The livekit-client itself doesn’t provide a built-in “strip XML” toggle, but the agent pipeline exposes a hook where you can transform transcription output (for example, the
transcription_node
hook). Use that hook to strip or sanitize tags before sending the transcript to the client or TTS engine. Example approach (conceptual): 1. Add a transcription processing node in your agent logic (the
transcription_node
). 2. For each incoming transcription delta, remove XML tags (for example with a simple regex or an XML/HTML sanitizer) and then yield the cleaned text so downstream consumers receive tag-free transcripts. Minimal Python-style example:
Copy code
import re

TAG_RE = re.compile(r'<[^>]+>')

async def transcription_node(self, text: AsyncIterable[str], model_settings) -> AsyncIterable[str]:
    async for delta in text:
        cleaned = TAG_RE.sub('', delta)   # removes <...> tags
        yield cleaned
Notes and tips: • A regex like the one above works for simple tag removal. If transcriptions may include nested or malformed XML/SSML, consider an XML/HTML parser or sanitizer to avoid removing desirable content or breaking encoding. • If you only need to remove specific tags (e.g.,
<break>
,
<prosody>
), target those tag names instead of stripping all tags. • This filtering affects both speech-aligned transcriptions and text-only responses if applied in the pipeline, so downstream TTS/clients will receive the sanitized text. If you want, tell me: • Which SDK/language you’re using (Node.js, Python, etc.), and • Whether you want to strip all tags or only specific ones— and I’ll provide a concrete code snippet tailored to your environment. Sources: client-sdk-js | livekit/livekit_composite | DeepWiki | How to build an agent with speech-to-text input and text-only output | Live... | Text and transcriptions | LiveKit Documentation | Pipeline nodes and hooks | LiveKit Documentation, with interactive elements
b
I just want to exclude it from UI showing transcripts
t
Thanks — I see you only want XML tags excluded from the UI transcript display. I can help with a small, safe approach you can run right before rendering text in your frontend. Quick question so I give the exact snippet you need: • Which frontend stack are you using (plain JS, React, Vue, Angular, etc.)? • Are transcripts arriving as full strings, or as streaming deltas you append to the UI? If you want a general approach now, here are two simple, safe options you can use client-side before rendering: • Remove all tags (simple, works in most cases)
Copy code
function stripTags(text) {
  return text.replace(/<[^>]+>/g, '');
}
Use this on each transcript string or incoming delta before inserting it into the DOM. • Remove only specific tags (keeps other markup)
Copy code
function removeSpecificTags(text, tags = ['break','prosody']) {
  const tagList = tags.join('|');
  const re = new RegExp(`<\\/?(?:${tagList})(?:\\s[^>]*)?>`, 'gi');
  return text.replace(re, '');
}
Pass the tag names you want excluded so other angle-bracket content stays intact. Important notes: • A regex is fine for straightforward tag removal. If transcripts may contain nested/malformed XML or encoded entities, use an HTML/XML parser or sanitizer on the client (e.g., DOMParser in browsers or a library) to avoid edge cases. • If transcripts are streamed, apply this function to each delta before appending to the UI to avoid flashes of raw tags. • If you’re using React, run the cleaning function before setting state and avoid dangerouslySetInnerHTML unless you intentionally need raw HTML. Tell me your frontend framework and whether transcripts are streamed or full messages, and I’ll provide a tailored code example you can drop into your UI. , with interactive elements