Skip to main content

Overview

AsteriskFrameSerializer converts between Pipecat frames and the media stream of an Asterisk WebSocket channel. It translates the channel’s JSON or plain-text events and raw audio payloads into Pipecat frames (and vice versa), so a Pipecat pipeline can handle telephony calls bridged through Asterisk. The serializer is designed to be used with Pipecat’s FastAPIWebsocketTransport.

Source Repository

Source code, examples, and issues for the Asterisk integration

PyPI Package

The pipecat-asterisk package on PyPI

Asterisk

Learn more about the Asterisk open-source telephony platform

WebSocket Channel Docs

Asterisk WebSocket channel driver documentation

Installation

This is a community-maintained package distributed separately from pipecat-ai:
uv add pipecat-asterisk
Or use pip install pipecat-asterisk if you manage dependencies with pip.

Prerequisites

Asterisk is a self-hosted, open-source telephony platform, so there is no provider account or API key to configure. You need:
  1. An Asterisk server with a WebSocket channel configured. The serializer and transport are based on the Asterisk WebSocket channel.
  2. slin-encoded audio: The serializer works with slin audio, since Asterisk natively supports all flavors of slin and Pipecat audio frames must be slin-encoded. Transcode on the Asterisk side if you need a different codec.
The repository includes an example docker-compose.yml and Asterisk configuration files under examples/pipecat_asterisk/ to spin up a local testing environment. See the source repository for details.

Configuration

AsteriskFrameSerializer is constructed with a single optional parameter:
sample_rate
int
default:"0"
Sample rate in kHz used by the Asterisk channel. When left at 0, it is populated during setup or from the Asterisk MEDIA_START event. Supported slin sample rates are 12, 16, 24, 32, 44, 48, 96, 192, 128 kHz.
This serializer does not use the Pipecat Settings dataclass pattern. See the source repository for the authoritative, up-to-date implementation.

Usage

Pass the serializer to a FastAPIWebsocketTransport through FastAPIWebsocketParams, then build your pipeline as usual:
from fastapi import WebSocket
from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.task import PipelineTask
from pipecat.transports.websocket.fastapi import (
    FastAPIWebsocketTransport,
    FastAPIWebsocketParams,
)
from pipecat_asterisk import AsteriskFrameSerializer


async def run_bot(websocket: WebSocket):
    transport = FastAPIWebsocketTransport(
        websocket=websocket,
        params=FastAPIWebsocketParams(
            serializer=AsteriskFrameSerializer(),
            audio_in_enabled=True,
            audio_out_enabled=True,
        ),
    )

    pipeline = Pipeline(
        [
            transport.input(),
            # ... VAD, STT, LLM, TTS, etc.
            transport.output(),
        ]
    )

    task = PipelineTask(pipeline)
    # ... run the pipeline
The package also ships an AsteriskWebsocketTransport, which wraps this serializer together with flow-control logic for managing buffer utilization between Pipecat and Asterisk. See the source repository for the full example.

Compatibility

Tested with Pipecat v1.1.0 and Python 3.12+. Check the source repository for the latest tested version and changelog.