Skip to main content
Get started with the Camb.ai C++ SDK in minutes

Overview

The Camb.ai C++ SDK provides a high-performance interface to integrate text-to-speech into your applications. This quickstart will have you generating speech in under 5 minutes.

Installation

Prerequisites

  • CMake (3.10+)
  • cpprestsdk (libcpprest-dev)
  • Boost (libboost-all-dev)
  • OpenSSL (libssl-dev)

Installation Steps

  1. Clone the repository:
git clone https://github.com/Camb-ai/cambai-cpp-sdk.git
  1. Add to your CMakeLists.txt:
add_subdirectory(cambai-cpp-sdk)
target_link_libraries(your_app PRIVATE CppRestOpenAPIClient)

Authentication

Get your API key from CAMB.AI Studio and initialize the client:
#include "CambAIClient.h"

cambai::CambAIClient client("your_api_key_here");

Quick Start

Streaming Text-to-Speech

Generate speech and handle the response stream. This example shows how to initiate the request:
#include "CambAIClient.h"
#include <iostream>

using namespace cambai;
using namespace org::openapitools::client::model;

int main() {
    CambAIClient client(getenv("CAMB_API_KEY"));

    auto payload = std::make_shared<CreateStreamTTSRequestPayload>();
    payload->setText(utility::conversions::to_string_t("Hello! Welcome to Camb.ai."));
    payload->setVoiceId(147320);
    
    auto lang = std::make_shared<Languages>();
    lang->setValue(Languages::eLanguages::EN_US);
    payload->setLanguage(lang);
    
    payload->setSpeechModel(utility::conversions::to_string_t("mars-flash"));

    try {
        auto task = client.getTextToSpeechApi()->ttsTtsStreamPost(payload);
        auto result = task.get();
        // Result contains the audio data
        std::cout << "Successfully initiated TTS stream." << std::endl;
    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
    }

    return 0;
}

Choosing a Model

Camb.ai offers three MARS models optimized for different use cases:
payload->setSpeechModel(utility::conversions::to_string_t("mars-flash"));
// Best for: Real-time voice agents, low-latency applications
// Sample rate: 22.05kHz

Listing Available Voices

Discover available voices for your application:
auto task = client.voiceCloning()->listVoicesListVoicesGet();
auto voices = task.get();

for (const auto& voice : voices) {
    std::cout << "ID: " << voice->getId() << ", Name: " << utility::conversions::to_utf8string(voice->getVoiceName()) << std::endl;
}

Language Support

Specify the language using the Languages enum wrapper:
auto lang = std::make_shared<Languages>();
lang->setValue(Languages::eLanguages::EN_US); // English (US)
payload->setLanguage(lang);

lang->setValue(Languages::eLanguages::ES_ES); // Spanish
payload->setLanguage(lang);

Error Handling

The SDK uses asynchronous tasks (pplx::task). Use .get() within a try-catch block to handle errors:
try {
    auto result = client.tts()->ttsTtsStreamPost(payload).get();
} catch (const std::exception& e) {
    std::cerr << "Exception: " << e.what() << std::endl;
}

Using Custom Provider

Baseten Deployment

Initialize the client with your custom provider implementation. Baseten Provider Example
auto baseten = std::make_shared<BasetenProvider>("YOUR_BASETEN_API_KEY", "YOUR_BASETEN_URL");
client.setTtsProvider(baseten);

Next Steps

https://mintcdn.com/cambai/2LvnefIkletroPxv/images/pipecat-orange.svg?fit=max&auto=format&n=2LvnefIkletroPxv&q=85&s=40cf8e001b8cadc8a4c3c557dea603d5

Voice Agents

Build real-time voice agents with Pipecat
https://mintcdn.com/cambai/2LvnefIkletroPxv/images/livekit-orange.svg?fit=max&auto=format&n=2LvnefIkletroPxv&q=85&s=c750fcee9b1de69e3c1d0d6ec7eb6b3f

LiveKit Integration

Create voice agents with LiveKit

API Reference

Explore the full TTS API

Voice Library

Browse available voices

Resources