hundreds-evening-11581
12/17/2025, 8:32 AMtall-airline-16756
12/17/2025, 8:32 AMtall-airline-16756
12/17/2025, 8:32 AMhundreds-evening-11581
12/17/2025, 8:35 AMtall-airline-16756
12/17/2025, 8:35 AM<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)
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:
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.hundreds-evening-11581
12/17/2025, 8:36 AMtall-airline-16756
12/17/2025, 8:36 AMtts_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
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