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

# Text-to-Speech quickstart

> Turn text into a WAV file with Timbre v3.0 in a few minutes.

Send a sentence to the REST endpoint and save the spoken audio as a WAV file. The examples use Timbre v3.0 and the voice `Shivani`, which speaks all ten supported languages.

**1. Create an API key**

Sign in to the [Gnani API dashboard](https://app.gnani.ai/voice) and generate an API key.

**2. Set your key**

The examples read your key from the `GNANI_API_KEY` environment variable, so it never appears in your code. Set it in the terminal you will run the examples from:

```bash macOS / Linux theme={null}
export GNANI_API_KEY="your-api-key"
```

```powershell Windows (PowerShell) theme={null}
$env:GNANI_API_KEY = "your-api-key"
```

```bash .env theme={null}
GNANI_API_KEY=your-api-key
```

If you use a `.env` file, load it with a library such as `python-dotenv` or `dotenv`, and keep the file out of version control.

**3. Install**

```bash Python theme={null}
pip install requests
```

```bash Node.js theme={null}
# Nothing to install. Node.js 18 or later includes fetch.
node --version
```

```bash Python SDK theme={null}
pip install gnani-vachana
```

cURL is preinstalled on macOS, Linux and Windows 10 or later.

**4. Run**

```bash cURL theme={null}
curl --request POST "https://api.vachana.ai/api/v1/tts/inference" \
  --header "Content-Type: application/json" \
  --header "X-API-Key-ID: $GNANI_API_KEY" \
  --data '{
    "text": "नमस्ते, आप कैसे हैं?",
    "voice": "Shivani",
    "model": "timbre-v3.0",
    "language": "hi-IN",
    "audio_config": {
      "sample_rate": 48000,
      "encoding": "linear_pcm",
      "container": "wav"
    }
  }' \
  --output speech.wav
```

```python Python theme={null}
# quickstart.py
import os
import requests

r = requests.post(
    "https://api.vachana.ai/api/v1/tts/inference",
    headers={"X-API-Key-ID": os.environ["GNANI_API_KEY"]},
    json={
        "text": "नमस्ते, आप कैसे हैं?",
        "voice": "Shivani",
        "model": "timbre-v3.0",
        "language": "hi-IN",
        "audio_config": {
            "sample_rate": 48000,
            "encoding": "linear_pcm",
            "container": "wav",
        },
    },
    timeout=60,
)

if r.ok:
    with open("speech.wav", "wb") as f:
        f.write(r.content)
    print("Saved speech.wav")
else:
    print(r.status_code, r.text)
```

```javascript Node.js theme={null}
// quickstart.mjs
import { writeFileSync } from "node:fs";

const response = await fetch("https://api.vachana.ai/api/v1/tts/inference", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-API-Key-ID": process.env.GNANI_API_KEY,
  },
  body: JSON.stringify({
    text: "नमस्ते, आप कैसे हैं?",
    voice: "Shivani",
    model: "timbre-v3.0",
    language: "hi-IN",
    audio_config: {
      sample_rate: 48000,
      encoding: "linear_pcm",
      container: "wav",
    },
  }),
});

if (response.ok) {
  writeFileSync("speech.wav", Buffer.from(await response.arrayBuffer()));
  console.log("Saved speech.wav");
} else {
  console.log(response.status, await response.text());
}
```

```python Python SDK theme={null}
# quickstart.py
from gnani.tts import GnaniTTSClient

client = GnaniTTSClient()  # reads GNANI_API_KEY

client.synthesize(
    "नमस्ते, आप कैसे हैं?",
    voice="Nalini",
    model="timbre-v2.5",
    language="hi-IN",
    output_file="speech.wav",
)
print("Saved speech.wav")
```

Run the Python examples with `python quickstart.py` and the Node.js example with `node quickstart.mjs`.

> [!NOTE]
>
> The Python SDK example uses Timbre v2.5 and the voice `Nalini`, the model the SDK documents. Timbre v2.5 voices work only with `"model": "timbre-v2.5"`.

**5. Check the output**

A successful request returns `200` with `Content-Type: audio/wav`, and the audio is saved as `speech.wav`. Play it: you should hear "नमस्ते, आप कैसे हैं?" ("Hello, how are you?") in Hindi.

## If it didn't work

Text-to-Speech errors return a JSON body with a `message` that says what is wrong, instead of audio.

| Status | Error | Fix |
| - | - | - |
| `401` | `MISSING_API_KEY` | `GNANI_API_KEY` is not set in this terminal. Set it again (step 2) in the same terminal you run the code from. |
| `401` | `INVALID_API_KEY` | The key is wrong or was revoked. Copy it again from the dashboard. |
| `403` | `SCOPE_NOT_ALLOWED` | Your key is not allowed to use Text-to-Speech. Use a key that has access to it. |
| `429` | `RATE_LIMITED` | Your account allows fewer requests at a time than you sent. Wait for the earlier request to finish, then retry. |
| `400` | Voice not found | The voice does not belong to the model. Timbre v3.0 and Timbre v2.5 have separate voice lists; pick one from [Available Voices](https://docs.gnani.ai/api/TTS/available-voices.md). |
| `400` | Invalid parameter | `message` names the field, for example `speed` or a value in `audio_config`. Fix that field. |

If `speech.wav` will not play, open it in a text editor: an error body saved by cURL looks like JSON. Every error is listed in the [Error Reference](https://docs.gnani.ai/api/introduction/errors.md#text-to-speech).

## Choose an interface for your app

The quickstart used REST. Answer two questions to see which interface fits your app: [REST](https://docs.gnani.ai/api/TTS/tts-inference.md) returns the whole file, [Streaming (SSE)](https://docs.gnani.ai/api/TTS/tts-sse.md) starts playback early, and [Realtime (WebSocket)](https://docs.gnani.ai/api/TTS/tts-websocket.md) has the lowest latency for live conversations.

## Next

> [card] [Available Voices](https://docs.gnani.ai/api/TTS/available-voices.md)
>
> The voices for Timbre v3.0 and Timbre v2.5.

> [card] [Audio tags](https://docs.gnani.ai/api/TTS/tts-audio-tags.md)
>
> Add laughter, whispers and pauses with Timbre v3.0.

> [card] [Streaming](https://docs.gnani.ai/api/TTS/tts-sse.md)
>
> Start playback before the whole sentence is generated.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.