Overview
Recording transcripts of conversations between users and your bot is useful for debugging, analysis, and creating a record of interactions. Pipecat’s turn events make it easy to collect both user and assistant messages as they occur.How It Works
Transcripts are collected using turn events on the context aggregators:- Capturing what the user says via
on_user_turn_stopped - Capturing what the assistant says via
on_assistant_turn_stopped - Each event provides the complete transcript for that turn
- Allowing you to handle these events with custom logic
Turn events are emitted by the context aggregators (
LLMUserAggregator and
LLMAssistantAggregator), which are created as part of the
LLMContextAggregatorPair.Basic Implementation
Step 1: Create Context Aggregators
First, create the context aggregator pair and get references to both aggregators:Step 2: Add to Your Pipeline
Include the aggregators in your pipeline:Step 3: Handle Turn Events
Register event handlers to capture transcripts when turns complete:With a realtime (speech-to-speech) service and
LLMContextAggregatorPair(context, realtime_service_mode=True), capture the
user transcript from
on_user_turn_message_added
instead of on_user_turn_stopped, whose message.content is None in that
mode.Next Steps
Turn Events Reference
Learn about all available turn events and their parameters.
Transcriptions Reference
See more examples for collecting and processing transcriptions.