Now that you’ve got Pipecat installed, let’s run your first example application. We’ll use the “Say One Thing” example, which creates a simple bot that greets users when they join a room and exits when they leave.

Getting the Example

Download the “Say One Thing” example from the pipecat repo and save it to your project directory.

Configuring the Example

The example uses Cartesia’s text-to-speech service. Make sure you have your .env file set up with:

DAILY_SAMPLE_ROOM_URL=https://YOURDOMAIN.daily.co/YOURROOM
DAILY_API_KEY=your_daily_api_key
CARTESIA_API_KEY=your_cartesia_api_key

The example uses a pre-configured voice. You can change this by modifying the voice_id parameter in the CartesiaHttpTTSService configuration.

Running the Example

  1. Open your Daily room URL in a browser tab
  2. Join the room
  3. Run the example:
python 01-say-one-thing.py

If all goes well, you should see another participant (named “Say One Thing”) join the room, greet you, and disconnect when you leave the room.

Understanding How It Works

Let’s look at the key components of this example:

# Configure Daily transport for WebRTC communication
# - room_url: Where to connect
# - None: No authentication token needed
# - "Say One Thing": Bot's display name
# - Enable audio output for text-to-speech playback
transport = DailyTransport(
    room_url,
    None,
    "Say One Thing",
    DailyParams(audio_out_enabled=True)
)

# Initialize Cartesia's text-to-speech service
# Using a pre-selected British female voice
# You can find other voices at play.cartesia.ai/library
tts = CartesiaHttpTTSService(
    api_key=os.getenv("CARTESIA_API_KEY"),
    voice_id="79a125e8-cd45-4c13-8a67-188112f4dd22",  # British Lady
)

# Create a pipeline runner to manage the processing pipeline
runner = PipelineRunner()

# Create pipeline to process text into speech and play it
# 1. tts: Converts text messages into audio
# 2. transport.output(): Sends audio to the Daily room
pipeline = Pipeline([
    tts,
    transport.output()
])

# Create PipelineTask
task = PipelineTask(pipeline)

# When the first person joins the room:
# - Extract their username from the participant info
# - Generate a greeting message
# - Queue it for text-to-speech conversion
@transport.event_handler("on_first_participant_joined")
async def on_first_participant_joined(transport, participant):
    participant_name = participant.get("info", {}).get("userName", "")
    await task.queue_frame(TextFrame(f"Hello there, {participant_name}!"))

# When someone leaves the room:
# - Queue an EndFrame to gracefully shut down the application
# This ensures proper cleanup of resources
@transport.event_handler("on_participant_left")
async def on_participant_left(transport, participant, reason):
    await task.queue_frame(EndFrame())

# Run the pipeline task
await runner.run(task)

This example demonstrates several core Pipecat concepts:

  • Using a transport for audio output
  • Setting up a TTS service
  • Creating a simple processing pipeline
  • Handling events and generating responses
  • Managing application lifecycle

Next Steps

Now that you’ve got your first Pipecat app running, you can: