Skip to main content
POST
/
text-to-speech
/
{model_id}
Generate Text-to-Speech
curl --request POST \
  --url https://api.faseeh.ai/api/v1/text-to-speech/{model_id} \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "voice_id": "<string>",
  "text": "<string>",
  "stability": 0.5,
  "streaming": true
}
'
"<string>"
STREAM Generate speech from Arabic text with streaming PCM16 audio output. Audio chunks are streamed as they’re generated, providing low-latency audio delivery.

Endpoint

POST /text-to-speech/:model_id

Authentication

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

Path Parameters

ParameterTypeRequiredDescription
model_idstringYesThe model identifier to use for generation

Request Body

FieldTypeRequiredDescription
voice_idstringYesThe voice ID to use for synthesis
textstringYesThe Arabic text to convert to speech
stabilitynumberYesVoice stability (0.0 to 1.0). Higher values produce more consistent output
streamingbooleanYesMust be true for streaming response

Example Request Body

{
  "voice_id": "voice_123",
  "text": "مرحبا بك في فصيح كيف يمكنني مساعدتك اليوم",
  "stability": 0.5,
  "streaming": true
}

Response

Status Code: 200 OK Headers:
  • Content-Type: audio/raw;codec=pcm16;rate=24000;channels=1
  • Cache-Control: no-cache
  • Connection: keep-alive
Body: Stream of PCM16 audio chunks (24kHz, mono)

Error Responses

400 Bad Request
{
  "errorCode": "400xx",
  "errorMessage": "Model not found: invalid_model_id"
}
402 Payment Required
{
  "errorCode": "402xx",
  "errorMessage": "Insufficient wallet balance. Required: $0.05, Available: $0.02"
}

Example Usage

JavaScript

const response = await fetch('https://api.faseeh.ai/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,
    streaming: true,
  }),
});

const reader = response.body.getReader();
const chunks = [];

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  chunks.push(value);
}

// Combine chunks into single audio buffer
const audioBuffer = new Uint8Array(chunks.reduce((acc, chunk) => acc + chunk.length, 0));
let offset = 0;
for (const chunk of chunks) {
  audioBuffer.set(chunk, offset);
  offset += chunk.length;
}

Python

import requests

url = "https://api.faseeh.ai/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,
    "streaming": True
}

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

if response.status_code == 200:
    with open("output.pcm", "wb") as f:
        for chunk in response.iter_content(chunk_size=8192):
            if chunk:
                f.write(chunk)
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.
Wallet Balance: Ensure your wallet has sufficient balance before making requests. Check your balance in the Faseeh dashboard.

Authorizations

x-api-key
string
header
required

API key for authentication

Path Parameters

model_id
string
required

The model identifier to use for generation

Body

application/json
voice_id
string
required

The voice ID to use for synthesis

text
string
required

The Arabic text to convert to speech

stability
number
required

Voice stability (0.0 to 1.0). Higher values produce more consistent output

Required range: 0 <= x <= 1
streaming
boolean
required

If true, returns streaming PCM16 audio. If false, returns complete WAV file

Response

Audio response (streaming or complete file)

PCM16 audio stream (when streaming=true)