Skip to main content
Sometimes the LLM’s text needs a touch-up before it’s spoken: expand an acronym so TTS says it correctly, strip markdown, or filter sensitive content. The tts pipeline hook gives you the reply’s text stream so you can transform it before synthesis.

The tts hook

Register an async hook with @pipeline.on("tts"). It receives the streaming reply text; yield the transformed text, then hand it to run_tts() to produce the audio.

What you can do in the hook

  • Fix pronunciation of acronyms, brand names, and technical terms (shown above).
  • Filter or redact content before it’s spoken.
  • Normalize formatting: strip markdown, expand numbers/dates, clean up symbols.
Because the hook sits between the LLM and TTS, the change affects only what’s spoken: the text recorded in chat context is unchanged.
This is one of several pipeline hooks. The same mechanism lets you intercept other stages of the pipeline.

References

Examples

Enhanced Pronunciation

Rewrite text before synthesis.