Skip to main content

Overview

Generate natural-sounding speech from text using the CAMB.AI SDK. This tutorial covers installation, generating your first audio, choosing a model, and listing voices.

Listen to an Example

Prerequisites

1

Create an account

Sign up at CAMB.AI Studio if you haven’t already.
2

Get your API key

Go to Settings → API Keys in Studio and copy your key. See Authentication for details.
3

Install the SDK

pip install camb-ai
Skip this step if you’re using the direct API.
4

Set your API key to use in your code

export CAMB_API_KEY="your_api_key_here"

Code

import os
from camb.client import CambAI, save_stream_to_file
from camb.types import StreamTtsOutputConfiguration

client = CambAI(api_key=os.getenv("CAMB_API_KEY"))

# Generate speech and save to file
response = client.text_to_speech.tts(
    text="Welcome to our service. We're glad to have you here.",
    voice_id=147320,
    language="en-us",
    speech_model="mars-flash",
    output_configuration=StreamTtsOutputConfiguration(format="wav")
)

save_stream_to_file(response, "output.wav")
print("Audio saved to output.wav")

Choosing a Model

CAMB.AI offers three MARS 8 model variants:
ModelBest ForSample Rate
mars-flashReal-time voice agents, low-latency apps22.05 kHz
mars-proAudio production, high-quality content48 kHz
mars-instructFine-grained control over tone and style22.05 kHz
mars-instruct accepts a user_instructions parameter to control delivery:
response = client.text_to_speech.tts(
    text="We just shipped the feature, and the response has been fantastic!",
    voice_id=147320,
    language="en-us",
    speech_model="mars-instruct",
    user_instructions="Speak in an excited, upbeat tone",
    output_configuration=StreamTtsOutputConfiguration(format="wav")
)

save_stream_to_file(response, "excited.wav")
See Choosing a Model for a detailed comparison.

Listing Voices

List available voices to find the right one for your use case:
voices = client.voice_cloning.list_voices()

for voice in voices[:10]:
    print(f"ID: {voice['id']}, Name: {voice['voice_name']}, Gender: {voice['gender']}")

Parameters

Required

ParameterTypeDescription
textstringText to convert to speech (min 3 characters)
voice_idintegerVoice ID to use (e.g., 147320)

Optional

ParameterTypeDefaultDescription
languagestring"en-us"BCP-47 language code
speech_modelstring"mars-flash"mars-flash, mars-pro, or mars-instruct
output_configurationobject{}Output format: wav, mp3, or pcm_s16le
user_instructionsstring-Tone/style guidance (mars-instruct only)

mars-instruct supports embedded emotion tags and SSML-style breaks for fine-grained control. See Emotional Voice Control for examples.

Next Steps