Skip to main content

Cartesia plugin for GetStream

Project description

Cartesia Text-to-Speech Plugin

High-quality Text-to-Speech (TTS) plugin for GetStream backed by the Cartesia Sonic model. It lets a Python process speak PCM audio into a Stream call.

Installation

Install from PyPI (installs both getstream and the Cartesia SDK):

pip install "getstream-plugins-cartesia[webrtc]"

If you already have the Stream SDK in your project just add the Cartesia plugin:

pip install cartesia getstream-plugins-cartesia

Usage

from getstream.plugins.cartesia import CartesiaTTS
from getstream.video.rtc.audio_track import AudioStreamTrack

async def speak():
    # Option A: read key from env var (CARTESIA_API_KEY)
    tts = CartesiaTTS()

    # Option B: pass explicitly
    # tts = CartesiaTTS(api_key="<your key>")

    # Audio MUST be 16-kHz, 16-bit PCM (matches Cartesia Sonic model)
    track = AudioStreamTrack(framerate=16000)
    tts.set_output_track(track)

    # Listen for every raw PCM chunk that gets produced
    @tts.on("audio")
    def _on_audio(chunk: bytes, user):
        print("🔊 got", len(chunk), "bytes of audio")

    await tts.send("Hello from Cartesia!")

# Run inside an event-loop, e.g. `asyncio.run(speak())`

Configuration Options

  • api_key (str, optional) – Cartesia API key (falls back to CARTESIA_API_KEY).
  • model_id (str) – Which model to hit ("sonic-2" by default).
  • voice_id (str | None) – Cartesia voice to use (pass None for model default).
  • sample_rate (int) – Target sample-rate in Hz. Must match the AudioStreamTrack.framerate you attach (defaults to 16000). If they don't match a TypeError is raised early so you don't get distorted audio on the call.

Events emitted:

audio – each raw PCM chunk, arguments: chunk: bytes, user: dict | None

error – any exception raised during synthesis

Requirements

  • Python 3.10+
  • cartesia>=2.0.5 (automatically installed)

Testing

Run the offline unit-tests:

pytest -q getstream/plugins/cartesia/tests

To additionally exercise the live Cartesia API set CARTESIA_API_KEY in your environment; the integration test will be executed automatically.


💡 See examples/tts_cartesia/ for a fully-working bot that joins a Stream call and greets participants using this plugin.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

getstream_plugins_cartesia-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for getstream_plugins_cartesia-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2475bb3d3b00459900deffb2656e4cfef08ee152c9e39e283d5a36b6b0459bc6
MD5 3bd07db9f555c4fdc68a63300d04559a
BLAKE2b-256 01726b8a9776a3c489bcc2f50dd0abcc4f6d68220c0bb6a4a3c31c7dc4e12bbf

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