Skip to main content

This package provides a WebSocket transport for integrating Pipecat applications with Asterisk websocket channel, enabling real-time audio streaming and signalling interaction between Asterisk and Pipecat applications.

Project description

pipecat-asterisk

A Pipecat community integration for Asterisk. This repository provides a transport and frame serializer to connect your Asterisk with Pipecat pipelines.

Features

  • AsteriskWebsocketTransport: Handles raw audio streaming and lifecycle events natively with Asterisk.
  • AsteriskFrameSerializer: Serializer to translate Asterisk websocket JSON or plain-text payloads and raw(audio) payloads into Pipecat frames.
  • Flow Control: Built-in logic to manage buffer utilization between the Pipecat application and Asterisk.

Installation

uv add pipecat-asterisk

(Or use pip install pipecat-asterisk if you are using pip for dependency management)

Usage

Here is a basic example of how to integrate the Asterisk WebSocket transport into a Pipecat pipeline:

from fastapi import FastAPI, WebSocket
from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.task import PipelineTask
from pipecat_asterisk import AsteriskWebsocketTransport

app = FastAPI()

@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
    await websocket.accept()
    
    # Initialize the Asterisk Transport
    ws_transport = AsteriskWebsocketTransport(websocket=websocket)
    
    # Build your Pipecat pipeline
    pipeline = Pipeline([
        ws_transport.input(),
        # ... other pipeline components (VAD, LLM, TTS, etc.)
        ws_transport.output(),
    ])
    
    task = PipelineTask(pipeline)
    
    # Run the pipeline
    # ...

Running the Example

An example Gemini-based voice bot is provided in examples/pipecat_asterisk/.

1. Configure Asterisk

The examples/pipecat_asterisk/ directory includes a docker-compose.yml and Asterisk configuration files in etc/ to easily spin up a local Asterisk testing environment. After the Docker container is running you can connect any sip client to localhost:5060 with the credentials specified in etc/asterisk/pjsip.conf (user: 1, password: 1). There are a few extensions configured in etc/asterisk/extensions.conf that you can use to test the bot, every extension represents a respective sampling rate.

exten = 8,1,Dial(WebSocket/pipecat/c(slin))
exten = 12,1,Dial(WebSocket/pipecat/c(slin12))
exten = 16,1,Dial(WebSocket/pipecat/c(slin16))
exten = 24,1,Dial(WebSocket/pipecat/c(slin24))
...

To run the Asterisk server with the provided configuration:

cd examples/pipecat_asterisk
docker-compose up -d

2. Set API Keys

The example uses Google's Gemini for conversational AI. Create a .env file or export your key directly:

export GOOGLE_API_KEY="your-google-api-key"

3. Run the application

Run the WebSocket server:

uv sync
uv run examples/pipecat_asterisk/ws_server.py

Compatibility

  • Tested with Pipecat v1.1.0
  • Requires Python 3.12+

Internal Architecture

The transport and the serializer are designed to work with slin encoded audio, because Asterisk natively supports all the flavors of slin and Pipecat's audio frames require to be slin-encoded. If you need to use a different codec, you can transcode on the Asterisk side, it's computationally more efficient and simplifies the transport and serializer logic.

Serializer and the transport implementation are based on the Asterisk websocket channel documentation.

The transport supports flow control logic to manage the buffer utilization between the Pipecat application and Asterisk. This ensures that we don't overwhelm the Asterisk server with too much data at once, while also ensuring that we send data as soon as there is capacity in the remote buffer. The output transport create an instance of flow controller and adds serialized (and resampled if needed) audio frames to the flow controller. The flow controller then decides when to send data to Asterisk based on the current buffer utilization and the amount of data in the local buffer. The flow control logic is as follows:

Flow control logic

flowchart TD
    C{Remote buffer utilization < <br>low water}
    C -->|yes| D{There are bytes in local buffer}
    C -->|no| H{Remote buffer utilization > <br>high water}
    H -->|yes| E[Skip]
    D -->|yes| F[Send up to MAX_WS_SEND <br> bytes from local buffer]
    D -->|no| E
    H -->|no| I{Do we have more than <br>MIN_BATCH bytes in local <br>buffer}
    I -->|yes| F
    I -->|no| E

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pipecat_asterisk-0.1.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pipecat_asterisk-0.1.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file pipecat_asterisk-0.1.0.tar.gz.

File metadata

  • Download URL: pipecat_asterisk-0.1.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pipecat_asterisk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f50c6cb5344ef619d724f8a69ea6268f0f4b125c5e2b50579719ea703502f234
MD5 203d6470f771fda427a8477a9b0e4bf3
BLAKE2b-256 0b62e08925534533ca929f2aff8619e934d6d7e1570f7cb229bcbb165a2a197b

See more details on using hashes here.

File details

Details for the file pipecat_asterisk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pipecat_asterisk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pipecat_asterisk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 479ba0f49e164148319c467dda31dd8268c91fa41606195dd9830809360fd56f
MD5 3d3e06a14e715a5c61333059f22a2c37
BLAKE2b-256 8f059c8dd22165c06fdf4e657128fc4c8782c0f93df0fb84f745b3695cdfcfb0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page