Skip to main content

Bandwidth Programmable Voice telephony serializer for Pipecat

Project description

pipecat-bandwidth

A Pipecat community integration that lets you use Bandwidth Programmable Voice as the telephony layer for your Pipecat voice bots.

This package provides BandwidthFrameSerializer, a FrameSerializer you plug into a FastAPIWebsocketTransport to handle Bandwidth's bidirectional WebSocket media stream protocol.

Maintained by Bandwidth.

What it does

  • Decodes Bandwidth's inbound μ-law audio (8 kHz) into Pipecat audio frames.
  • Encodes outbound audio as either μ-law or linear PCM at 8/16/24 kHz. PCM at 24 kHz noticeably improves TTS quality compared to μ-law.
  • Handles interruptions by emitting Bandwidth's clear event, so the bot stops talking immediately when the caller speaks.
  • Auto hangs up the call via the Bandwidth Voice API on EndFrame or CancelFrame, using OAuth 2.0 client_credentials.

Installation

pip install pipecat-bandwidth

Or with uv:

uv add pipecat-bandwidth

Usage

from pipecat.transports.websocket.fastapi import (
    FastAPIWebsocketParams,
    FastAPIWebsocketTransport,
)
from pipecat_bandwidth import BandwidthFrameSerializer

# IMPORTANT: call_id and account_id flow into an authenticated POST to the
# Bandwidth Voice API on auto hang-up. They MUST come from a server-trusted
# source — typically the (authenticated) inbound voice webhook body — and
# NOT from the WebSocket "start" event's metadata, which is unauthenticated
# and attacker-controllable. See the chatbot example for one safe pattern
# (token-in-URL correlating the webhook to the WS connect).
serializer = BandwidthFrameSerializer(
    stream_id=stream_id,
    call_id=call_id,
    account_id=account_id,
    client_id=os.getenv("BANDWIDTH_CLIENT_ID"),
    client_secret=os.getenv("BANDWIDTH_CLIENT_SECRET"),
)

transport = FastAPIWebsocketTransport(
    websocket=websocket,
    params=FastAPIWebsocketParams(
        audio_in_enabled=True,
        audio_out_enabled=True,
        add_wav_header=False,
        serializer=serializer,
    ),
)

For higher-fidelity outbound audio, configure linear PCM:

from pipecat_bandwidth import BandwidthFrameSerializer

serializer = BandwidthFrameSerializer(
    stream_id=stream_id,
    call_id=call_id,
    account_id=account_id,
    client_id=os.getenv("BANDWIDTH_CLIENT_ID"),
    client_secret=os.getenv("BANDWIDTH_CLIENT_SECRET"),
    params=BandwidthFrameSerializer.InputParams(
        outbound_encoding="PCM",
        outbound_pcm_sample_rate=24000,
    ),
)

Example

A complete end-to-end example lives in examples/bandwidth-chatbot. It shows a single-file FastAPI server that:

  1. Returns a <StartStream> BXML response on Bandwidth's voice webhook.
  2. Accepts the bidirectional WebSocket and reads Bandwidth's start event for the stream/call/account IDs.
  3. Runs a Deepgram (STT) → OpenAI (LLM) → Cartesia (TTS) Pipecat pipeline.

See the example's README for setup and run instructions.

DTMF

Bandwidth does not deliver DTMF over the media-stream WebSocket. DTMF is captured by the BXML <Gather> verb and posted to a separate webhook. Wire DTMF handling in your application's webhook handler — not in the serializer.

Compatibility

  • Tested with Pipecat v1.1.0.
  • Python 3.11, 3.12.

Links

License

BSD 2-Clause. See LICENSE.

Contributing

Issues and PRs are welcome. For larger changes, please open an issue first to discuss what you'd like to change.

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_bandwidth-0.1.0.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

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

pipecat_bandwidth-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pipecat_bandwidth-0.1.0.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pipecat_bandwidth-0.1.0.tar.gz
Algorithm Hash digest
SHA256 be3571a7b01c56945421a6b55ce4bd4277702ee7083ccf871d94740800af74bf
MD5 a6d8e06d35b7e27f6bd8769ab9727d21
BLAKE2b-256 669a8a5900ffd3c60ca2b0c40348394367f0931f8d2244fc424b6113c7eab408

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pipecat_bandwidth-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pipecat_bandwidth-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a09629953a87076163345d79ddba673de687fe364e07368a579d29db672e1bfe
MD5 ab6bc1246ee3cd05e6086dbf074de59d
BLAKE2b-256 bd06779fd7e7fc36d8b1e76316b2a3e4f6ab9e1f329a367e83032e639505c250

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