> ## Documentation Index
> Fetch the complete documentation index at: https://docs.60db.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Text to Speech

> Convert text to natural-sounding speech

## Request

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token with your API key
</ParamField>

<ParamField header="Content-Type" type="string" required>
  application/json
</ParamField>

### Body

<ParamField body="text" type="string" required>
  The text to convert to speech (max 5000 characters)
</ParamField>

<ParamField body="voice_id" type="string" required>
  ID of the voice to use. Fetch available voices from `GET /voices`.
</ParamField>

<ParamField body="audio_config" type="object">
  Nested audio configuration block (matches the upstream Inworld schema).
</ParamField>

<ParamField body="audio_config.audio_encoding" type="string" default="LINEAR16">
  Audio encoding for the streamed response. Options: `LINEAR16`, `OGG_OPUS`.
</ParamField>

<ParamField body="audio_config.sample_rate_hertz" type="integer" default="24000">
  Output sample rate. Options: `16000`, `24000`, `48000`.
</ParamField>

<ParamField body="speed" type="number" default="1">
  Speaking rate. Range `0.5` (slow) – `2.0` (fast). `1.0` = normal.
</ParamField>

<ParamField body="stability" type="integer" default="50">
  Voice consistency `0`–`100`. `0` = expressive, `50` = balanced, `100` = consistent.
</ParamField>

<ParamField body="similarity" type="integer" default="75">
  Voice match fidelity `0`–`100`. `0` = loose, `75` = strong, `100` = exact clone.
</ParamField>

<ParamField body="timestamp_type" type="string" default="WORD">
  Set to `"WORD"` to receive per-word timestamps in the final NDJSON chunk (`timestampInfo`). Omit or set to `"NONE"` to skip.
</ParamField>

<ParamField body="target_language" type="string">
  Optional cross-lingual synthesis hint (e.g. `"en"`, `"hi"`, `"ar"`). Required when the voice's reference audio is in a different language than the input text. Auto-detected from voice metadata when omitted.
</ParamField>

<Note>
  **Legacy flat keys (`sample_rate`, `audio_encoding`) are still accepted** for backwards-compatibility, but new integrations should send the nested `audio_config` object.
</Note>

## Response

<ResponseField name="success" type="boolean">
  Indicates if the request was successful
</ResponseField>

<ResponseField name="message" type="string">
  Status message
</ResponseField>

<ResponseField name="audio_base64" type="string">
  Base64-encoded audio data
</ResponseField>

<ResponseField name="sample_rate" type="number">
  Audio sample rate in Hz
</ResponseField>

<ResponseField name="duration_seconds" type="number">
  Duration of the audio in seconds
</ResponseField>

<ResponseField name="encoding" type="string">
  Audio encoding format
</ResponseField>

<ResponseField name="output_format" type="string">
  Audio output format
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.60db.ai/tts-synthesize \
    -H "Authorization: Bearer your-api-key" \
    -H "Content-Type: application/json" \
    -d '{
      "text": "Hello, this is a test of the Inworld-compatible text-to-speech API with streaming.",
      "voice_id": "038cf0d1-eef8-45a6-81b0-99c5e57a33d2",
      "audio_config": {
        "audio_encoding": "LINEAR16",
        "sample_rate_hertz": 24000
      },
      "speed": 1,
      "stability": 50,
      "similarity": 75,
      "timestamp_type": "WORD"
    }'
  ```

  ```javascript JavaScript theme={null}
  import { SixtyDBClient } from "60db";

  const client = new SixtyDBClient("your-api-key");

  const audio = await client.textToSpeech({
    text: "Hello, this is a test of the Inworld-compatible text-to-speech API with streaming.",
    voice_id: "038cf0d1-eef8-45a6-81b0-99c5e57a33d2",
    // model_id: "indic_tts_v1",
    audio_config: {
      audio_encoding: "LINEAR16",
      sample_rate_hertz: 24000,
    },
    speed: 1,
    stability: 50,
    similarity: 75,
    timestamp_type: "WORD",
  });

  // audio is an ArrayBuffer
  ```

  ```python Python theme={null}
  from sixtydb import SixtyDBClient

  client = SixtyDBClient('your-api-key')

  audio = client.text_to_speech(
      text='Hello, this is a test of the Inworld-compatible text-to-speech API with streaming.',
      voice_id='038cf0d1-eef8-45a6-81b0-99c5e57a33d2',
      # model_id='indic_tts_v1',
      audio_config={
          'audio_encoding': 'LINEAR16',
          'sample_rate_hertz': 24000,
      },
      speed=1,
      stability=50,
      similarity=75,
      timestamp_type='WORD',
  )

  # Save to file
  with open('output.wav', 'wb') as f:
      f.write(audio)
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "success": true,
    "message": "Audio generated successfully",
    "audio_base64": "SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU4Ljc2LjEwMAAAAAAAAAAAAAAA...",
    "sample_rate": 24000,
    "duration_seconds": 3.5,
    "encoding": "mp3",
    "output_format": "mp3"
  }
  ```
</ResponseExample>
