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

Overview

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

Installation

Install the package via NuGet:
dotnet add package CambApi

Authentication

Get your API key from CAMB.AI Studio and set it as an environment variable:
export CAMB_API_KEY=your_api_key_here

Quick Start

Streaming Text-to-Speech

Generate and stream speech in real-time. The SDK returns a Stream for the audio data:
using CambApi;

// Initialize the client
var client = new CambApiClient(Environment.GetEnvironmentVariable("CAMB_API_KEY"));

// Stream TTS audio
var responseStream = await client.TextToSpeech.TtsAsync(new CreateStreamTtsRequestPayload
{
    Text = "Hello! Welcome to Camb.ai text-to-speech.",
    Language = CreateStreamTtsRequestPayloadLanguage.EnUs,
    VoiceId = 147320,
    SpeechModel = CreateStreamTtsRequestPayloadSpeechModel.MarsFlash,
    OutputConfiguration = new StreamTtsOutputConfiguration
    {
        Format = OutputFormat.Wav
    }
});

// Save to file
using var fileStream = File.Create("output.wav");
await responseStream.CopyToAsync(fileStream);

Console.WriteLine("Success! Audio saved to output.wav");

Using the Helper Function

You can easily wrap the stream saving into a helper method:
public static async Task SaveStreamToFileAsync(Stream stream, string filename)
{
    using var fileStream = File.Create(filename);
    await stream.CopyToAsync(fileStream);
}

// Usage:
var stream = await client.TextToSpeech.TtsAsync(payload);
await SaveStreamToFileAsync(stream, "output.wav");

Choosing a Model

Camb.ai offers three MARS models optimized for different use cases:
SpeechModel = CreateStreamTtsRequestPayloadSpeechModel.MarsFlash
// Best for: Real-time voice agents, low-latency applications
// Sample rate: 22.05kHz

Listing Available Voices

Discover available voices for your application:
var voices = await client.VoiceCloning.ListVoicesAsync();

foreach (var voice in voices)
{
    Console.WriteLine($"ID: {voice.Id}, Name: {voice.VoiceName}, Gender: {voice.Gender}");
}

Language Support

Camb.ai supports 140+ languages. Specify the language using the CreateStreamTtsRequestPayloadLanguage enum: Languages supported by each model mentioned at MARS Models.
// English (US)
Language = CreateStreamTtsRequestPayloadLanguage.EnUs

// Spanish
Language = CreateStreamTtsRequestPayloadLanguage.EsEs

// French
Language = CreateStreamTtsRequestPayloadLanguage.FrFr

Error Handling

Handle common errors gracefully:
try 
{
    var stream = await client.TextToSpeech.TtsAsync(payload);
}
catch (Exception ex)
{
    Console.WriteLine($"Error generating speech: {ex.Message}");
}

Using Custom Provider

For more details check this guide Custom Cloud Providers

Baseten Deployment

Initialize the client with your custom provider implementation. Baseten Provider Example
using CambApi.Providers;

var ttsProvider = new BasetenProvider(
    apiKey: "YOUR_BASETEN_API_KEY",
    url: "YOUR_BASETEN_URL"
);

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