Skip to main content

Overview

Generate speech with different language accents. The language parameter controls the accent/pronunciation style of the output. The TTS API speaks the text you provide - it does not translate. To speak in a different language, provide input text in that language. For automatic translation + speech, use the Translated TTS API.

Hear the Difference

Same text, different accents - all with the same voice:

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
import asyncio
from camb.client import AsyncCambAI, save_async_stream_to_file
from camb.types import StreamTtsOutputConfiguration

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

# Languages to generate
LANGUAGES = [
    ("en-us", "English"),
    ("es-es", "Spanish"),
    ("fr-fr", "French"),
    ("pt-br", "Portuguese"),
]

async def generate_language(text, lang_code, lang_name):
    """Generate TTS for a single language"""
    print(f"Generating {lang_name}...")
    response = client.text_to_speech.tts(
        text=text,
        language=lang_code,
        speech_model="mars-flash",
        voice_id=144300,  # Replace with your voice ID
        output_configuration=StreamTtsOutputConfiguration(format="wav")
    )
    filename = f"output_{lang_code}.wav"
    await save_async_stream_to_file(response, filename)
    print(f"  Saved: {filename}")
    return filename

async def main():
    text = "Welcome to our service. We're glad to have you here."

    print(f"Generating TTS in {len(LANGUAGES)} languages...\n")

    # Generate all languages concurrently
    tasks = [
        generate_language(text, code, name)
        for code, name in LANGUAGES
    ]
    files = await asyncio.gather(*tasks)

    print(f"\nDone! Generated {len(files)} audio files.")

asyncio.run(main())

Supported Accents

Over 140 language accents are supported. Common codes:
AccentCode
English (US)en-us
English (UK)en-gb
Spanish (Spain)es-es
Spanish (Mexico)es-mx
Frenchfr-fr
Germande-de
Italianit-it
Portuguese (Brazil)pt-br
Japaneseja-jp
Koreanko-kr
Chinese (Mandarin)zh-cn
Hindihi-in
Arabicar-sa
Russianru-ru
See API Reference for the full list.

Use Cases


Next Steps

Emotional Voice Control

Add emotional expression and character to your speech with mars-instruct.

Translated TTS

Translate text and generate speech in the target language.

Voice Cloning

Clone a voice from reference audio.

Text to Sound Effects

Generate sound effects and music from text.

API Reference

Full TTS streaming API specification.