Overview

Recording transcripts of conversations between users and your bot is useful for debugging, analysis, and creating a record of interactions. Pipecat’s TranscriptProcessor makes it easy to collect both user and bot messages as they occur.

How It Works

The TranscriptProcessor collects transcripts by:

  1. Capturing what the user says (from TranscriptionFrames)
  2. Capturing what the bot says (from TTSTextFrames)
  3. Emitting events with transcript updates in real-time
  4. Allowing you to handle these events with custom logic

The TranscriptProcessor provides two separate processors: one for user speech and one for assistant speech. Both emit the same event type when new transcript content is available.

Basic Implementation

Step 1: Create a Transcript Processor

First, initialize the transcript processor:

from pipecat.processors.transcript_processor import TranscriptProcessor

# Create a single transcript processor instance
transcript = TranscriptProcessor()

Step 2: Add to Your Pipeline

Place the processors in your pipeline at the appropriate positions:

pipeline = Pipeline(
    [
        transport.input(),
        stt,                            # Speech-to-text
        transcript.user(),              # Captures user transcripts
        context_aggregator.user(),
        llm,
        tts,                            # Text-to-speech
        transport.output(),
        transcript.assistant(),         # Captures assistant transcripts
        context_aggregator.assistant(),
    ]
)

Place transcript.user() after the STT processor and transcript.assistant() after transport.output() to ensure accurate transcript collection.

Step 3: Handle Transcript Updates

Register an event handler to process transcript updates:

@transcript.event_handler("on_transcript_update")
async def handle_transcript_update(processor, frame):
    # Each message contains role (user/assistant), content, and timestamp
    for message in frame.messages:
        print(f"[{message.timestamp}] {message.role}: {message.content}")

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

Next Steps

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.