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

# Bot Speech Observer

> BotSpeechObserver reports the text the bot will speak as the TTS service produces it, and when the bot's speech ends or is interrupted.

## Overview

`BotSpeechObserver` reports each piece of text the bot will speak, as the TTS service produces it and ahead of playback, and the end of the bot's speech with whether it was interrupted.

A TTS service that reports word timestamps produces one word at a time, each with a presentation timestamp (`pts`) saying when its audio is due at the transport. A service that doesn't produces text in the pieces it generates, often a sentence, with no `pts`. Expression sounds and pauses are left out, since the bot doesn't say them as words. After an interruption, text of the cut-off reply is left out until the TTS service starts its next reply. Uninterruptible text plays on, so it is still reported.

## Events

Both handlers run in order on the observer's task, so they need to be fast.

| Event | Arguments | Description |
| - | - | - |
| `on_bot_text` | `observer`, `frame: TTSTextFrame` | Called for each piece of text the bot will speak. |
| `on_bot_speech_ended` | `observer`, `interrupted: bool` | Called once after the text reported since it was last called, when the bot stops speaking or is interrupted. After an interrupted end, text reported earlier may not have been heard. |

## Usage

```python theme={null}
from pipecat.frames.frames import TTSTextFrame
from pipecat.observers.bot_speech_observer import BotSpeechObserver
from pipecat.pipeline.worker import PipelineWorker

observer = BotSpeechObserver()

@observer.event_handler("on_bot_text")
async def on_bot_text(observer, frame: TTSTextFrame):
    logger.info(f"Bot will say: {frame.text}")

@observer.event_handler("on_bot_speech_ended")
async def on_bot_speech_ended(observer, interrupted: bool):
    logger.info(f"Bot speech ended (interrupted={interrupted})")

worker = PipelineWorker(
    pipeline,
    observers=[observer],
)
```

## Configuration

### Constructor Parameters

\*\***kwargs** `Any`

Additional arguments passed to the parent `BaseObserver`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.