API Documentation
Integrate text-to-speech into your applications with our REST API. Access 5 TTS engines, nearly 300 voices, and voice cloning.
API Features
- ✓ 5 TTS engines
- ✓ Nearly 300 voices
- ✓ Voice cloning
- ✓ 40+ languages
- ✓ MP3, WAV, OGG
Contents
Base URL
https://api.texttospeechai.com/v1/
Authentication
All API requests require a Bearer token in the Authorization header.
Getting Your API Token
- Log in to your account dashboard
- Navigate to API Settings
- Generate a new API token
Request Header
Authorization: Bearer YOUR_API_TOKEN
Example (cURL)
curl -X GET "https://api.texttospeechai.com/v1/account/" \
-H "Authorization: Bearer YOUR_API_TOKEN"
Rate Limits
API requests are limited based on your account tier:
| Tier | Requests/Day |
|---|---|
| Free | 100 |
| Premium | 1,000 |
| Enterprise | 10,000 |
Rate limits reset at midnight UTC. Check the X-RateLimit-* headers in API responses.
Generate Speech
Create a new text-to-speech generation request.
/v1/generate/
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
text |
string | Yes | Text to synthesize (max 5000 chars) |
voice |
string | Yes | Voice slug (e.g., "en_US-kristin-medium") |
speed |
float | No | Speaking speed 0.5-2.0 (default 1.0) |
pitch |
float | No | Pitch adjustment 0.5-2.0 (default 1.0) |
format |
string | No | Output format: mp3, wav, ogg (default mp3) |
Example Request
curl -X POST "https://api.texttospeechai.com/v1/generate/" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"text": "Hello, welcome to TextToSpeechAI!",
"voice": "en_US-kristin-medium",
"speed": 1.0,
"format": "mp3"
}'
Response
{
"uuid": "abc123-def456-...",
"status": "pending",
"text_length": 35,
"voice": "en_US-kristin-medium",
"credits_used": 0.35,
"estimated_time": 5
}
List Voices
Get available voices with optional filtering.
/v1/voices/
Query Parameters
| Parameter | Description |
|---|---|
language |
Filter by language code (e.g., "en") |
gender |
Filter by gender (male/female/neutral) |
model_type |
Filter by TTS engine (piper, vits, bark, styletts2, tortoise) |
page |
Page number (default 1) |
per_page |
Results per page (default 50, max 100) |
Example Request
curl "https://api.texttospeechai.com/v1/voices/?language=en&gender=female" \
-H "Authorization: Bearer YOUR_API_TOKEN"
Check Status
Check the status of a generation request.
/v1/status/{uuid}/
Status Values
pending- Request queued for processingprocessing- Currently generating audiocompleted- Audio ready for downloadfailed- Generation failed (see error field)
Response (Completed)
{
"uuid": "abc123-def456-...",
"status": "completed",
"audio_url": "https://texttospeechai.com/uploads/generations/...",
"duration_seconds": 2.5,
"processing_time_ms": 1200
}
Voice Cloning
Create a cloned voice from reference audio.
/v1/clone/
Request (multipart/form-data)
| Parameter | Type | Required | Description |
|---|---|---|---|
name |
string | Yes | Name for the cloned voice |
audio |
file | Yes | Reference audio (WAV/MP3, 6-60 seconds) |
language |
string | No | Language code (default "en") |
Example Request
curl -X POST "https://api.texttospeechai.com/v1/clone/" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "name=My Custom Voice" \
-F "audio=@reference.wav" \
-F "language=en"
Account Info
Get account information and credit balance.
/v1/account/
Response
{
"email": "user@example.com",
"credits": 1000.00,
"created_at": "2024-01-01T00:00:00Z",
"rate_limit": {
"limit": 100,
"remaining": 95,
"used": 5,
"resets_at": "2024-01-02T00:00:00Z"
}
}
Error Codes
| Code | Description |
|---|---|
400 |
Bad Request - Invalid parameters |
401 |
Unauthorized - Invalid or missing API token |
402 |
Payment Required - Insufficient credits |
404 |
Not Found - Resource not found |
429 |
Too Many Requests - Rate limit exceeded |
500 |
Internal Server Error |
Error Response Format
{
"error": "error_description"
}
Frequently Asked Questions
/v1/clone/ endpoint. We'll create a cloned voice that you can use in future generations. Cloned voices work across multiple languages - clone once, generate in any supported language.
format parameter. For voice cloning input, we accept WAV and MP3 reference audio.
Code Examples
import requests
import time
API_KEY = "YOUR_API_TOKEN"
BASE_URL = "https://api.texttospeechai.com/v1"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
# Generate speech
response = requests.post(
f"{BASE_URL}/generate/",
headers=headers,
json={
"text": "Hello, world!",
"voice": "en_US-kristin-medium",
"format": "mp3"
}
)
data = response.json()
uuid = data["uuid"]
# Poll for completion
while True:
status = requests.get(
f"{BASE_URL}/status/{uuid}/",
headers=headers
).json()
if status["status"] == "completed":
print(f"Audio URL: {status['audio_url']}")
break
elif status["status"] == "failed":
print(f"Error: {status['error']}")
break
time.sleep(2)
const API_KEY = 'YOUR_API_TOKEN';
const BASE_URL = 'https://api.texttospeechai.com/v1';
async function generateSpeech(text, voice) {
const response = await fetch(`${BASE_URL}/generate/`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: text,
voice: voice,
format: 'mp3'
})
});
const data = await response.json();
// Poll for completion
while (true) {
const status = await fetch(
`${BASE_URL}/status/${data.uuid}/`,
{ headers: { 'Authorization': `Bearer ${API_KEY}` } }
).then(r => r.json());
if (status.status === 'completed') {
return status.audio_url;
} else if (status.status === 'failed') {
throw new Error(status.error);
}
await new Promise(r => setTimeout(r, 2000));
}
}
// Usage
generateSpeech('Hello, world!', 'en_US-kristin-medium')
.then(url => console.log('Audio URL:', url))
.catch(err => console.error(err));
# Generate speech
curl -X POST "https://api.texttospeechai.com/v1/generate/" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "Hello, world!", "voice": "en_US-kristin-medium"}'
# Check status (replace UUID)
curl "https://api.texttospeechai.com/v1/status/abc123-def456/" \
-H "Authorization: Bearer YOUR_API_TOKEN"
# List voices
curl "https://api.texttospeechai.com/v1/voices/?language=en" \
-H "Authorization: Bearer YOUR_API_TOKEN"
Ready to Build?
Get your free API key and start generating speech in minutes. 1,000 free credits included.
Create Free AccountNo credit card required. 100 API requests/day free.