هوش مصنوعی صوتی ElevenLabs
طبیعیترین صداهای هوش مصنوعی با کنترل احساسات و پشتیبانی از چندین زبان.
✓ صداهای طبیعی
✓ کنترل احساسات
✓ ۲۹ زبان مختلف
✓ شبیهسازی صدا (Cloning)
احراز هویت
برای دسترسی به ElevenLabs از طریق API دویتانگ (Doitong)، از کلید API خود استفاده کنید. این کلید را در هدرهای REST API یا Mutationهای GraphQL قرار دهید.
// GraphQL Header
{
"Authorization": "Bearer YOUR_API_KEY"
}
// REST Header
"X-API-Key": "YOUR_API_KEY"
شروع سریع
در عرض چند دقیقه کار با ElevenLabs TTS API را شروع کنید. این مراحل ساده را برای ساخت اولین tts خود دنبال کنید.
مرحله ۱: دریافت کلید API
در سایت دویتانگ ثبتنام کنید و برای ساخت کلید API به پنل کاربری خود بروید.
مرحله ۲: اولین درخواست خود را ارسال کنید
از نمونه کدهای زیر برای ارسال اولین درخواست 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"
}
}
}
قیمتگذاری
سرویس ElevenLabs TTS API از مدل قیمتگذاری مبتنی بر اعتبار (Credit) استفاده میکند. میزان مصرف اعتبار بر اساس پیچیدگی و زمان محتوای تولید شده محاسبه میشود.
| قابلیت | اعتبار | توضیحات |
|---|---|---|
| صدای استاندارد | ۱ اعتبار به ازای هر ۱۰۰ کاراکتر | صداهای عصبی (Neural) پایه |
| صدای ویژه (Premium) | ۲ اعتبار به ازای هر ۱۰۰ کاراکتر | صداهای عصبی پیشرفته با بیان احساسات |
نقاط اتصال API
سرویس ElevenLabs TTS API از طریق نقطه اتصال یکپارچه GraphQL ما در دسترس است.
نقطه اتصال GraphQL
POST https://api.doitong.com/graphql
نقطه اتصال REST
POST https://api.doitong.com/v1/tts
پارامترها
پارامترهای موجود برای درخواستهای ElevenLabs TTS API:
| پارامتر | نوع | اجباری | توضیحات |
|---|---|---|---|
service |
رشته (String) | Yes | شناسه سرویس: "elevenlabs" |
version |
رشته (String) | No | Model version: "eleven-turbo-v2" |
webhookUrl |
رشته (String) | No | آدرس URL برای دریافت اعلانهای تکمیل عملیات |
فرمت پاسخ
تمامی پاسخهای API از یک ساختار ثابت پیروی میکنند:
پاسخ موفق (Success)
{
"data": {
"tts": {
"id": "abc123xyz",
"status": "processing",
"url": null,
"webhookUrl": "https://your-webhook.com/callback",
"createdAt": "2024-01-01T00:00:00Z"
}
}
}
پاسخ تکمیل شده (Completed)
{
"data": {
"tts": {
"id": "abc123xyz",
"status": "completed",
"url": "https://cdn.doitong.com/outputs/abc123xyz.mp3",
"duration": null,
"createdAt": "2024-01-01T00:00:00Z"
}
}
}
مدیریت خطاها
این API از کدهای وضعیت استاندارد HTTP استفاده کرده و پیامهای خطای دقیقی را برمیگرداند.
کدهای خطای رایج
| کد وضعیت | نوع خطا | توضیحات |
|---|---|---|
| 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 |
فرمت پاسخ خطا
{
"errors": [
{
"message": "Insufficient credits for this operation",
"extensions": {
"code": "INSUFFICIENT_CREDITS",
"creditsRequired": 100,
"creditsAvailable": 50
}
}
]
}
وبهوکها (Webhooks)
هنگام اتمام فرآیند تولید tts، اعلانهای لحظهای دریافت کنید.
راهاندازی وبهوکها
Include a <code>webhookUrl</code> parameter in your request to receive a POST notification when processing is complete.
پیکره (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
}
}
امنیت وبهوک
تمامی درخواستهای وبهوک شامل یک هدر امضا (Signature) برای تایید اصالت هستند:
X-Doitong-Signature: sha256=abc123...
محدودیت نرخ فراخوانی
برای اطمینان از استفاده منصفانه و پایداری سیستم، محدودیتهای زیر اعمال میشوند:
| طرح | درخواست در دقیقه | پردازشهای همزمان | محدودیت روزانه |
|---|---|---|---|
| رایگان | 10 | 1 | 100 |
| استارتر | 30 | 3 | 1,000 |
| حرفهای | 60 | 10 | 10,000 |
| سازمانی | سفارشی | سفارشی | نامحدود |
X-RateLimit-Limit: Maximum requests per windowX-RateLimit-Remaining: Requests remainingX-RateLimit-Reset: Window reset timestamp
توصیههای کلیدی
۱. بهینهسازی پرامپتها
برای دریافت بهترین نتیجه، پرامپتهای دقیق و توصیفی بنویسید:
- Be specific about visual elements, style, and mood
- Include details about lighting, camera angles, and composition
- Avoid contradictory or impossible requests
۲. مدیریت پردازشهای نامتقارن
فرآیند تولید محتوا بهصورت نامتقارن (Async) است. از روش Polling یا Webhook استفاده کنید:
// 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;
}
۳. بازیابی خطا
منطق تلاش مجدد (Retry) را با استفاده از عقبنشینی نمایی (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);
}
}
}
۴. نظارت بر مصرف اعتبار
میزان مصرف اعتبار خود را زیر نظر داشته باشید تا از قطع سرویس جلوگیری کنید:
- Check credit balance before large batch operations
- Set up alerts for low credit thresholds
- Implement credit-aware request queuing
آماده شروع هستید؟
به هزاران توسعهدهندهای بپیوندید که از ElevenLabs TTS API برای خلق محتوای شگفتانگیز استفاده میکنند.