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, the input text must be in that language. For automatic translation + speech, use the Translated TTS API.

Python

import os
import asyncio
from camb.client import AsyncCambAI, save_async_stream_to_file
from camb.types.stream_tts_output_configuration import StreamTtsOutputConfiguration

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

# Languages to generate
LANGUAGES = [
    ("en-us", "English"),
    ("es-es", "Spanish"),
    ("fr-fr", "French"),
    ("de-de", "German"),
    ("ja-jp", "Japanese"),
    ("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())

TypeScript

import { CambClient, saveStreamToFile } from '@camb-ai/sdk';

const client = new CambClient({
    apiKey: process.env.CAMB_API_KEY
});

// Languages to generate
const LANGUAGES = [
    { code: 'en-us', name: 'English' },
    { code: 'es-es', name: 'Spanish' },
    { code: 'fr-fr', name: 'French' },
    { code: 'de-de', name: 'German' },
    { code: 'ja-jp', name: 'Japanese' },
    { code: 'pt-br', name: 'Portuguese' },
];

async function generateLanguage(text, langCode, langName) {
    console.log(`Generating ${langName}...`);
    const response = await client.textToSpeech.tts({
        text: text,
        language: langCode,
        speech_model: 'mars-flash',
        voice_id: 144300  // Replace with your voice ID
    });
    const filename = `output_${langCode}.wav`;
    await saveStreamToFile(response, filename);
    console.log(`  Saved: ${filename}`);
    return filename;
}

async function main() {
    const text = "Welcome to our service. We're glad to have you here.";

    console.log(`Generating TTS in ${LANGUAGES.length} languages...\n`);

    // Generate all languages concurrently
    const promises = LANGUAGES.map(lang =>
        generateLanguage(text, lang.code, lang.name)
    );
    const files = await Promise.all(promises);

    console.log(`\nDone! Generated ${files.length} audio files.`);
}

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

  • Accent Variation: Same English text spoken with different accents
  • Character Voices: Give characters regional accents
  • Language Learning: Hear pronunciation differences across accents
  • Localized Feel: Match accent to target audience region