# Source: https://docs.pipecat.ai/guides/fundamentals/saving-transcripts.md

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pipecat.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Saving Conversation Transcripts

> Learn how to collect and save conversation transcripts between users and your bot

## 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:

1. Capturing what the user says via `on_user_turn_stopped`
2. Capturing what the assistant says via `on_assistant_turn_stopped`
3. Each event provides the complete transcript for that turn
4. Allowing you to handle these events with custom logic

<Note>
  Turn events are emitted by the context aggregators (`LLMUserAggregator` and
  `LLMAssistantAggregator`), which are created as part of the
  `LLMContextAggregatorPair`.
</Note>

## Basic Implementation

### Step 1: Create Context Aggregators

First, create the context aggregator pair and get references to both aggregators:

```python  theme={null}
from pipecat.processors.aggregators.llm_response_universal import (
    LLMContextAggregatorPair,
    UserTurnStoppedMessage,
    AssistantTurnStoppedMessage,
)

# Create context aggregator pair
user_aggregator, assistant_aggregator = LLMContextAggregatorPair(context)
```

### Step 2: Add to Your Pipeline

Include the aggregators in your pipeline:

```python  theme={null}
pipeline = Pipeline(
    [
        transport.input(),
        stt,                              # Speech-to-text
        user_aggregator,
        llm,
        tts,                              # Text-to-speech
        transport.output(),
        assistant_aggregator,
    ]
)
```

### Step 3: Handle Turn Events

Register event handlers to capture transcripts when turns complete:

```python  theme={null}
@user_aggregator.event_handler("on_user_turn_stopped")
async def on_user_turn_stopped(aggregator, strategy, message: UserTurnStoppedMessage):
    print(f"[{message.timestamp}] user: {message.content}")

@assistant_aggregator.event_handler("on_assistant_turn_stopped")
async def on_assistant_turn_stopped(aggregator, message: AssistantTurnStoppedMessage):
    print(f"[{message.timestamp}] assistant: {message.content}")
```

<Tip>
  In addition to console logging, you can save transcripts to a database or file
  for later analysis.
</Tip>

## Next Steps

<CardGroup cols={2}>
  <Card title="Turn Events Reference" icon="book" iconType="duotone" href="/server/utilities/turn-management/turn-events">
    Learn about all available turn events and their parameters.
  </Card>

  <Card title="Transcriptions Reference" icon="scroll" iconType="duotone" href="/server/utilities/turn-management/transcriptions">
    See more examples for collecting and processing transcriptions.
  </Card>
</CardGroup>

Consider implementing transcript recording in your application for debugging during development and preserving important conversations in production. The transcript data can also be useful for analyzing conversation patterns and improving your bot's responses over time.