POST
/
tts-stream
curl --request POST \
  --url https://client.camb.ai/apis/tts-stream \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '{
  "text": "<string>",
  "voice_id": 123,
  "language": 1,
  "gender": null,
  "age": 123,
  "output_format": "adts"
}'
This response does not have an example.

This endpoint transforms your text into speech in real-time, delivering audio as it is generated rather than waiting for the entire file to complete. This streaming approach allows for immediate playback and faster integration into your applications.

Personalizing Your Voice

Selecting Voice Characteristics

When creating your speech, you can customize the voice characteristics to match your needs:

  • Gender: Choose the voice gender by providing a simple number:
GenderCorresponding Value
Not Known0
Male1
Female2
Not Applicable9

Finding Your Perfect Voice

You have two options for voices:

  • Select from our extensive library of pre-made voices using the /list-voices endpoint.
  • Create your own custom voice with the /create-custom-voice endpoint for a truly unique sound.

Choosing Your Language

Our platform supports multiple languages for your speech needs. Discover all available options through our /source-languages or /target-languages endpoints.

Understanding the Response

  • When you call this endpoint, you will receive the audio content immediately as it is generated. The audio streams in the format you have specified (default is adts, but you can request other formats).
  • Each response includes an X-Credits-Required header that transparently shows you the resource cost of your request.

Available Output Formats

You can specify your preferred audio format using the output_format parameter:

FormatDescriptionUse Case
wavUncompressed audio format with excellent qualityHigh-fidelity applications, audio editing
flacLossless compressed audio format that maintains high qualityStorage-efficient high-quality audio
adtsStandard streaming audio format with good qualityDefault format, streaming applications
pcm_s16leStandard quality raw audio formatBasic audio processing, lower memory usage
pcm_s32leHigh-quality raw audio formatProfessional audio work, highest quality

Example Code

import requests

# Define what you want to say and how you want it said
tts_payload = {
    "text": "Jupiter, the largest planet in our solar system, is a gas giant with swirling storms like the iconic Great Red Spot.",
    "voice_id": 123,    # Replace with your chosen voice ID
    "language": 1,      # English
    "output_format": "wav"  # Choose your preferred audio format
}

# Set up your API credentials
headers = {
    "x-api-key": "your-api-key",  # Replace with your actual API key
}

# Make the request with streaming enabled
response = requests.post(
    "https://client.camb.ai/apis/tts-stream",
    json=tts_payload,
    headers=headers,
    stream=True  # This tells requests to stream the response
)

# Check if the request was successful
response.raise_for_status()

# Get the credit usage information (optional)
credits_used = response.headers.get('X-Credits-Required', 'Not specified')
print(f"Credits required for this request: {credits_used}")

# Save the streaming audio to a file
with open("output.wav", "wb") as audio_file:
    # Process the response in chunks to handle large audio files efficiently
    for chunk in response.iter_content(chunk_size=1024):
        if chunk:  # Filter out keep-alive chunks
            audio_file.write(chunk)

print("Voice generation complete! Audio saved as 'output.wav'")

The streaming approach gives you immediate access to your audio, making it perfect for interactive applications, voice assistants, and real-time communication tools. By using the standard requests library with stream=True, you can handle audio generation efficiently even for longer text passages.

Authorizations

x-api-key
string
header
required

The x-api-key is a custom header required for authenticating requests to our API. Include this header in your request with the appropriate API key value to securely access our endpoints. You can find your API key(s) in the 'API' section of our studio website.

Body

application/json

Response

200
audio/flac
Generated speech audio in the specified format.

The response is of type file.