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

# Audio (TTS & transcription)

> Generate speech with `POST /v1/audio/speech` and transcribe audio with `POST /v1/audio/transcriptions`.

Two audio endpoints, both OpenAI-shaped:

* **Text-to-speech (TTS)** — `POST /v1/audio/speech` returns audio bytes for a text input. Find models with `audio_speech` in `supports`.
* **Transcription (ASR)** — `POST /v1/audio/transcriptions` returns text for an audio file upload. Find models with `audio_transcription` in `supports`.

See [model discovery](/inference-api/guides/model-discovery#audio-text-to-speech) for the filter snippets.

## Text-to-speech

The example below uses `Kokoro-82M`. The response body is raw audio bytes (WAV by default) — write them straight to disk.

<CodeGroup>
  ```bash cURL theme={null}
  curl https://tokens.flex.ai/v1/audio/speech \
    -H "Authorization: Bearer $FLEXAI_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "Kokoro-82M",
      "input": "Hello from FlexAI.",
      "voice": "neutral_female"
    }' \
    --output out.wav
  ```

  ```python Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(base_url="https://tokens.flex.ai/v1", api_key=os.environ["FLEXAI_API_KEY"])

  resp = client.audio.speech.create(
      model="Kokoro-82M",
      input="Hello from FlexAI.",
      voice="neutral_female",
  )
  resp.stream_to_file("out.wav")
  ```

  ```typescript TypeScript theme={null}
  import fs from "node:fs";
  import OpenAI from "openai";

  const client = new OpenAI({
    baseURL: "https://tokens.flex.ai/v1",
    apiKey: process.env.FLEXAI_API_KEY,
  });

  const resp = await client.audio.speech.create({
    model: "Kokoro-82M",
    input: "Hello from FlexAI.",
    voice: "neutral_female",
  });
  fs.writeFileSync("out.wav", Buffer.from(await resp.arrayBuffer()));
  ```
</CodeGroup>

### Voices

Voice names are model-specific — there's no shared "Alloy/Echo/Fable/…" namespace. Check the model's `description` on `GET /api/models` for the supported set, or fall back to the model's upstream documentation.

### Billing

TTS bills per input character — see `pricing[]` (`billing_unit: "character"`) on `GET /api/models`, or [billing](/inference-api/reference/billing).

## Transcription

`/v1/audio/transcriptions` is Whisper-compatible. Send the audio file as `multipart/form-data`, get back a JSON `{ "text": "..." }`. The current model is `whisper-large-v3-turbo`.

<CodeGroup>
  ```bash cURL theme={null}
  curl https://tokens.flex.ai/v1/audio/transcriptions \
    -H "Authorization: Bearer $FLEXAI_API_KEY" \
    -F "file=@input.wav" \
    -F "model=whisper-large-v3-turbo" \
    -F "language=en"
  ```

  ```python Python theme={null}
  import os
  from openai import OpenAI

  client = OpenAI(base_url="https://tokens.flex.ai/v1", api_key=os.environ["FLEXAI_API_KEY"])

  with open("input.wav", "rb") as f:
      resp = client.audio.transcriptions.create(
          model="whisper-large-v3-turbo",
          file=f,
          language="en",
      )
  print(resp.text)
  ```

  ```typescript TypeScript theme={null}
  import fs from "node:fs";
  import OpenAI from "openai";

  const client = new OpenAI({
    baseURL: "https://tokens.flex.ai/v1",
    apiKey: process.env.FLEXAI_API_KEY,
  });

  const resp = await client.audio.transcriptions.create({
    model: "whisper-large-v3-turbo",
    file: fs.createReadStream("input.wav"),
    language: "en",
  });
  console.log(resp.text);
  ```
</CodeGroup>

### Request fields

| Field      | Required | Notes                                                       |
| ---------- | -------- | ----------------------------------------------------------- |
| `file`     | Yes      | `multipart/form-data` upload. WAV, MP3, M4A, FLAC, OGG.     |
| `model`    | Yes      | Must have `audio_transcription` in `supports`.              |
| `language` | No       | ISO-639-1 code (`en`, `fr`, …). Auto-detected when omitted. |

### Billing

ASR bills per minute of input audio — see `pricing[]` (`billing_unit: "minute"`) on `GET /api/models`.

## See also

* [Model discovery](/inference-api/guides/model-discovery) — capability filters for `audio_speech` and `audio_transcription`.
* [OpenAI compatibility](/inference-api/reference/openai-compatibility) — `/v1/audio/translations` is not supported.
