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

# Text-to-Speech

> Generate speech from Arabic text using a specific model. Supports both streaming and non-streaming responses.

Generate speech from Arabic text and receive a complete WAV audio file. The entire audio is generated before being returned, ensuring complete audio quality.

## Authentication

Requires API key authentication via `x-api-key` header.

## Path Parameters

| Parameter  | Type   | Required | Description                                |
| ---------- | ------ | -------- | ------------------------------------------ |
| `model_id` | string | Yes      | The model identifier to use for generation |

## Request Body

| Field       | Type    | Required | Description                                                                                      |
| ----------- | ------- | -------- | ------------------------------------------------------------------------------------------------ |
| `voice_id`  | string  | Yes      | The voice ID to use for synthesis                                                                |
| `text`      | string  | Yes      | The Arabic text to convert to speech                                                             |
| `stability` | number  | Yes      | Voice stability (0.0 to 1.0). Higher values produce more consistent output                       |
| `speed`     | number  | No       | Speech speed (0.7 to 1.2, default 1.0). Values below 1.0 slow down speech, above 1.0 speed it up |
| `streaming` | boolean | Yes      | Must be `false` for complete WAV file response                                                   |

### Example Request Body

```json theme={null}
{
  "voice_id": "voice_123",
  "text": "مرحبا بك في فصيح كيف يمكنني مساعدتك اليوم",
  "stability": 0.5,
  "speed": 1.0,
  "streaming": false
}
```

## Response

**Status Code:** `200 OK`

**Headers:**

* `Content-Type: audio/wav`
* `Cache-Control: no-cache`
* `Content-Length: <file_size>`

**Body:** Complete WAV audio file

### Error Responses

**400 Bad Request**

```json theme={null}
{
  "errorCode": "400xx",
  "errorMessage": "Model not found: invalid_model_id"
}
```

**402 Payment Required**

```json theme={null}
{
  "errorCode": "402xx",
  "errorMessage": "Insufficient wallet balance. Required: $0.05, Available: $0.02"
}
```

## Example Usage

### JavaScript

```javascript theme={null}
const response = await fetch('https://api.munsit.com/api/v1/text-to-speech/MODEL_ID', {
  method: 'POST',
  headers: {
    'x-api-key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    voice_id: 'VOICE_ID',
    text: 'مرحبا بك في فصيح كيف يمكنني مساعدتك اليوم',
    stability: 0.5,
    speed: 1.0,
    streaming: false,
  }),
});

const audioBlob = await response.blob();
const audioUrl = URL.createObjectURL(audioBlob);
// Use audioUrl to play or download the audio
```

### Python

```python theme={null}
import requests

url = "https://api.munsit.com/api/v1/text-to-speech/MODEL_ID"
headers = {
    "x-api-key": "YOUR_API_KEY",
    "Content-Type": "application/json"
}
data = {
    "voice_id": "VOICE_ID",
    "text": "مرحبا بك في فصيح كيف يمكنني مساعدتك اليوم",
    "stability": 0.5,
    "speed": 1.0,
    "streaming": False
}

response = requests.post(url, json=data, headers=headers)

if response.status_code == 200:
    with open("output.wav", "wb") as f:
        f.write(response.content)
else:
    print(f"Error: {response.status_code} - {response.text}")
```

## Cost Calculation

The cost is calculated based on:

* Text length (number of characters)
* Model cost per character

Cost is deducted from your wallet balance upon successful generation.

<Note>
  **Wallet Balance**: Ensure your wallet has sufficient balance before making requests. Check your balance in the [Munsit dashboard](https://app.munsit.com//en/api-keys).
</Note>


## OpenAPI

````yaml POST /text-to-speech/{model_id}
openapi: 3.1.0
info:
  title: Munsit API
  description: >-
    Munsit - First True Arabic Voice AI that speaks Dialects From Abu Dhabi to
    Rabat with Voice Cloning & On-prem support
  version: 1.0.0
servers:
  - url: https://api.munsit.com/api/v1
    description: Global production server
  - url: https://ae.api.faseeh.ai/api/v1
    description: UAE regional server
security:
  - apiKeyAuth: []
paths:
  /text-to-speech/{model_id}:
    post:
      tags:
        - Text-to-Speech
      summary: Generate Text-to-Speech
      description: >-
        Generate speech from Arabic text using a specific model. Supports both
        streaming and non-streaming responses.
      operationId: generateTextToSpeech
      parameters:
        - name: model_id
          in: path
          required: true
          description: The model identifier to use for generation
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TextToSpeechRequest'
      responses:
        '200':
          description: Audio response (streaming or complete file)
          content:
            audio/raw:
              schema:
                type: string
                format: binary
                description: PCM16 audio stream (when streaming=true)
            audio/wav:
              schema:
                type: string
                format: binary
                description: WAV audio file (when streaming=false)
        '400':
          description: Bad Request - Invalid parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized - Invalid or missing API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '402':
          description: Payment Required - Insufficient wallet balance
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Not Found - Model not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Too Many Requests - Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    TextToSpeechRequest:
      type: object
      required:
        - voice_id
        - text
        - stability
        - streaming
      properties:
        voice_id:
          type: string
          description: The voice ID to use for synthesis
        text:
          type: string
          description: The Arabic text to convert to speech
        stability:
          type: number
          minimum: 0
          maximum: 1
          description: >-
            Voice stability (0.0 to 1.0). Higher values produce more consistent
            output
        speed:
          type: number
          minimum: 0.7
          maximum: 1.2
          default: 1
          description: >-
            Speech speed multiplier (0.7 to 1.2). Values below 1.0 slow down
            speech, values above 1.0 speed it up
        streaming:
          type: boolean
          description: >-
            If true, returns streaming PCM16 audio. If false, returns complete
            WAV file
    Error:
      type: object
      required:
        - errorCode
        - errorMessage
      properties:
        errorCode:
          type: string
          description: Error code identifier
        errorMessage:
          type: string
          description: Human-readable error message
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: API key for authentication

````