Overview
The Camb.ai Browser SDK is designed for client-side applications, providing a simple, type-safe interface to integrate high-quality text-to-speech directly into your web apps.Installation
Authentication
[!CAUTION] Security Warning: Hardcoding your API key in client-side code (HTML/JS) is not secure. Anyone visiting your site can inspect the source code and steal your key, which can lead to unauthorized usage and charges.
Recommended: Backend Proxy
For production applications, it is highly recommended to route requests through a secure backend proxy:- Store your Camb.ai API key securely on your server (e.g., in environment variables).
- Set up an endpoint on your server that forwards requests to Camb.ai and adds the
x-api-keyheader. - Implement authentication on your server to control who can use the TTS services.
Development Only (Direct Client)
Use the API key directly only for local development or prototyping:Quick Start
Streaming Text-to-Speech
Generate and play speech directly in the browser: (Assumesclient is initialized as shown in the Authentication section).
Using the Helper Function
The SDK’stts method returns binary data that can be easily converted to a URL for playback:
Choosing a Model
Camb.ai offers three MARS models optimized for different use cases:MARS Flash
Sample rate: 22.05kHz
MARS Pro
Sample rate: 48kHz
MARS Instruct
Sample rate: 22.05kHz
Listing Available Voices
Discover available voices for your application:Language Support
Camb.ai supports 140+ languages. Specify the language using theLanguages enum exports:
Languages supported by each model mentioned at MARS Models.
Error Handling
Handle common errors gracefully:Using Custom Provider
For more details check this guide Custom Cloud ProvidersBaseten Deployment
Initialize the client with provider configuration. Baseten Provider ExampleNext Steps
Voice Agents
Build real-time voice agents with Pipecat
LiveKit Integration
Create voice agents with LiveKit
API Reference
Explore the full TTS API
Voice Library
Browse available voices