ElevenLabs Voice AI
Najbolj naravni AI glasovi z nadzorom čustev in podporo za več jezikov.
✓ Naravni glasovi
✓ Nadzor čustev
✓ 29 jezikov
✓ Kloniranje glasu
Avtentikacija
Za dostop do storitve ElevenLabs prek API-ja Doitong uporabite svoj API ključ. Vključite ga v mutacijo GraphQL ali v glave REST API-ja.
// GraphQL Header
{
"Authorization": "Bearer YOUR_API_KEY"
}
// REST Header
"X-API-Key": "YOUR_API_KEY"
Hitri začetek
Začnite uporabljati ElevenLabs TTS API v le nekaj minutah. Sledite tem preprostim korakom za ustvarjanje svoje prve tts.
1. korak: Pridobite API ključ
Registrirajte se za račun Doitong in v nadzorni plošči ustvarite svoj API ključ.
2. korak: Izvedite prvo zahtevo
Uporabite enega od spodnjih primerov kode za svoj prvi klic API.
curl -X POST https://api.doitong.com/graphql \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"query": "mutation Generate($input: GenerateInput!) { generate(input: $input) { id status type provider url metadata creditCost } }",
"variables": {
"input": {
"type": "AUDIO",
"provider": "elevenlabs",
"input": {
"text": "Hello world, this is a text to speech example.",
"voice": "en-US-neural"
},
"options": {
"speed": 1.0
}
}
}
}'
const response = await fetch('https://api.doitong.com/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
query: `
mutation GenerateSpeech($input: TTSInput!) {
generateSpeech(input: $input) {
id
audioUrl
duration
}
}
`,
variables: {
input: {
service: 'elevenlabs',
text: 'Hello world, this is a text to speech example.',
voice: 'en-US-neural',
speed: 1.0
}
}
})
});
const data = await response.json();
console.log('Result:', data.data.generate);
import requests
import json
url = "https://api.doitong.com/graphql"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
}
query = """
mutation Generate($input: GenerateInput!) {
generate(input: $input) {
id
status
type
provider
url
metadata
creditCost
}
}
"""
variables = {
"input": {
"type": "AUDIO",
"provider": "elevenlabs",
"input": {
"text": "Hello world, this is a text to speech example.",
"voice": "en-US-neural"
},
"options": {
"speed": 1.0
}
}
}
response = requests.post(url, json={
"query": query,
"variables": variables
}, headers=headers)
data = response.json()
print("Result:", data["data"]["generate"])
mutation Generate($input: GenerateInput!) {
generate(input: $input) {
id
status
type
provider
url
metadata
creditCost
createdAt
}
}
# Variables
{
"input": {
"type": "AUDIO",
"provider": "elevenlabs",
"input": {
"text": "Hello world, this is a text to speech example.",
"voice": "en-US-neural"
},
"options": {
"speed": 1.0,
"pitch": 1.0,
"language": "en",
"version": "eleven-turbo-v2"
}
}
}
Cenik
ElevenLabs TTS API uporablja model cen na podlagi kreditov. Krediti se porabijo glede na kompleksnost in trajanje ustvarjene vsebine.
| Funkcija | Krediti | Opis |
|---|---|---|
| Standardni glas | 1 kredit na 100 znakov | Osnovni nevralni glasovi |
| Premium glas | 2 kredita na 100 znakov | Napredni nevralni glasovi s čustvenim izrazom |
Končne točke API
ElevenLabs TTS API je na voljo prek naše enotne končne točke GraphQL.
Končna točka GraphQL
POST https://api.doitong.com/graphql
Končna točka REST
POST https://api.doitong.com/v1/tts
Parametri
Razpoložljivi parametri za zahteve ElevenLabs TTS API:
| Parameter | Vrsta | Obvezno | Opis |
|---|---|---|---|
service |
Niz | Yes | Identifikator storitve: "elevenlabs" |
version |
Niz | No | Model version: "eleven-turbo-v2" |
webhookUrl |
Niz | No | URL za prejem obvestil o dokončanju |
Format odgovora
Vsi odgovori API-ja sledijo enotnemu formatu:
Odgovor ob uspehu
{
"data": {
"tts": {
"id": "abc123xyz",
"status": "processing",
"url": null,
"webhookUrl": "https://your-webhook.com/callback",
"createdAt": "2024-01-01T00:00:00Z"
}
}
}
Odgovor ob dokončanju
{
"data": {
"tts": {
"id": "abc123xyz",
"status": "completed",
"url": "https://cdn.doitong.com/outputs/abc123xyz.mp3",
"duration": null,
"createdAt": "2024-01-01T00:00:00Z"
}
}
}
Obravnava napak
API uporablja standardne statusne kode HTTP in vrača podrobna sporočila o napakah.
Pogoste kode napak
| Statusna koda | Vrsta napake | Opis |
|---|---|---|
| 400 | Bad Request | Invalid parameters or malformed request |
| 401 | Unauthorized | Missing or invalid API key |
| 402 | Payment Required | Insufficient credits |
| 429 | Too Many Requests | Rate limit exceeded |
| 500 | Internal Server Error | Server error, please retry |
Format odgovora ob napaki
{
"errors": [
{
"message": "Insufficient credits for this operation",
"extensions": {
"code": "INSUFFICIENT_CREDITS",
"creditsRequired": 100,
"creditsAvailable": 50
}
}
]
}
Webhooki
Prejemajte obvestila v realnem času, ko je generiranje vaše tts končano.
Nastavitev webhookov
Include a <code>webhookUrl</code> parameter in your request to receive a POST notification when processing is complete.
Vsebina webhooka
{
"id": "abc123xyz",
"status": "completed",
"url": "https://cdn.doitong.com/outputs/abc123xyz.mp3",
"service": "elevenlabs",
"createdAt": "2024-01-01T00:00:00Z",
"completedAt": "2024-01-01T00:01:00Z",
"metadata": {
"duration": null,
"width": null,
"height": null
}
}
Varnost webhookov
Vse zahteve webhookov vključujejo glavo s podpisom za preverjanje:
X-Doitong-Signature: sha256=abc123...
Omejitve števila zahtev
Za zagotavljanje poštene uporabe in stabilnosti sistema veljajo naslednje omejitve:
| Paket | Zahtev/minuto | Vzporedna opravila | Dnevna omejitev |
|---|---|---|---|
| Brezplačno | 10 | 1 | 100 |
| Starter | 30 | 3 | 1,000 |
| Pro | 60 | 10 | 10,000 |
| Enterprise | Po meri | Po meri | Neomejeno |
X-RateLimit-Limit: Maximum requests per windowX-RateLimit-Remaining: Requests remainingX-RateLimit-Reset: Window reset timestamp
Najboljše prakse
1. Optimizirajte svoje pozive
Za najboljše rezultate pišite jasne in opisne pozive:
- Be specific about visual elements, style, and mood
- Include details about lighting, camera angles, and composition
- Avoid contradictory or impossible requests
2. Upravljajte asinhrono obdelavo
Generiranje je asinhrono. Implementirajte ustrezno poizvedovanje (polling) ali webhooke:
// Polling example
async function pollStatus(jobId) {
let status = 'processing';
while (status === 'processing') {
await sleep(2000); // Wait 2 seconds
const result = await checkJobStatus(jobId);
status = result.status;
}
return result;
}
3. Obnovitev po napakah
Implementirajte logiko ponovnega poskusa z eksponentnim zamikom:
async function retryWithBackoff(fn, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (error) {
if (i === maxRetries - 1) throw error;
await sleep(Math.pow(2, i) * 1000);
}
}
}
4. Spremljajte porabo kreditov
Sledite porabi kreditov, da se izognete prekinitvam storitve:
- Check credit balance before large batch operations
- Set up alerts for low credit thresholds
- Implement credit-aware request queuing
Ste pripravljeni na začetek?
Pridružite se tisočem razvijalcev, ki uporabljajo ElevenLabs TTS API za ustvarjanje neverjetnih vsebin