I am trying to apply phoneme tags in the text I se...
# ask-ai
s
I am trying to apply phoneme tags in the text I send to ElevenLabs TTS for custom pronunciation. I am encountering a complication though. The timed strings returned by TTS show words wrapped in phoneme tags in their phoneme encoding form. I use these timed strings to display in my UI and save them as a record of the conversation transcript. Is there a way to get the original text from ElevenLabs TTS instead of the phoneme encoding?
t
Thanks for reaching out, Andrew. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking whether ElevenLabs TTS can return the original (pre-phoneme) text in its timed strings instead of the phoneme-encoded text so you can show readable UI transcripts. I can't change ElevenLabs behavior, but I can help with options to keep readable text in your UI. Could you confirm which of these matches your setup? • You send text that already includes phoneme tags (SSML) to ElevenLabs and receive timed strings where words are replaced by phoneme encodings. • Or you send plain text and ElevenLabs returns timed strings that include phoneme encodings for some words. Depending on which is true, here are practical approaches you can use: If you send text that already contains phoneme tags • Keep a local copy of the original text before you send it. Use that copy for display and transcripts and use the timed strings solely for timestamps and alignment. • In your transcript record, store both the original text and the timed metadata (timestamp + phoneme-encoded token) so you can render readable text while preserving accurate timing. If ElevenLabs returns phoneme-encoded tokens even when you send plain text • Post-process the timed strings by mapping phoneme-encoded tokens back to readable words using a mapping table you build from the response (or from the original input text) — essentially align phoneme tokens to the original words by sequence position. • If alignment is ambiguous, use heuristics: token order, surrounding context, or nearest-token matching to pick the readable word. If you want, tell me: • an example input you send and the timed-string output you receive (redact sensitive data), • and whether you currently store the original input text. I can then suggest a concrete parsing/mapping approach or sample code to keep readable transcripts while preserving timing.
s
I send text that already includes phoneme tags (SSML) to ElevenLabs and receive timed strings where words are replaced by phoneme encodings.
t
Thanks — since you send SSML with phoneme tags and receive timed strings where the words are phoneme-encoded, here are practical, implementable options to keep readable transcripts in your UI. 1) Store original text alongside timed strings (recommended) • Before sending SSML to ElevenLabs, save the original readable text (the SSML source or a stripped/plain-text version) together with the returned timed metadata. Use the saved readable text for UI and the timed data for alignment/timestamps. 2) Keep a mapping from phoneme-tagged tokens to readable tokens • When you construct SSML, record the mapping between each readable token (word or phrase) and the phoneme-tagged token you send. After receiving timed strings, replace phoneme tokens with the mapped readable tokens by index or ID. 3) Emit readable tokens inside SSML wrappers (if supported) • Wrap the phoneme tag around the readable text in a way that preserves the readable surface form in your copy, e.g. <phoneme ph="...">word</phoneme>. Then save the original SSML/plain text for display and use timed strings for timing only. 4) Re-align timed tokens to original text after the fact • If you didn’t record a mapping, align phoneme tokens to your original text using sequence position and surrounding tokens. Heuristics: ◦ Match tokens in order (first timed token -> first word, etc.) ◦ Use surrounding punctuation/spacing to improve alignment ◦ If mismatches occur, fall back to showing the original saved text and attach timing to nearest word If you want, I can: • Suggest a small code snippet (your language of choice) that saves the mapping and reconstructs readable transcripts from ElevenLabs timed output. • Review an anonymized example of your SSML input and the timed-string output and show exactly how to map them back to readable text. Which would you prefer?
s
If I save a mapping, how can I apply the same fix to the display I’m showing via useTrackTranscription?
t
Responding to: "If I save a mapping, how can I apply the same fix to the display I’m showing via useTrackTranscription?" You can apply the mapping in one of two places; agent-side is simplest and recommended because it preserves timing and keeps the client code unchanged. 1) Recommended — clean in the agent (preserve TimedString timing) • Modify your agent’s
transcription_node()
to replace phoneme-encoded text with the readable tokens using your saved mapping, and yield new
TimedString
objects that keep the original `start_time`/`end_time`. • This ensures
lk.transcription
carries cleaned text and
useTrackTranscription
on the frontend receives readable tokens with correct timing. Example pattern (Python-like pseudocode):
Copy code
replacements = {"A P I": "API", "U R L": "URL", ...}

async for chunk in text:
    if isinstance(chunk, TimedString):
        cleaned = chunk.text
        for wrong, right in replacements.items():
            cleaned = cleaned.replace(wrong, right)
        yield TimedString(text=cleaned, start_time=chunk.start_time, end_time=chunk.end_time)
    else:
        # plain string fallback
        cleaned = chunk
        for wrong, right in replacements.items():
            cleaned = cleaned.replace(wrong, right)
        yield cleaned
2) Alternative — clean on the frontend (if you cannot change the agent) • Use
useTrackTranscription
as normal, then map/replace phoneme text to readable words before rendering. • When replacing, preserve timing by updating only the
text
field of each TimedString from the transcript array. Example pattern (React/TSX pseudocode):
Copy code
const transcripts = useTrackTranscription({ participantTrack });

const cleaned = transcripts.map(t => ({
  ...t,
  text: applyMapping(t.text, replacements) // applyMapping does the string replacements
}));

return cleaned.map((t, i) => <span key={i}>{t.text}</span>);
Which approach to choose • If you control the agent: apply changes in
transcription_node()
so every client gets cleaned, timed text automatically. • If you only control the client: apply mapping in the UI before render. If you want, share: • a small anonymized example of the SSML you send and a TimedString you receive, • and whether you can modify the agent code or only the frontend— and I’ll produce a concrete agent implementation or a frontend code snippet tailored to your stack. Sources: Text and transcriptions | LiveKit docs | Pipeline nodes and hooks | LiveKit docs | Web and mobile frontends | LiveKit docs