Skip to main content

pipecat-sonex

SonexLabs TTS for pipecat-ai real-time voice pipelines.

PyPI Python License: MIT


pipecat-sonex provides SonexTTSService — a pipecat-native TTS service that connects any pipecat pipeline to the SonexLabs Panini TTS API.

SonexTTSService extends pipecat's official TTSService base class, so it works exactly like CartesiaTTSService, ElevenLabsTTSService, and other first-party services:

  • The base class handles sentence aggregation, LLM token buffering, interruption recovery, TTSStartedFrame / TTSStoppedFrame, and metrics.
  • You only need to configure credentials and voice.
  • Voice and language can be changed mid-conversation via TTSUpdateSettingsFrame.

Streaming and connection reuse

Requests go to SonexLabs' /v1/speech/stream endpoint, so audio is delivered as chunked HTTP as soon as each sentence is generated instead of waiting for the full utterance, reducing time-to-first-audio. The underlying aiohttp.ClientSession uses a TCPConnector with keepalive_timeout set, so connections are pooled and reused across requests rather than reconnecting for every sentence.


Installation

pip install pipecat-sonex
# or
uv add pipecat-sonex

Quick start

1. List available voices

curl https://api.sonexlabs.com/v1/voices \
  -H "Authorization: Bearer $SONEX_API_KEY"

Copy a voice_id from the response — it is required.

2. Add to your pipeline

from pipecat_sonex import SonexTTSService

tts = SonexTTSService(
    api_key="vsk_...",
    voice="72ly9crx9v",     # from GET /v1/voices — required, no default
    language="en",          # optional, leave unset to auto-detect
    sample_rate=24000,      # 24000 for WebRTC, 8000 for telephony
)

Drop it into any pipeline the same way as any other pipecat TTS service:

pipeline = Pipeline([
    transport.input(),
    stt,
    context_aggregator.user(),
    llm,
    tts,                    # ← SonexTTSService here
    transport.output(),
    context_aggregator.assistant(),
])

Constructor parameters

Parameter Type Default Description
api_key str SonexLabs API key (vsk_...)
voice str Required. Voice ID from GET /v1/voices
language str "" Language code ("en", "hi", "te", …). Leave unset to auto-detect.
speed float 1.0 Speech rate multiplier (practical range: 0.75–1.5)
sample_rate int 24000 Pipeline output rate in Hz. Not sent to the API — Panini always returns audio at its native rate; pipecat resamples to this value. Use 8000 for Twilio/Exotel telephony.
endpoint str https://api.sonexlabs.com API base URL
settings SonexTTSSettings None Runtime-updatable settings (takes precedence)

Runtime settings update

Change voice or language mid-conversation:

from pipecat.frames.frames import TTSUpdateSettingsFrame
from pipecat_sonex import SonexTTSSettings

await task.queue_frames([
    TTSUpdateSettingsFrame(delta=SonexTTSSettings(voice="lkwlapu6ab", language="hi"))  # Priya, from GET /v1/voices
])

Examples

All examples are in the examples/ directory. Copy .env.example to .env and fill in your credentials before running.

WebRTC + OpenAI LLM

Full browser-to-server voice bot using SmallWebRTC transport:

pip install "pipecat-ai[openai,deepgram,silero,webrtc]" pipecat-sonex python-dotenv fastapi uvicorn
python examples/webrtc_openai.py
# Open http://localhost:7860 and click Connect

Twilio telephony

pip install "pipecat-ai[openai,deepgram,silero,twilio]" pipecat-sonex python-dotenv fastapi uvicorn
python examples/telephony_twilio.py
# Expose with ngrok, point Twilio webhook to https://<host>/incoming-call

Exotel telephony

pip install "pipecat-ai[openai,deepgram,silero]" pipecat-sonex python-dotenv fastapi uvicorn
python examples/telephony_exotel.py
# Expose with ngrok, set Exotel Passthru URL to wss://<host>/ws/exotel

Vobiz telephony

VobizFrameSerializer is bundled in pipecat_sonex.vobiz — no extra package needed:

pip install "pipecat-ai[openai,deepgram,silero]" pipecat-sonex python-dotenv fastapi uvicorn
python examples/telephony_vobiz.py
# Set Vobiz WebSocket URL to wss://<host>/ws/vobiz

LiveKit

For a LiveKit room-based voice bot example, see the separate pipecat-sonex-livekit repo.


API reference

See the full API documentation at docs.sonexlabs.com/api-reference.


License

MIT — see LICENSE.

Download files

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

Source Distribution

pipecat_sonex-0.2.2.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

pipecat_sonex-0.2.2-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file pipecat_sonex-0.2.2.tar.gz.

File metadata

  • Download URL: pipecat_sonex-0.2.2.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.12

File hashes

Hashes for pipecat_sonex-0.2.2.tar.gz
Algorithm Hash digest
SHA256 0840f56ed418b64b38a2c266d4c2b854edca3b1e4e709cf89baf5e657fc0d28f
MD5 6a1e6c44cc04ff87db3c48d9b436c17e
BLAKE2b-256 3d24e62bf95c7164c817baad8a7670702a7554c816b4f1b0e85c3fa52bef922f

See more details on using hashes here.

File details

Details for the file pipecat_sonex-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pipecat_sonex-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.12

File hashes

Hashes for pipecat_sonex-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1a87c4420c359bc2fa59e3573948015598a0bf3e1b8eda9c5850db1eaf9a4fcb
MD5 1cfd7bef761e3a7886858473054ebc12
BLAKE2b-256 c9d8fd82f32f1e324a5edfe766009aded041166a8c87b8eb31259f464e2af162

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