In my system prompt for the ai agent it is not fol...
# ask-ai
h
In my system prompt for the ai agent it is not following phonetics and pronunciation no matter what I do, how do fix this ?
t
Thanks for reaching out, Prathamesh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're right to be concerned — system prompts alone won't control how text is spoken. To fix pronunciation, you need to configure your TTS layer (SSML or provider-specific pronunciation features) or preprocess the LLM output to insert phonetic markup. To help quickly, please tell me: • Which TTS provider/plugin you’re using (ElevenLabs, Rime, Resemble, MiniMax, etc.) • A short snippet of your system prompt and an example phrase that’s being pronounced wrong • Whether you can enable SSML or pass a pronunciation dictionary in your TTS config Once you share those, I’ll give the exact SSML or code snippet to correct the pronunciation. Sources: How to Get Help from LiveKit | Rime TTS plugin guide | LiveKit Docs | ElevenLabs TTS plugin guide | LiveKit Docs | Cartesia TTS plugin guide | LiveKit docs | Resemble AI TTS plugin guide | LiveKit Docs
h
'preprocess the LLM output to insert phonetic markup.' How would I do this ?
t
You're asking how to programmatically modify the LLM's text output so the TTS speaks with the pronunciation you want. I can walk you through the general approach and give concrete examples — but first, tell me which TTS provider you use (ElevenLabs, Rime, Resemble, MiniMax, etc.) and share a short example of the LLM output plus the desired pronunciation. While I wait, here’s a concise, provider-agnostic plan and example patterns you can use immediately: 1) Pipeline overview • Generate text from the LLM. • Run a preprocessing step that replaces words/phrases with SSML or provider-specific pronunciation tokens. • Send the transformed text to the TTS engine with SSML/parsing enabled (or with the provider pronunciation dictionary parameter). 2) Common preprocessing techniques • Exact replace: Swap problematic words with
<phoneme>
SSML or provider bracket/phoneme syntax. • Dictionary lookup: Maintain a
pronunciation_dict
mapping from surface text → phoneme/SSML. • Regex + context rules: Use regex to match patterns (numbers, acronyms, names) and transform them consistently. • Post-filter for safety: Ensure inserted SSML is well-formed and escape any user-supplied content. 3) Example — SSML replacement (pseudo-Python)
Copy code
pronunciation_dict = {
  "API": '<phoneme alphabet="ipa" ph="eɪ piː aɪ">API</phoneme>',
  "LiveKit": '<phoneme alphabet="ipa" ph="laɪv kɪt">LiveKit</phoneme>',
  "$1,000": '<say-as interpret-as="unit">$1,000</say-as>'
}

def apply_pronunciations(text):
    for key, ssml in pronunciation_dict.items():
        text = re.sub(r'\b' + re.escape(key) + r'\b', ssml, text)
    return f"<speak>{text}</speak>"
4) Example — provider-specific (Rime-like bracket phonemize) • If the provider supports phonemize-in-brackets, convert occurrences into bracketed form:
Copy code
text = text.replace("LiveKit", "LiveKit[laɪv kɪt]")
and send with
phonemize_between_brackets=True
. 5) Handling numbers/acronyms/dates • Use
say-as
for numbers/dates, or expand numerals before TTS: ◦ Replace "1000" → "one thousand" or wrap:
<say-as interpret-as="cardinal">1000</say-as>
• Expand acronyms programmatically or map them in your dictionary. 6) Validation • Wrap resulting text in
<speak>
and validate XML/SSML. • If your provider uses a different syntax (pronunciation_dict, phoneme tags, brackets), adapt replacements accordingly. Tell me your TTS provider and a short example phrase and I’ll produce the exact replacement snippet you should use for your environment.
h
tts=cartesia.TTS(model="sonic-3", voice="22bb5a1d-627e-484a-9e0c-eeda819abb95")
t
You're asking how to preprocess the LLM output so Cartesia TTS speaks words the way you want. Below is a concise, ready-to-use approach and example tailored to Cartesia. What I'll cover: • Intercept LLM text before TTS • Apply a pronunciation dictionary + regex replacements • Wrap output for TTS (SSML only if your pipeline supports it) • Example agent
tts_node
override you can drop into your code Key idea • Replace problematic tokens in the LLM output with phonetic spellings or SSML (if supported). Cartesia reliably accepts text-based phonetic replacements; SSML may or may not be parsed by your pipeline, so use plain text replacements as the default. 1) Pronunciation dictionary approach • Create a mapping: surface text → replacement (phonetic spelling or SSML snippet). • Use regex with word boundaries to avoid partial matches. • Stream/transform the LLM output and hand the transformed text to Cartesia. 2) Minimal robust example (Python) — drop into your Agent class
Copy code
import re
from livekit import agents
from livekit.plugins import cartesia

class Assistant(agents.Agent):
    async def tts_node(self, text, model_settings):
        # Pronunciation rules: surface -> replacement
        pronunciations = {
            "API": "A P I",
            "SQL": "sequel",
            "LiveKit": "Live Kit",
            "nginx": "engine-x",
            "$1,000": "one thousand dollars",
        }

        async def transform(stream):
            async for chunk in stream:
                modified = chunk
                for surface, repl in pronunciations.items():
                    # case-insensitive whole-word replace
                    modified = re.sub(rf'\b{re.escape(surface)}\b', repl, modified, flags=re.IGNORECASE)
                yield modified

        # Pass transformed text into the default TTS pipeline which sends to Cartesia
        async for frame in agents.Agent.default.tts_node(self, transform(text), model_settings):
            yield frame

# Example TTS initialization (your existing code)
tts = cartesia.TTS(model="sonic-3", voice="22bb5a1d-627e-484a-9e0c-eeda819abb95")
3) If you can use SSML • If your pipeline parses SSML, replace entries with
<phoneme>
or
<say-as>
tags and wrap final output in
<speak>...</speak>
. • Test whether Cartesia respects SSML in your environment. If it doesn't, revert to text-based phonetic replacements. Example SSML replacement (only if supported): surface "API" -> '<phoneme alphabet="ipa" ph="eɪ piː aɪ">API</phoneme>' 4) Helpful tips • Start small: add common acronyms/names to
pronunciations
and expand as you hear issues. • For numbers/dates, prefer
<say-as>
or expand numerals ("1000" → "one thousand") if SSML isn't parsed. • Keep replacements safe: escape any user-provided content before inserting into SSML. • Validate output quickly by generating short test phrases and listening. If you want, share one exact LLM output line that pronounces wrong and the desired pronunciation; I’ll give you the precise replacement (plain text or SSML) to add to your dictionary. Sources: Cartesia TTS plugin guide | LiveKit docs | Agent speech and audio | LiveKit docs