Text to Speech (TTS)
Convert text to natural-sounding speech
POST
/api/v1/tts/generate/
Converts text to speech using AI voice synthesis. Returns an MP3 audio file.
Authentication
Include your API key in the Authorization header.
Request Body
| Parameter | Type | Description |
|---|---|---|
| text required | string | Text to convert (max 1500 characters) |
| voice_id required | integer | Voice ID from the voice list |
| prerecording optional | integer | 1 (Basic Enhancement) or 2 (AI Enhancement) |
| voice_settings optional | object | Voice customization options |
Voice Settings Object
| Parameter | Type | Range | Default | Description |
|---|---|---|---|---|
| speed | float | 0.7 - 1.2 | 1.0 | Speech speed |
| temperature | float | 0 - 100 | 75 | Voice Creativity (100 most creative) |
| voice_similarity | float | 0 - 100 | 100 | Similarity to used voice (100 most similar) |
| enable_emotions | boolean | False/True | False | Enable emotional expression |
Example
curl -X POST "https://moknah.io/api/v1/tts/generate/" \
-H "Authorization: "Bearer your_api_key"
-d '{
"text": "مرحبا بك في منصة مكنة",
"voice_id": 1,
"prerecording": 1,
"voice_settings": {
"speed": 1.0,
"temperature": 70
}
}' \
--output speech.mp3
import requests
response = requests.post(
"https://moknah.io/api/v1/tts/generate/",
headers={
"Authorization": "Bearer your_api_key",
"Content-Type": "application/json"
},
json={
"text": "مرحبا بك في منصة مكنة",
"voice_id": 1,
"prerecording": 1,
"voice_settings": {
"speed": 1.0,
"temperature": 70
}
}
)
with open("speech.mp3", "wb") as f:
f.write(response.content)
const response = await fetch(
'https://moknah.io/api/v1/tts/generate/',
{
method: 'POST',
headers: {
'Authorization': 'Bearer your_api_key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: 'مرحبا بك في منصة مكنة',
voice_id: 1,
prerecording: 1,
voice_settings: {
speed: 1.0,
temperature: 70
}
})
}
);
const blob = await response.blob();
// Save or play the audio
Response
Returns binary MP3 audio data with these headers:
| Header | Description |
|---|---|
Content-Type |
audio/mpeg |
Errors
| Status | Code | Description |
|---|---|---|
400 |
INVALID_REQUEST | Invalid parameters |
401 |
UNAUTHORIZED | Invalid API key |
402 |
INSUFFICIENT_CREDITS | Not enough credits |
429 |
RATE_LIMIT_EXCEEDED | Too many requests |
API Support
For API-related questions or issues, contact us at api@moknah.io.