ElevenLabs Zamiana tekstu na dźwięk
Użyj punktu końcowego text to sound, aby utworzyć asynchroniczne zadanie.
Omówienie
Użyj punktu końcowego text to sound z wymaganymi danymi wejściowymi. Użyj zwróconego identyfikatora zadania, aby pobrać jego stan, lub podaj callback_url dla dostarczeń udokumentowanych poniżej.
Szybki start
- Utwórz klucz API i ustaw go jako RUNAPI_API_KEY.
- Wyślij żądanie POST, którego treść odpowiada schematowi żądania.
- Zapisz zwrócony identyfikator zadania, a następnie odpytuj do momentu osiągnięcia stanu końcowego lub obsłuż wywołania zwrotne opisane poniżej.
Punkt końcowy
- Bazowy URL
https://runapi.ai- Wersja API
v1- Uwierzytelnianie
Authorization: Bearer YOUR_API_TOKEN
Obsługiwane modele
Otwórz stronę modelu, aby zapoznać się z aktualnymi cenami, limitami żądań i szczegółami dotyczącymi użytku komercyjnego.
Schemat żądania
Wysyłaj wyłącznie udokumentowane pola. Gdy podany jest callback_url, odbiera on dostarczenia zadania opisane poniżej.
sound-effect-v26 pola
callback_urlstringduration_secondsnumberloopbooleanoutput_formatstringmp3_22050_32, mp3_44100_32, mp3_44100_64, mp3_44100_96, mp3_44100_128, mp3_44100_192, pcm_8000, pcm_16000, pcm_22050, pcm_24000, pcm_44100, pcm_48000, ulaw_8000, alaw_8000, opus_48000_32, opus_48000_64, opus_48000_96, opus_48000_128, opus_48000_192
prompt_influencenumbertextstringTworzenie akceptacji
POST /api/v1/elevenlabs/text_to_sound
Schemat odpowiedzi
{
"properties": {
"billing": {
"properties": {
"refund": {
"oneOf": [
{
"properties": {
"refunded_at": {
"type": "string"
}
},
"required": [
"refunded_at"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
},
"reservation": {
"oneOf": [
{
"properties": {
"amount_cents": {
"type": "integer"
}
},
"required": [
"amount_cents"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
},
"settlement": {
"oneOf": [
{
"properties": {
"amount_micro_cents": {
"type": "integer"
},
"charged_amount_cents": {
"type": "integer"
}
},
"required": [
"charged_amount_cents",
"amount_micro_cents"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
}
},
"required": [
"reservation",
"settlement",
"refund"
],
"type": "object",
"unevaluatedProperties": false
},
"id": {
"type": "string"
},
"status": {
"enum": [
"processing"
],
"type": "string"
},
"task_replayed": {
"type": "boolean"
}
},
"required": [
"id",
"status",
"billing"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"id": "tsk_reference_demo",
"status": "processing"
}
Odpytywanie w toku
GET /api/v1/elevenlabs/text_to_sound/:id
Schemat odpowiedzi
{
"properties": {
"billing": {
"properties": {
"refund": {
"oneOf": [
{
"properties": {
"refunded_at": {
"type": "string"
}
},
"required": [
"refunded_at"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
},
"reservation": {
"oneOf": [
{
"properties": {
"amount_cents": {
"type": "integer"
}
},
"required": [
"amount_cents"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
},
"settlement": {
"oneOf": [
{
"properties": {
"amount_micro_cents": {
"type": "integer"
},
"charged_amount_cents": {
"type": "integer"
}
},
"required": [
"charged_amount_cents",
"amount_micro_cents"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
}
},
"required": [
"reservation",
"settlement",
"refund"
],
"type": "object",
"unevaluatedProperties": false
},
"id": {
"type": "string"
},
"status": {
"enum": [
"processing"
],
"type": "string"
}
},
"required": [
"id",
"status",
"billing"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"id": "tsk_reference_demo",
"status": "processing"
}
Odpytywanie zakończone
GET /api/v1/elevenlabs/text_to_sound/:id
Schemat odpowiedzi
{
"properties": {
"audios": {
"items": {
"properties": {
"url": {
"type": "string",
"x-runapi-generated-media": true
}
},
"required": [
"url"
],
"type": "object",
"unevaluatedProperties": false
},
"type": "array"
},
"billing": {
"properties": {
"refund": {
"oneOf": [
{
"properties": {
"refunded_at": {
"type": "string"
}
},
"required": [
"refunded_at"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
},
"reservation": {
"oneOf": [
{
"properties": {
"amount_cents": {
"type": "integer"
}
},
"required": [
"amount_cents"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
},
"settlement": {
"oneOf": [
{
"properties": {
"amount_micro_cents": {
"type": "integer"
},
"charged_amount_cents": {
"type": "integer"
}
},
"required": [
"charged_amount_cents",
"amount_micro_cents"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
}
},
"required": [
"reservation",
"settlement",
"refund"
],
"type": "object",
"unevaluatedProperties": false
},
"id": {
"type": "string"
},
"status": {
"enum": [
"completed"
],
"type": "string"
}
},
"required": [
"id",
"status",
"audios",
"billing"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"audios": [
{
"url": "https://file.runapi.ai/reference-audio.mp3"
}
],
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"id": "tsk_reference_demo",
"status": "completed"
}
Odpytywanie nie powiodło się
GET /api/v1/elevenlabs/text_to_sound/:id
Schemat odpowiedzi
{
"properties": {
"billing": {
"properties": {
"refund": {
"oneOf": [
{
"properties": {
"refunded_at": {
"type": "string"
}
},
"required": [
"refunded_at"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
},
"reservation": {
"oneOf": [
{
"properties": {
"amount_cents": {
"type": "integer"
}
},
"required": [
"amount_cents"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
},
"settlement": {
"oneOf": [
{
"properties": {
"amount_micro_cents": {
"type": "integer"
},
"charged_amount_cents": {
"type": "integer"
}
},
"required": [
"charged_amount_cents",
"amount_micro_cents"
],
"type": "object",
"unevaluatedProperties": false
},
{
"enum": [
null
]
}
]
}
},
"required": [
"reservation",
"settlement",
"refund"
],
"type": "object",
"unevaluatedProperties": false
},
"error": {
"type": "string"
},
"id": {
"type": "string"
},
"status": {
"enum": [
"failed"
],
"type": "string"
}
},
"required": [
"id",
"status",
"error",
"billing"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"billing": {
"refund": null,
"reservation": null,
"settlement": null
},
"error": "Task processing failed.",
"id": "tsk_reference_demo",
"status": "failed"
}
Wywołanie zwrotne klienta: ukończono
POST callback_url
Schemat odpowiedzi
{
"properties": {
"audios": {
"items": {
"properties": {
"url": {
"type": "string",
"x-runapi-generated-media": true
}
},
"required": [
"url"
],
"type": "object",
"unevaluatedProperties": false
},
"type": "array"
},
"id": {
"type": "string"
},
"status": {
"enum": [
"completed"
],
"type": "string"
}
},
"required": [
"id",
"status",
"audios"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"audios": [
{
"url": "https://file.runapi.ai/reference-audio.mp3"
}
],
"id": "tsk_reference_demo",
"status": "completed"
}
Wywołanie zwrotne klienta: niepowodzenie
POST callback_url
Schemat odpowiedzi
{
"properties": {
"error": {
"oneOf": [
{
"type": "string"
},
{
"properties": {
"code": {
"type": "string"
},
"limit_cents": {
"type": "integer"
},
"message": {
"type": "string"
},
"reset_at": {
"format": "date-time",
"type": [
"string",
"null"
]
},
"used_cents": {
"type": "integer"
},
"window": {
"enum": [
"1h",
"1d",
"7d",
"daily",
"weekly",
"monthly",
"lifetime"
],
"type": "string"
}
},
"required": [
"code",
"message"
],
"type": "object",
"unevaluatedProperties": false
}
]
},
"id": {
"type": "string"
},
"status": {
"enum": [
"failed"
],
"type": "string"
}
},
"required": [
"id",
"status",
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"error": {
"code": "generation_failed",
"message": "Task processing failed."
},
"id": "tsk_reference_demo",
"status": "failed"
}
Błędy
POST /api/v1/elevenlabs/text_to_sound
Schemat odpowiedzi
{
"properties": {
"error": {
"description": "Czytelny dla człowieka komunikat o błędzie.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"error": "Authentication required"
}
Błędy
GET /api/v1/elevenlabs/text_to_sound/:id
Schemat odpowiedzi
{
"properties": {
"error": {
"description": "Czytelny dla człowieka komunikat o błędzie.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"error": "Authentication required"
}
Błędy
POST /api/v1/elevenlabs/text_to_sound
Schemat odpowiedzi
{
"oneOf": [
{
"properties": {
"error": {
"description": "Czytelny dla człowieka komunikat o błędzie.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
},
{
"properties": {
"error": {
"description": "Czytelne dla człowieka podsumowanie walidacji.",
"type": "string"
},
"errors": {
"additionalProperties": {
"items": {
"type": "string"
},
"type": "array"
},
"description": "Komunikaty walidacyjne identyfikowane przez publiczne pole żądania, z tablicą czytelnych dla człowieka ciągów znaków dla każdego pola.",
"type": "object"
}
},
"required": [
"error",
"errors"
],
"type": "object",
"unevaluatedProperties": false
}
]
}
Przykład odpowiedzi
{
"error": "Validation failed",
"errors": {
"text": [
"is required"
]
}
}
Błędy
POST /api/v1/elevenlabs/text_to_sound
Schemat odpowiedzi
{
"properties": {
"error": {
"description": "Czytelny dla człowieka komunikat o błędzie.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"error": "Insufficient balance"
}
Błędy
POST /api/v1/elevenlabs/text_to_sound
Schemat odpowiedzi
{
"properties": {
"error": {
"description": "Czytelny dla człowieka komunikat o błędzie.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"error": "API key credit limit exceeded"
}
Błędy
POST /api/v1/elevenlabs/text_to_sound
Schemat odpowiedzi
{
"properties": {
"error": {
"description": "Czytelny dla człowieka komunikat o błędzie.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"error": "The request uses features that are not supported for the selected model"
}
Błędy
POST /api/v1/elevenlabs/text_to_sound
Schemat odpowiedzi
{
"properties": {
"error": {
"description": "Czytelny dla człowieka komunikat o błędzie.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"error": "Rate limit reached. Please retry later."
}
Błędy
POST /api/v1/elevenlabs/text_to_sound
Schemat odpowiedzi
{
"properties": {
"error": {
"description": "Czytelny dla człowieka komunikat o błędzie.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"error": "Service under maintenance, please try again later"
}
Błędy
POST /api/v1/elevenlabs/text_to_sound
Schemat odpowiedzi
{
"properties": {
"error": {
"description": "Czytelny dla człowieka komunikat o błędzie.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"error": "The request timed out"
}
Błędy
GET /api/v1/elevenlabs/text_to_sound/:id
Schemat odpowiedzi
{
"properties": {
"error": {
"description": "Czytelny dla człowieka komunikat o błędzie.",
"type": "string"
}
},
"required": [
"error"
],
"type": "object",
"unevaluatedProperties": false
}
Przykład odpowiedzi
{
"error": "Task with id 'tsk_reference_demo' not found"
}
Wygenerowane przykłady kodu
Używaj bezpośrednio cURL lub zainstaluj SDK dla swojego języka. Każdy przykład przesyła zwalidowane żądanie pokazane w tej dokumentacji.
Instalacja
pip install runapi-elevenlabs
import os
from runapi.elevenlabs import ElevenlabsClient
client = ElevenlabsClient(api_key=os.environ["RUNAPI_API_KEY"])
task = client.text_to_sound.create(
text="Heavy rain on a tin roof.",
loop=False,
duration_seconds=5,
prompt_influence=0.8,
output_format="mp3_44100_128"
)