Overview
LLMTextProcessor is a processor designed to aggregate LLMTextFrames into coherent text units before passing them to downstream services, such as TTS. By utilizing text aggregators, it ensures that text is properly segmented and structured, enhancing the quality of subsequent processing. This processor expects LLMTextFrames as input and outputs AggregatedTextFrames containing the aggregated text.
When an
LLMTextProcessor is in use, text aggregation is handled upstream and
the TTS service’s built-in aggregator is bypassed.bot-output messages, supporting custom client-side handling and rendering (e.g. collapsible code blocks, clickable links, etc.).
LLMTextProcessor API Reference
Pipecat’s API methods for LLMTextProcessor
Example Implementation
Complete example with LLMTextProcessor and custom TTS and RTVI handling
Constructor Parameters
BaseTextAggregator
default:"None"
An instance of a text aggregator (e.g.,
PatternPairAggregator or a custom
aggregator type) used to aggregate incoming text from LLMTextFrames. If
None, a SimpleTextAggregator will be used by default, aggregating text
based on sentence boundaries.list[tuple[TextType | str, TextTransform]]
default:"None"
Callables that rewrite each aggregation, as
(text_type | "*", transform)
pairs. A transform takes the text and its type and returns the rewritten text,
and "*" matches every type. The rewrite reaches the TTS service, the
context, and the client. A transform that leaves only whitespace drops the
aggregation. A transform registered on the TTS service rewrites only what is
spoken. TextTransform is in pipecat.utils.text.transforms.Methods
add_text_transformer
text_type, or for every type with "*".
remove_text_transformer
text_type.
Usage
TheLLMTextProcessor should be integrated into your pipeline after the LLM service and before any services that consume text, such as TTS. It processes incoming LLMTextFrames, aggregates their text content, and outputs AggregatedTextFrames.