API-documentatie
Integreer text-to-speech in je toepassingen met onze REST API. Krijg toegang tot 7 TTS-engines, meer dan 250 stemmen en stemklonen.
API-functies
- ✓ 7 TTS-engines
- ✓ Meer dan 250 stemmen
- ✓ Stemklonen
- ✓ 40+ talen
- ✓ MP3, WAV, OGG
Inhoud
Basis-URL
https://api.texttospeechai.com/v1/
Authenticatie
Alle API-verzoeken vereisen een Bearer-token in de Authorization-header.
Je API-token ophalen
- Log in op je accountdashboard
- Ga naar de API-instellingen
- Een nieuw API-token genereren
Aanvraagheader
Authorization: Bearer YOUR_API_TOKEN
Voorbeeld (cURL)
curl -X GET "https://api.texttospeechai.com/v1/account/" \
-H "Authorization: Bearer YOUR_API_TOKEN"
Gebruikslimieten
API-verzoeken worden beperkt op basis van je accountniveau:
| Niveau | Requests/Day |
|---|---|
| Gratis | 100 |
| Premium | 1,000 |
| Enterprise | 10,000 |
De gebruikslimieten worden om middernacht UTC gereset. Controleer de X-RateLimit-* headers in API-reacties.
Spraak genereren
Maak een nieuw text-to-speech-generatieverzoek.
/v1/generate/
Aanvraagbody
| Parameter | Type | Verplicht | Beschrijving |
|---|---|---|---|
text |
string | Ja | Te synthetiseren tekst (max. 5000 tekens) |
voice |
string | Ja | Stem-slug (bijv. "en_US-kristin-medium") |
speed |
float | Nee | Spreeksnelheid 0.5-2.0 (standaard 1.0) |
pitch |
float | Nee | Toonhoogte-aanpassing 0.5-2.0 (standaard 1.0) |
format |
string | Nee | Uitvoerformaat: mp3, wav, ogg (standaard mp3) |
Voorbeeldverzoek
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"
}'
Antwoord
{
"uuid": "abc123-def456-...",
"status": "pending",
"text_length": 35,
"voice": "en_US-kristin-medium",
"credits_used": 0.35,
"estimated_time": 5
}
Stemmen weergeven
Haal beschikbare stemmen op met optionele filtering.
/v1/voices/
Queryparameters
| Parameter | Beschrijving |
|---|---|
language |
Filteren op taalcode (bijv. "en") |
gender |
Filteren op geslacht (mannelijk/vrouwelijk/neutraal) |
model_type |
Filteren op TTS-engine (piper, vits, bark, styletts2, tortoise) |
page |
Paginanummer (standaard 1) |
per_page |
Resultaten per pagina (standaard 50, max. 100) |
Voorbeeldverzoek
curl "https://api.texttospeechai.com/v1/voices/?language=en&gender=female" \
-H "Authorization: Bearer YOUR_API_TOKEN"
Status controleren
Controleer de status van een generatieverzoek.
/v1/status/{uuid}/
Statuswaarden
pending- Aanvraag in de wachtrij voor verwerkingprocessing- Genereert op dit moment audiocompleted- Audio klaar om te downloadenfailed- Generatie mislukt (zie het veld error)
Antwoord (voltooid)
{
"uuid": "abc123-def456-...",
"status": "completed",
"audio_url": "https://texttospeechai.com/uploads/generations/...",
"duration_seconds": 2.5,
"processing_time_ms": 1200
}
Stemklonen
Maak een gekloonde stem op basis van referentie-audio.
/v1/clone/
Aanvraag (multipart/form-data)
| Parameter | Type | Verplicht | Beschrijving |
|---|---|---|---|
name |
string | Ja | Naam voor de gekloonde stem |
audio |
bestand | Ja | Referentie-audio (WAV/MP3, 6-60 seconden) |
language |
string | Nee | Taalcode (standaard "en") |
Voorbeeldverzoek
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"
Accountgegevens
Haal accountinformatie en creditsaldo op.
/v1/account/
Antwoord
{
"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"
}
}
Foutcodes
| Code | Beschrijving |
|---|---|
400 |
Bad Request: ongeldige parameters |
401 |
Unauthorized: ongeldig of ontbrekend API-token |
402 |
Payment Required: onvoldoende credits |
404 |
Not Found: resource niet gevonden |
429 |
Too Many Requests: gebruikslimiet overschreden |
500 |
Interne serverfout |
Formaat van de foutreactie
{
"error": "error_description"
}
Veelgestelde vragen
/v1/clone/ endpoint. We maken een gekloonde stem die je in toekomstige generaties kunt gebruiken. Gekloonde stemmen werken in meerdere talen: één keer klonen, genereren in elke ondersteunde taal.
format parameter. Voor invoer bij stemklonen accepteren we WAV- en MP3-referentie-audio.
Codevoorbeelden
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"
Klaar om te bouwen?
Haal je gratis API-sleutel op en genereer binnen enkele minuten spraak. 1,000 gratis credits inbegrepen.
Gratis account aanmakenGeen creditcard nodig. 100 API-verzoeken/dag gratis.