API ElevenLabs trên APIMaster
Dùng khóa API APIMaster trong tiêu đề `Authorization: Bearer`. Các điểm cuối có tiền tố `/v1/elevenlabs`. Liên kết tham số dẫn đến tài liệu ElevenLabs.
Dùng khóa API APIMaster trong tiêu đề Authorization: Bearer. Các điểm cuối có tiền tố /v1/elevenlabs. Liên kết tham số dẫn đến tài liệu ElevenLabs.
Tải lên tệp cục bộ. URL từ xa và webhook phiên âm không khả dụng. Thiết kế giọng cần ít nhất 100 ký tự văn bản nghe thử. Chỉ định thời lượng nhạc và hiệu ứng. WebSocket của APIMaster xử lý thông tin xác thực. Sau khi xác nhận âm thanh, gửi response.create rồi đợi response.done.
Mô hình và điểm cuối
| Tính năng | ID mô hình | Điểm cuối chính thức | Tham số chính |
|---|---|---|---|
| Tổng hợp giọng nói và hội thoại | eleven_v4, eleven_v4_turbo, eleven_v3, eleven_v3_conversational, eleven_multilingual_v2, eleven_flash_v2_5, eleven_flash_v2, eleven_turbo_v2_5, eleven_turbo_v2 |
POST /v1/elevenlabs/text-to-speech/{voice_id} · POST /v1/elevenlabs/text-to-dialogue |
text · model_id · voice_settings · language_code · output_format · inputs[].voice_id · inputs[].text |
| Chuyển tệp thành văn bản | scribe_v3, scribe_v2, scribe_v2_medical |
POST /v1/elevenlabs/speech-to-text |
model_id · file · language_code · diarize · timestamps_granularity · keyterms · transcript_edit |
| Chuyển lời nói thành văn bản theo thời gian thực | scribe_v3_live, scribe_v2_realtime |
WSS /v1/elevenlabs/speech-to-text/realtime |
model_id · audio_format · commit_strategy · audio_base_64 · commit |
| Đổi giọng | eleven_multilingual_sts_v2, eleven_english_sts_v2 |
POST /v1/elevenlabs/voice-changer/{voice_id} |
audio · model_id · remove_background_noise · voice_settings · output_format |
| Thiết kế giọng | eleven_ttv_v3, eleven_multilingual_ttv_v2 |
POST /v1/elevenlabs/text-to-voice/design |
model_id · voice_description · text · guidance_scale · seed |
| Hiệu ứng âm thanh | eleven_text_to_sound_v3, eleven_text_to_sound_v2 |
POST /v1/elevenlabs/sound-generation |
model_id · text · duration_seconds · loop · prompt_influence |
| Âm nhạc | music_v2_5, music_v2, music_v1 |
POST /v1/elevenlabs/music |
model_id · prompt · composition_plan · music_length_ms · force_instrumental |
| Hội thoại thời gian thực | eleven_realtime_v1_mini, eleven_realtime_v1_max |
WSS /v1/elevenlabs/realtime |
model · input_audio_buffer.append · response.create |
| Lồng tiếng | dubbing_v2, dubbing_v1 |
POST /v1/elevenlabs/dubbing/project |
model_id · file · source_language · target_language · project_id |
Tham số và phản hồi
voice_idchọn giọng,model_idchọn mô hình,language_codechọn ngôn ngữ vàvoice_settingsđiều chỉnh cách đọc. Mỗi mục tronginputschỉ định văn bản và giọng của một lượt nói.- Tải âm thanh lên bằng
file.diarizephân biệt người nói, còntimestamps_granularityxác định độ chi tiết của mốc thời gian. Khi chạy trực tiếp, gửi các đoạn PCM mã hóa Base64, xác nhận bằngcommitrồi đợicommitted_transcript. - Khi đổi giọng,
voice_idchọn giọng đích. Thiết kế giọng trả về ba bản nghe thử. Nhập ít nhất 100 ký tự vàotext. duration_secondscủa hiệu ứng nhận 0,5–30 giây. Tạo nhạc vớiprompthoặccomposition_plan. Vớiprompt, dùngmusic_length_msđể đặt thời lượng vàforce_instrumentalđể bỏ giọng hát.- Với lồng tiếng, kiểm tra trạng thái dự án và ngôn ngữ theo
project_id, rồi tảioutputs.lossless_audiokhi hoàn tất.
Ví dụ
curl https://apimaster.ai/v1/elevenlabs/text-to-speech/JBFqnCBsd6RMkjVDRZzb \
-H "Authorization: Bearer $APIMASTER_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"model_id":"eleven_v4","text":"Hello from ElevenLabs."}' \
--output speech.mp3
curl https://apimaster.ai/v1/elevenlabs/speech-to-text \
-H "Authorization: Bearer $APIMASTER_API_KEY" \
-F 'model_id=scribe_v3' -F 'file=@speech.mp3' \
-F 'diarize=true' -F 'timestamps_granularity=word'
curl https://apimaster.ai/v1/elevenlabs/music \
-H "Authorization: Bearer $APIMASTER_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"model_id":"music_v2_5","prompt":"Soft piano jingle","music_length_ms":3000,"force_instrumental":true}' \
--output jingle.mp3
curl https://apimaster.ai/v1/elevenlabs/dubbing/project \
-H "Authorization: Bearer $APIMASTER_API_KEY" \
-F 'model_id=dubbing_v2' -F 'file=@speech.mp3' \
-F 'source_language=en' -F 'target_language=es'
curl "https://apimaster.ai/v1/elevenlabs/dubbing/project/$PROJECT_ID" \
-H "Authorization: Bearer $APIMASTER_API_KEY"
curl "https://apimaster.ai/v1/elevenlabs/dubbing/project/$PROJECT_ID/language/$LANGUAGE_ID" \
-H "Authorization: Bearer $APIMASTER_API_KEY"
Định dạng và giới hạn yêu cầu
Gửi yêu cầu tổng hợp giọng nói, hội thoại, thiết kế giọng, hiệu ứng và nhạc dưới dạng application/json tối đa 4 MiB. Đặt output_format trong chuỗi truy vấn. Hội thoại nhiều người hỗ trợ eleven_v4 và eleven_v3. Thêm /stream vào đường dẫn tổng hợp, hội thoại, đổi giọng, nhạc hoặc tách tiếng để nhận phản hồi theo từng phần.
Dùng multipart/form-data để tải lên một tệp. Dùng audio cho đổi giọng và tách tiếng, file cho chép lời, căn chỉnh, tách nhạc thành từng phần và lồng tiếng. Với PCM thô mono 16 kHz, 16 bit little-endian, dùng file_format=pcm_s16le_16.
Nhạc dài từ 3.000 đến 600.000 mili giây. Gửi music_length_ms khi dùng prompt. Với composition_plan, đặt duration_ms cố định cho mỗi đoạn.
Ví dụ hội thoại thời gian thực
Cài websocket-client rồi đặt APIMASTER_API_KEY. Gửi đầu vào sau session.created. Âm thanh đến qua response.audio.delta hoặc response.output_audio.delta. Xem trạng thái và mức sử dụng của lượt hội thoại trong response.done.
import json
import os
from urllib.parse import urlsplit, urlunsplit
from websocket import create_connection
base = urlsplit("https://apimaster.ai/v1")
url = urlunsplit(("wss", base.netloc, base.path.rstrip("/") + "/elevenlabs/realtime",
"model=eleven_realtime_v1_mini", ""))
socket = create_connection(
url, header={"Authorization": "Bearer " + os.environ["APIMASTER_API_KEY"]},
timeout=30,
)
try:
assert json.loads(socket.recv())["type"] == "session.created"
socket.send(json.dumps({
"type": "conversation.item.create",
"item": {"type": "message", "role": "user",
"content": [{"type": "input_text", "text": "Say hello."}]},
}))
socket.send(json.dumps({"type": "response.create"}))
while True:
event = json.loads(socket.recv())
if event["type"] == "error":
raise RuntimeError(event["error"])
if event["type"] == "response.done":
print(event["response"]["status"], event["response"].get("usage"))
break
finally:
socket.close()
Điểm cuối âm thanh độc lập
POST /v1/elevenlabs/audio-isolation·audio,file_formatPOST /v1/elevenlabs/forced-alignment·file,textPOST /v1/elevenlabs/music/stem-separation·file,stem_variation_id(two_stems_v1,six_stems_v1)
Tính phí và khả năng tương thích
Tổng hợp giọng nói tính theo ký tự, các tính năng âm thanh khác tính theo đơn vị thời lượng tương ứng. Hội thoại thời gian thực tính cả phút kết nối và token. Ba bản nghe thử của thiết kế giọng chỉ tính phí một lần theo văn bản. music_v1 dự kiến ngừng vào 2027-01-31 và eleven_text_to_sound_v2 vào 2027-03-01.
