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

# TTS in five minutes

> Generate your first Rime TTS audio clip in five minutes using cURL, Python, JavaScript, or TypeScript.

By the end of this page, you'll have a WAV file of a Rime voice reading a short sentence, made with one request to Rime's text-to-speech API. Choose a language tab, copy the complete script, and run it from your terminal.

## Prerequisites

You need:

* **A Rime API token:** Create a free [Rime account](https://app.rime.ai/signup/) and copy your API key from the [API Tokens](https://app.rime.ai/tokens/) page.
* A language runtime, depending on which tab you follow:
  * **cURL**: a terminal with cURL installed (included with macOS and most Linux distributions).
  * **Python**: [Python 3.10](https://www.python.org/downloads/release/python-3100/) or later.
  * **JavaScript**: [Node.js 18](https://nodejs.org/) or later.
  * **TypeScript**: Node.js 18+ plus [tsx](https://github.com/privatenumber/tsx) (`npm install -g tsx`).

Each code block is tabbed by language. Pick the same language in every block.

> [!NOTE]
>
> These examples call Rime's HTTPS API with a standard library or built-in `fetch`. No Rime package is required.
>
> Rime publishes Python [`rime-api`](https://pypi.org/project/rime-api/) and JavaScript [`@rimelabs/api`](https://www.npmjs.com/package/@rimelabs/api) with generated TTS message definitions for the standalone engine. See [package installation and scope](https://docs.rime.ai/docs/on-prem/protocols.md#python-and-javascript-packages).
>
> Framework-specific starters are available for [Next.js](https://docs.rime.ai/docs/voice-agent-nextjs.md), [Vite](https://docs.rime.ai/docs/voice-agent-vite.md), [Express](https://docs.rime.ai/docs/voice-agent-express.md), [plain Node](https://docs.rime.ai/docs/voice-agent-node.md), and [FastAPI](https://docs.rime.ai/docs/voice-agent-fastapi.md).

The scripts read your key from the `RIME_API_KEY` environment variable, which keeps it out of files you might share or commit. Set it in the terminal you'll run them from:

```bash macOS and Linux theme={null}
export RIME_API_KEY="your_api_key_here"
```

```powershell Windows PowerShell theme={null}
$env:RIME_API_KEY = "your_api_key_here"
```

## Copy the request

Each script sends "Hello! This is Rime speaking." to the `celeste` voice and saves the audio to `output.wav`, so you can replay it as many times as you need while you check it. One sentence is short enough to hear the whole result.

Create a file called `rime_hello_world.py`, `rime_hello_world.js`, or `rime_hello_world.ts` (or run the cURL version directly in your terminal) and paste the full script:

> [accordion] Full script (copy/paste)
>
> ```bash cURL theme={null}
> curl --request POST \
>   --url https://coda.api.rime.ai/ \
>   --header "Authorization: Bearer $RIME_API_KEY" \
>   --header 'Content-Type: application/json' \
>   --header 'Accept: audio/wav' \
>   --fail \
>   --show-error \
>   --output output.wav \
>   --data '{
>     "text": "Hello! This is Rime speaking.",
>     "speaker": "celeste"
>   }'
> ```
>
> ```python Python theme={null}
> import json
> import os
> import urllib.request
>
> RIME_API_KEY = os.environ["RIME_API_KEY"]
>
> headers = {
>     "Accept": "audio/wav",
>     "Authorization": f"Bearer {RIME_API_KEY}",
>     "Content-Type": "application/json"
> }
>
> payload = {
>     "text": "Hello! This is Rime speaking.",
>     "speaker": "celeste"
> }
>
> data = json.dumps(payload).encode("utf-8")
>
> request = urllib.request.Request(
>     "https://coda.api.rime.ai/",
>     data=data,
>     headers=headers,
>     method="POST"
> )
>
> with urllib.request.urlopen(request) as response:
>     with open("output.wav", "wb") as f:
>         while chunk := response.read(4096):
>             f.write(chunk)
>
> print("Audio saved to output.wav")
> ```
>
> ```javascript JavaScript theme={null}
> const fs = require("fs");
> const { Readable } = require("stream");
> const { pipeline } = require("stream/promises");
>
> const RIME_API_KEY = process.env.RIME_API_KEY;
> if (!RIME_API_KEY) {
>     throw new Error("Set RIME_API_KEY before running this script.");
> }
>
> const headers = {
>     "Accept": "audio/wav",
>     "Authorization": `Bearer ${RIME_API_KEY}`,
>     "Content-Type": "application/json"
> };
>
> const payload = {
>     text: "Hello! This is Rime speaking.",
>     speaker: "celeste"
> };
>
> async function generateSpeech() {
>     const response = await fetch("https://coda.api.rime.ai/", {
>         method: "POST",
>         headers: headers,
>         body: JSON.stringify(payload)
>     });
>
>     if (!response.ok) {
>         throw new Error(`HTTP error! status: ${response.status}`);
>     }
>
>     if (!response.body) {
>         throw new Error("The response did not include an audio body.");
>     }
>
>     await pipeline(
>         Readable.fromWeb(response.body),
>         fs.createWriteStream("output.wav")
>     );
>     console.log("Audio saved to output.wav");
> }
>
> generateSpeech();
> ```
>
> ```typescript TypeScript theme={null}
> import * as fs from "fs";
> import { Readable } from "stream";
> import { pipeline } from "stream/promises";
>
> const RIME_API_KEY = process.env.RIME_API_KEY;
> if (!RIME_API_KEY) {
>     throw new Error("Set RIME_API_KEY before running this script.");
> }
>
> const headers: Record<string, string> = {
>     "Accept": "audio/wav",
>     "Authorization": `Bearer ${RIME_API_KEY}`,
>     "Content-Type": "application/json"
> };
>
> const payload = {
>     text: "Hello! This is Rime speaking.",
>     speaker: "celeste"
> };
>
> async function generateSpeech(): Promise<void> {
>     const response = await fetch("https://coda.api.rime.ai/", {
>         method: "POST",
>         headers: headers,
>         body: JSON.stringify(payload)
>     });
>
>     if (!response.ok) {
>         throw new Error(`HTTP error! status: ${response.status}`);
>     }
>
>     if (!response.body) {
>         throw new Error("The response did not include an audio body.");
>     }
>
>     await pipeline(
>         Readable.fromWeb(response.body),
>         fs.createWriteStream("output.wav")
>     );
>     console.log("Audio saved to output.wav");
> }
>
> generateSpeech();
> ```

## Run it

The cURL tab runs the request directly. For Python, JavaScript, or TypeScript, run:

```bash Python theme={null}
python rime_hello_world.py
```

```bash JavaScript theme={null}
node rime_hello_world.js
```

```bash TypeScript theme={null}
npx tsx rime_hello_world.ts
```

A successful request writes `output.wav` and prints:

```bash theme={null}
Audio saved to output.wav
```

## Confirm it worked

Play the file. If you hear the sentence, your key, the request, and the voice all worked.

```bash macOS theme={null}
afplay output.wav
```

```bash Linux theme={null}
aplay output.wav
```

```bash Windows theme={null}
start output.wav
```

A file on disk isn't proof of audio. If the player won't open it, check what the file contains:

```bash theme={null}
ls -l output.wav      # expect tens of kilobytes, not a few hundred bytes
file output.wav       # expect: RIFF (little-endian) data, WAVE audio
head -c 4 output.wav  # expect: RIFF
```

A file without the `RIFF` header usually means the request reached the API with an `Accept` header other than `audio/wav`, for example because a proxy or client wrapper replaced it. The API streams the format that `Accept` names, so `audio/pcm` returns raw 16-bit PCM with no WAV header, and players won't open it. A request with no `Accept` header fails with `400`, and a wildcard `*/*` returns WAV. The cURL example uses `--fail --show-error` so HTTP errors stop the command instead of being saved as `output.wav`.

## If it did not work

Find the row that matches what you see. For the complete list of statuses and messages, see the [error reference](https://docs.rime.ai/docs/errors.md).

| What you see | Cause | Fix |
| :- | :- | :- |
| The client reports HTTP 401 | The API key is missing or invalid, or the account has no active subscription | Confirm `RIME_API_KEY` is set, recopy it from the [API Tokens page](https://app.rime.ai/tokens/), and check the account |
| The client reports HTTP 400 | A required field is missing or invalid | Check `speaker`, `text`, and `lang`, and the model's URL, against the [error reference](https://docs.rime.ai/docs/errors.md) |
| The client reports that the text is too long | `text` exceeded the configured limit | Split the text across requests |
| The client reports HTTP 400 with `Missing Accept header and audioFormat not provided` | The request arrived with no `Accept` header | Set `Accept` to `audio/wav` |
| File won't play and doesn't start with `RIFF` | `Accept` named a headerless format such as `audio/pcm`, so the API returned raw PCM | Set `Accept` to `audio/wav`. See [Streaming formats](https://docs.rime.ai/docs/streaming.md) |
| File is 0 bytes | The request never completed | Confirm the URL is `https://coda.api.rime.ai/` and reachable from your network |
| Audio plays but the voice is wrong | The `speaker`, model host, and `lang` combination is not one the catalog serves | An unsupported combination is not reliably rejected. Verify the voice against the [Coda catalog](https://docs.rime.ai/docs/voices-coda.md) |

> [accordion] How the request works
>
> ### Build the request step by step
>
> Create a file called `rime_hello_world.py`, `rime_hello_world.js`, or `rime_hello_world.ts` and import the required library modules:
>
> ```python Python theme={null}
> import json
> import os
> import urllib.request
> ```
>
> ```javascript JavaScript theme={null}
> const fs = require("fs");
> const { Readable } = require("stream");
> const { pipeline } = require("stream/promises");
> ```
>
> ```typescript TypeScript theme={null}
> import * as fs from "fs";
> import { Readable } from "stream";
> import { pipeline } from "stream/promises";
> ```
>
> Set the request headers with your Rime API key and the expected audio format:
>
> ```python Python theme={null}
> RIME_API_KEY = os.environ["RIME_API_KEY"]
>
> headers = {
>     "Accept": "audio/wav",
>     "Authorization": f"Bearer {RIME_API_KEY}",
>     "Content-Type": "application/json"
> }
> ```
>
> ```javascript JavaScript theme={null}
> const RIME_API_KEY = process.env.RIME_API_KEY;
> if (!RIME_API_KEY) {
>     throw new Error("Set RIME_API_KEY before running this script.");
> }
>
> const headers = {
>     "Accept": "audio/wav",
>     "Authorization": `Bearer ${RIME_API_KEY}`,
>     "Content-Type": "application/json"
> };
> ```
>
> ```typescript TypeScript theme={null}
> const RIME_API_KEY = process.env.RIME_API_KEY;
> if (!RIME_API_KEY) {
>     throw new Error("Set RIME_API_KEY before running this script.");
> }
>
> const headers: Record<string, string> = {
>     "Accept": "audio/wav",
>     "Authorization": `Bearer ${RIME_API_KEY}`,
>     "Content-Type": "application/json"
> };
> ```
>
> Set the model's URL, and the text and speaker in the request body:
>
> ```python Python theme={null}
> url = "https://coda.api.rime.ai/"
> payload = {
>     "text": "Hello! This is Rime speaking.",
>     "speaker": "celeste"
> }
> ```
>
> ```javascript JavaScript theme={null}
> const url = "https://coda.api.rime.ai/";
> const payload = {
>     text: "Hello! This is Rime speaking.",
>     speaker: "celeste"
> };
> ```
>
> ```typescript TypeScript theme={null}
> const url = "https://coda.api.rime.ai/";
> const payload = {
>     text: "Hello! This is Rime speaking.",
>     speaker: "celeste"
> };
> ```
>
> The URL and the payload set the three required choices:
>
> * `text` is the content to synthesize.
> * `speaker` selects a voice from the [voice catalog](https://docs.rime.ai/docs/voices.md).
> * `url` selects the model, because each model has its own host. Use `https://coda.api.rime.ai/` for the full Coda voice lineup or `https://mist.api.rime.ai/` for Mist v3, the lowest time to first audio.
>
> The [Coda API reference](https://docs.rime.ai/api-reference/coda/http.md) lists the optional request parameters.
>
> Send the `POST` request and write the streamed audio response to a file:
>
> ```python Python theme={null}
> data = json.dumps(payload).encode("utf-8")
>
> request = urllib.request.Request(
>     url,
>     data=data,
>     headers=headers,
>     method="POST"
> )
>
> with urllib.request.urlopen(request) as response:
>     with open("output.wav", "wb") as f:
>         while chunk := response.read(4096):
>             f.write(chunk)
>
> print("Audio saved to output.wav")
> ```
>
> ```javascript JavaScript theme={null}
> async function generateSpeech() {
>     const response = await fetch(url, {
>         method: "POST",
>         headers: headers,
>         body: JSON.stringify(payload)
>     });
>
>     if (!response.ok) {
>         throw new Error(`HTTP error! status: ${response.status}`);
>     }
>
>     if (!response.body) {
>         throw new Error("The response did not include an audio body.");
>     }
>
>     await pipeline(
>         Readable.fromWeb(response.body),
>         fs.createWriteStream("output.wav")
>     );
>     console.log("Audio saved to output.wav");
> }
>
> generateSpeech();
> ```
>
> ```typescript TypeScript theme={null}
> async function generateSpeech(): Promise<void> {
>     const response = await fetch(url, {
>         method: "POST",
>         headers: headers,
>         body: JSON.stringify(payload)
>     });
>
>     if (!response.ok) {
>         throw new Error(`HTTP error! status: ${response.status}`);
>     }
>
>     if (!response.body) {
>         throw new Error("The response did not include an audio body.");
>     }
>
>     await pipeline(
>         Readable.fromWeb(response.body),
>         fs.createWriteStream("output.wav")
>     );
>     console.log("Audio saved to output.wav");
> }
>
> generateSpeech();
> ```
>
> These examples stream the response but write each chunk to disk. Interactive applications can play chunks as they arrive so speech begins before the complete response is generated. The [LiveKit quickstart](https://docs.rime.ai/docs/quickstart-livekit.md) shows this pattern in a conversational agent.

## Choose a voice

Keep the same sentence and change only `speaker`. With the words held constant, it's easier to hear what the new voice changes:

```python Python theme={null}
payload = {
    "text": "Hello! This is Rime speaking.",
    "speaker": "orion"  # Try different voices here
}
```

```javascript JavaScript theme={null}
const payload = {
    text: "Hello! This is Rime speaking.",
    speaker: "orion"  // Try different voices here
};
```

```typescript TypeScript theme={null}
const payload = {
    text: "Hello! This is Rime speaking.",
    speaker: "orion"  // Try different voices here
};
```

The [Voices](https://docs.rime.ai/docs/voices.md) page lists starter voices and the full catalog. Each voice speaks one language. If you choose a voice in another language, give it text in that language and add `lang` with the voice's language tag.

## Custom pronunciation

> [!NOTE]
>
> Custom pronunciation is supported on **English Mist v3**. Coda and non-English Mist v3 do not support [`phonemizeBetweenBrackets`](https://docs.rime.ai/docs/custom-pronunciation).

English Mist v3 lets you specify the pronunciation of brand names or uncommon words using the [Rime phonetic alphabet](https://docs.rime.ai/platform/rime-phonetic-alphabet.md). Add the custom pronunciation in curly brackets, set [`phonemizeBetweenBrackets`](https://docs.rime.ai/docs/custom-pronunciation) to `true`, and send the request to the Mist v3 host:

```python Python theme={null}
url = "https://mist.api.rime.ai/"
payload = {
    "text": "Welcome to {r1Ym} labs.",
    "speaker": "peak",
    "phonemizeBetweenBrackets": True
}
```

```javascript JavaScript theme={null}
const url = "https://mist.api.rime.ai/";
const payload = {
    text: "Welcome to {r1Ym} labs.",
    speaker: "peak",
    phonemizeBetweenBrackets: true
};
```

```typescript TypeScript theme={null}
const url = "https://mist.api.rime.ai/";
const payload = {
    text: "Welcome to {r1Ym} labs.",
    speaker: "peak",
    phonemizeBetweenBrackets: true
};
```

See the [Rime phonetic alphabet](https://docs.rime.ai/platform/rime-phonetic-alphabet.md) for the full symbol reference, and [Pronunciation control](https://docs.rime.ai/platform/pronunciation-control.md) for an overview of all the ways to control pronunciation.

## Production choices

The [LiveKit quickstart](https://docs.rime.ai/docs/quickstart-livekit.md) extends the same streaming API into a real-time voice agent. These references cover the main model, voice, latency, and transport decisions:

> [card] [Models](https://docs.rime.ai/docs/models.md)
>
> Compare Coda (flagship) and Mist v3 (fast)

> [card] [Voices](https://docs.rime.ai/docs/voices.md)
>
> Browse all available voice options

> [card] [Latency](https://docs.rime.ai/docs/latency.md)
>
> Optimize for real-time performance

> [card] [Coda Streaming API](https://docs.rime.ai/api-reference/coda/http.md)
>
> Stream audio with Coda, Rime's flagship model


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