Skip to main content

Prerequisites

Before you begin, ensure you have:
  • A Cartesia API key (Sign up here)
  • Node.js 18+ or Python 3.8+
  • Basic understanding of async/await patterns

Installation

Basic Setup

1

Initialize the Client

2

Choose a Voice

3

Generate Speech

Streaming Integration

For real-time applications like CARTER:

WebSocket Integration

For lowest latency (like CARTER’s voice interface):

Adding Emotions

Control voice emotions like CARTER:

Available Emotions

  • positivity (lowest, low, high, highest)
  • curiosity
  • surprise
  • anger
  • sadness

Error Handling

Implement robust error handling:

Rate Limiting

Handle rate limits gracefully:

Best Practices

Use the same context_id for related messages to maintain conversation flow and improve latency.
  • Use PCM for lowest latency
  • Use MP3 for file storage
  • Match sample rate to your playback system
Implement reconnection logic for WebSocket connections:
Fetch and cache voice IDs at startup rather than on each request.

Next Steps

Voice API Reference

Detailed API documentation

Code Examples

Working code samples
For production use, always implement proper error handling, rate limiting, and monitoring.