Giọng nói AI ElevenLabs

Giọng nói AI tự nhiên nhất với khả năng kiểm soát cảm xúc và hỗ trợ nhiều ngôn ngữ.

✓ Giọng nói tự nhiên

✓ Kiểm soát cảm xúc

✓ 29 ngôn ngữ

✓ Nhân bản giọng nói

Xác thực

Để truy cập ElevenLabs thông qua Doitong API, hãy sử dụng mã API (API key) của bạn. Hãy đính kèm mã này vào mutation GraphQL hoặc header của REST API.

Quan trọng: Hãy bảo mật mã Doitong API của bạn và tuyệt đối không để lộ trong mã nguồn phía client. Luôn thực hiện các lệnh gọi API từ máy chủ backend của bạn.
// GraphQL Header
{
  "Authorization": "Bearer YOUR_API_KEY"
}

// REST Header
"X-API-Key": "YOUR_API_KEY"

Bắt đầu nhanh

Bắt đầu với ElevenLabs TTS API chỉ trong vài phút. Làm theo các bước đơn giản sau để tạo tts đầu tiên của bạn.

Bước 1: Lấy mã API

Đăng ký tài khoản Doitong và đi tới bảng điều khiển để tạo mã API.

Bước 2: Thực hiện yêu cầu đầu tiên

Sử dụng một trong các ví dụ mã dưới đây để thực hiện lệnh gọi API đầu tiên.

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"
    }
  }
}

Bảng giá

ElevenLabs TTS API sử dụng mô hình tính phí theo tín dụng (credit). Tín dụng sẽ được tiêu thụ dựa trên độ phức tạp và thời lượng của nội dung được tạo.

Tính năng Tín dụng Mô tả
Giọng đọc Tiêu chuẩn 1 tín dụng mỗi 100 ký tự Giọng đọc AI cơ bản
Giọng đọc Cao cấp 2 tín dụng mỗi 100 ký tự Giọng đọc AI nâng cao với cảm xúc

Điểm cuối API

ElevenLabs TTS API khả dụng thông qua điểm cuối GraphQL hợp nhất của chúng tôi.

Điểm cuối GraphQL

POST https://api.doitong.com/graphql

Điểm cuối REST

POST https://api.doitong.com/v1/tts

Tham số

Các tham số khả dụng cho yêu cầu ElevenLabs TTS API:

Tham số Loại Bắt buộc Mô tả
service Chuỗi Yes Định danh dịch vụ: "elevenlabs"
version Chuỗi No Model version: "eleven-turbo-v2"
webhookUrl Chuỗi No URL để nhận thông báo khi hoàn tất

Định dạng phản hồi

Tất cả phản hồi API đều tuân theo một định dạng nhất quán:

Phản hồi thành công

{
  "data": {
    "tts": {
      "id": "abc123xyz",
      "status": "processing",
      "url": null,
      "webhookUrl": "https://your-webhook.com/callback",
      "createdAt": "2024-01-01T00:00:00Z"
    }
  }
}

Phản hồi hoàn tất

{
  "data": {
    "tts": {
      "id": "abc123xyz",
      "status": "completed",
      "url": "https://cdn.doitong.com/outputs/abc123xyz.mp3",
      "duration": null,
      "createdAt": "2024-01-01T00:00:00Z"
    }
  }
}

Xử lý lỗi

API sử dụng các mã trạng thái HTTP tiêu chuẩn và trả về thông báo lỗi chi tiết.

Các mã lỗi phổ biến

Mã trạng thái Loại lỗi Mô tả
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

Định dạng phản hồi lỗi

{
  "errors": [
    {
      "message": "Insufficient credits for this operation",
      "extensions": {
        "code": "INSUFFICIENT_CREDITS",
        "creditsRequired": 100,
        "creditsAvailable": 50
      }
    }
  ]
}

Webhooks

Nhận thông báo theo thời gian thực khi quá trình tạo tts của bạn hoàn tất.

Thiết lập Webhooks

Include a <code>webhookUrl</code> parameter in your request to receive a POST notification when processing is complete.

Dữ liệu Webhook (Payload)

{
  "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
  }
}

Bảo mật Webhook

Tất cả các yêu cầu webhook đều bao gồm một header chữ ký để xác thực:

X-Doitong-Signature: sha256=abc123...

Giới hạn tốc độ

Để đảm bảo sử dụng công bằng và ổn định hệ thống, các giới hạn tốc độ sau sẽ được áp dụng:

Gói dịch vụ Yêu cầu/Phút Công việc đồng thời Giới hạn hàng ngày
Miễn phí 10 1 100
Khởi đầu 30 3 1,000
Chuyên nghiệp 60 10 10,000
Doanh nghiệp Tùy chỉnh Tùy chỉnh Không giới hạn
Header giới hạn tốc độ: Kiểm tra các header phản hồi để biết trạng thái giới hạn hiện tại:
  • X-RateLimit-Limit: Maximum requests per window
  • X-RateLimit-Remaining: Requests remaining
  • X-RateLimit-Reset: Window reset timestamp

Lời khuyên hữu ích

1. Tối ưu hóa câu lệnh (Prompt)

Viết các câu lệnh rõ ràng, chi tiết để có kết quả tốt nhất:

  • Be specific about visual elements, style, and mood
  • Include details about lighting, camera angles, and composition
  • Avoid contradictory or impossible requests

2. Xử lý bất đồng bộ

Quá trình tạo là bất đồng bộ. Hãy triển khai cơ chế polling hoặc webhook phù hợp:

// 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. Khôi phục lỗi

Triển khai logic thử lại (retry) với khoảng thời gian chờ tăng dần (exponential backoff):

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. Theo dõi mức sử dụng tín dụng

Theo dõi lượng tiêu thụ tín dụng của bạn để tránh bị gián đoạn:

  • Check credit balance before large batch operations
  • Set up alerts for low credit thresholds
  • Implement credit-aware request queuing

Sẵn sàng bắt đầu?

Tham gia cùng hàng ngàn nhà phát triển đang sử dụng ElevenLabs TTS API để tạo ra nội dung tuyệt vời

Lấy mã API ngay Xem bảng giá