Sawalni API
APIsDocumentationOpen portal ↗
Omneity Labs API collection ↗Integration quickstart →API keys and playgrounds →
API Reference

Speech Synthesis API

Generate speech audio from text using ASAT v2, short for ASAT Speaks Any Text. It is optimized around Moroccan Arabic and Arabic speech generation.

Endpoints

Canonical endpoint:

text
POST https://api.sawalni.com/v1/audio/speech

Sawalni-style alias:

text
POST https://api.sawalni.com/v1/speech/synthesize

Request Body

Send an application/json request.

ParameterTypeRequiredDescription
inputstringYesText to synthesize into speech
modelstringNoModel identifier. Use asat. Default: asat
voicestringNoReference voice. Default: male-1
response_formatstringNowav or pcm16. Default: wav
streambooleanNoSend audio bytes as they are generated. Default: false. This changes delivery, not model quality.

The current service does not expose NFE steps, speed, CFG, or chunk-size controls. Do not send those fields; the current server ignores extra request fields.

Streaming and Formats

The service keeps one speech session for each request. stream: true delivers output chunks as they become available. It does not select a separate quality path. Use response_format: "pcm16" for raw signed 16-bit little-endian PCM at 24 kHz, mono. For a streamed WAV, the initial RIFF header has placeholder lengths. Rewrite the RIFF and data lengths after the stream ends before saving a standalone WAV file. The playground does this for you.

Example — curl

bash
curl -X POST https://api.sawalni.com/v1/audio/speech \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "asat", "voice": "male-1", "response_format": "wav", "input": "السلام، كيف داير؟ هادي تجربة ديال الصوت بالدارجة المغربية." }' \ --output asat.wav

Example — Python

python
import requests response = requests.post( "https://api.sawalni.com/v1/audio/speech", headers={"Authorization": "Bearer YOUR_API_KEY"}, json={ "model": "asat", "voice": "male-1", "response_format": "wav", "input": "السلام، كيف داير؟", }, ) response.raise_for_status() open("asat.wav", "wb").write(response.content) print("Duration:", response.headers.get("x-audio-duration-s"))

Example — JavaScript

javascript
const response = await fetch('https://api.sawalni.com/v1/audio/speech', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'asat', voice: 'male-1', response_format: 'wav', input: 'السلام، كيف داير؟', }), }); const audio = await response.blob(); new Audio(URL.createObjectURL(audio)).play(); console.log('Duration:', response.headers.get('x-audio-duration-s'));

Response

The response body is audio/wav or raw 24 kHz mono signed 16-bit PCM. Metadata is returned in response headers. Some fields, including duration and processing time, are only available for buffered responses. For streams, calculate duration from PCM byte count at 48,000 bytes per second.

HeaderDescription
x-audio-duration-sGenerated audio duration in seconds (buffered responses)
x-processing-msServer-side generation time in milliseconds (buffered responses)
x-input-charsNumber of input characters processed
x-asat-modelPublic model identifier, asat
x-asat-voiceResolved reference voice
x-asat-conditioningSpeech conditioning method used for this response
x-audio-sample-rateOutput sample rate, currently 24000
x-audio-channelsOutput channel count, currently 1
x-audio-codecOutput codec, currently pcm_s16le
x-asat-preprocessText preprocessing applied by the Sawalni gateway

Supported Voices

Retrieve the current machine-readable catalog with GET https://api.sawalni.com/v1/voices. The voice request value must be one of these IDs:

VoiceDescription
male-1Yassine
male-2Mehdi
male-3Anas
male-4Amine
male-5Hamza
male-6Ayoub
male-7Ilyas
male-8Soufiane
male-9Reda
male-10Othmane
male-11Zakaria
male-12Youssef
female-1Salma
female-2Ghita
female-3Kenza
female-4Imane
female-5Hajar
female-6Zineb
female-7Sara
female-8Meryem
female-9Asmae
female-10Chaimae

The service uses the selected voice for speech generation.

Model Details

PropertyValue
Model IDasat
Full NameASAT Speaks Any Text
SpecializationMoroccan Arabic and Arabic text-to-speech

Error Handling

HTTP CodeMeaning
200Success — audio returned
400Invalid input, model, voice, or response format
503No healthy speech synthesis deployments
504Speech synthesis timed out

Pricing

Speech synthesis is metered by generated audio duration.

MetricRate
Generated audio seconds$6.00 per 1M seconds