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

Overview

The Camb.ai Go 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

go get github.com/camb-ai/cambai-go-sdk

Authentication

Get your API key from CAMB.AI Studio and set it as an environment variable:
export CAMB_API_KEY=your_api_key_here
Or use a .env file or load it directly in your code.

Quick Start

Streaming Text-to-Speech

Generate and stream speech in real-time:
package main

import (
	"context"
	"io"
	"os"

	"github.com/camb-ai/cambai-go-sdk"
	"github.com/camb-ai/cambai-go-sdk/client"
	"github.com/camb-ai/cambai-go-sdk/option"
)

func main() {
	// Initialize the client
	c := client.NewClient(
		option.WithAPIKey(os.Getenv("CAMB_API_KEY")),
	)

	// Stream TTS audio
	stream, err := c.TextToSpeech.Tts(
		context.Background(),
		&cambai.CreateStreamTtsRequestPayload{
			Text:     "Hello! Welcome to Camb.ai text-to-speech.",
			VoiceID:     147320,
			Language:    cambai.CreateStreamTtsRequestPayloadLanguageEnUs,
			SpeechModel: cambai.CreateStreamTtsRequestPayloadSpeechModelMarsFlash.Ptr(),
			OutputConfiguration: &cambai.StreamTtsOutputConfiguration{
				Format: cambai.OutputFormatWav.Ptr(),
			},
		},
	)
	if err != nil {
		panic(err)
	}

	// Save to file
	outFile, _ := os.Create("output.wav")
	defer outFile.Close()
	io.Copy(outFile, stream)
}

Using the Helper Function

Since the SDK returns an io.Reader, you can use this helper to save streams easily:
func SaveStreamToFile(stream io.Reader, filename string) error {
	f, err := os.Create(filename)
	if err != nil {
		return err
	}
	defer f.Close()
	_, err = io.Copy(f, stream)
	return err
}

// Usage:
stream, _ := client.TextToSpeech.Tts(...)
SaveStreamToFile(stream, "output.wav")

Choosing a Model

Camb.ai offers three MARS models optimized for different use cases:
stream, _ := c.TextToSpeech.Tts(ctx, &cambai.CreateStreamTtsRequestPayload{
    Text:        "Fast and efficient speech synthesis.",
    Language:    cambai.CreateStreamTtsRequestPayloadLanguageEnUs,
    VoiceID:     147320,
    SpeechModel: cambai.CreateStreamTtsRequestPayloadSpeechModelMarsFlash.Ptr(),
})
// Best for: Real-time voice agents, low-latency applications
// Sample rate: 22.05kHz

Listing Available Voices

Discover available voices for your application:
voices, _ := c.VoiceCloning.ListVoices(
    context.Background(),
    &cambai.ListVoicesListVoicesGetRequest{},
)

for _, voice := range voices {
    fmt.Printf("ID: %d, Name: %s, Gender: %v\n", voice.ID, voice.VoiceName, voice.Gender)
}

Language Support

Camb.ai supports 140+ languages. Specify the language using the provided constants: Languages supported by each model mentioned at MARS Models.
// English (US)
c.TextToSpeech.Tts(ctx, &cambai.CreateStreamTtsRequestPayload{
    Language: cambai.CreateStreamTtsRequestPayloadLanguageEnUs,
    // ...
})

// Spanish
c.TextToSpeech.Tts(ctx, &cambai.CreateStreamTtsRequestPayload{
    Language: cambai.CreateStreamTtsRequestPayloadLanguageEsEs,
    // ...
})

Error Handling

Handle common errors gracefully:
stream, err := c.TextToSpeech.Tts(ctx, request)
if err != nil {
    fmt.Printf("Error generating speech: %v\n", err)
    return
}

Using Custom Provider

For more details check this guide Custom Cloud Providers

Baseten Deployment

Initialize the client with your API key and the specific model URL. Baseten Provider Example
var ttsProvider provider.TtsProvider = &BasetenProvider{
	APIKey:            "YOUR_BASETEN_API_KEY",
	URL:               "YOUR_BASETEN_URL",
	ReferenceAudio:    "YOUR_REFERENCE_AUDIO", // Public URL or base64-encoded audio file
	ReferenceLanguage: "en-us",
}

req := &cambai.CreateStreamTtsRequestPayload{
	Text:     "Hello from Go Custom Provider!",
	Language: cambai.CreateStreamTtsRequestPayloadLanguageEnUs,
}

stream, err := ttsProvider.Tts(context.Background(), req)
if err != nil {
	fmt.Printf("Error generating speech: %v\n", err)
	return
}

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