ancient-hospital-67205
10/29/2025, 10:35 PMtall-airline-16756
10/29/2025, 10:36 PMtall-airline-16756
10/29/2025, 10:36 PMancient-hospital-67205
10/29/2025, 10:36 PMtall-airline-16756
10/29/2025, 10:37 PMnormalizeText function from LiveKit's turn detector utilities. It applies Unicode NFKC normalization, cleans up unnecessary punctuation, and keeps apostrophes just right.
• If you’re working with JavaScript or TypeScript agents, you can use the normalizeText utility directly. For Python agents, a similar approach is to use Python’s unicodedata.normalize('NFKC', text) function.
• For those using TTS services, turning on their built-in text normalization features can really help. For example, Speechify TTS and ElevenLabs TTS offer parameters like text_normalization and apply_text_normalization that handle these issues smoothly.
Following these steps should clear up the encoding problems in your custom agent code. If you run into any bumps or have more questions, feel free to reach out—I’m here to help!
Sources: plugins/livekit/src/turn_detector/utils.test.ts | livekit-plugins/livekit-plugins-speechify/livekit/plugins/speechify/tts.py | ElevenLabs TTS | LiveKit Docsancient-hospital-67205
10/29/2025, 10:38 PMtall-airline-16756
10/29/2025, 10:39 PMllm_node Method: You can customize the LLM output stream by overriding the llm_node method in your agent class. This way, you get to process and clean the text chunks as they come through. Here’s a simple example to guide you:
class SimpleAgent(Agent):
async def llm_node(self, chat_ctx, tools, model_settings=None):
async def process_stream():
async with self.llm.chat(chat_ctx=chat_ctx, tools=tools) as stream:
async for chunk in stream:
if chunk is None:
continue
content = getattr(chunk.delta, 'content', None)
if content:
processed_content = content.replace('â', "'")
chunk.delta.content = processed_content
yield chunk
return process_stream()
• Use the before_tts_cb Callback: Another great approach is to apply a final cleanup to the text just before it’s sent to the TTS engine, using the before_tts_cb parameter. Here’s how you can do it:
async def _before_tts_cb(agent, text):
if isinstance(text, str):
return text.replace('â', "'")
else:
async def process_stream():
async for chunk in text:
yield chunk.replace('â', "'")
return process_stream()
These friendly methods will help make sure your outgoing text looks just right, free from those encoding hiccups. If you’d like, I’m here to help you walk through implementing these solutions step by step—just let me know!
Sources: Modifying LLM output before TTS | LiveKit Docs | pipeline-llm/llm_powered_content_filter.py | chain-of-thought-tts/README.mdoc | Pipeline nodes and hooks | LiveKit Docsancient-hospital-67205
10/29/2025, 10:44 PMtall-airline-16756
10/29/2025, 10:45 PM