Chuyển đến nội dung chính

Nội dung yêu cầu

Timeout cho yêu cầu đồng bộ: endpoint không phải chat này chờ model được định tuyến hoàn tất. Input lớn, audio dài, hoặc batch lớn có thể vượt quá mặc định 30s phổ biến của client, vì vậy hãy đặt timeout của HTTP client ít nhất là 120s. Các field tuỳ chọn được hỗ trợ khác nhau theo từng họ model. TokenLab kiểm tra ma trận field này trước khi routing: OpenAI TTS nhận voice, instructions, response_format, stream_format, và speed; MiniMax speech nhận voice, voice_id, response_format, stream_format, và speed; Gemini TTS nhận prompt, language_code, voice, response_format, stream_format, speed, và temperature; các route TTS hẹp hơn kiểu Vidu/Kling có thể chỉ nhận inputstream_format. Field top-level không xác định, bao gồm user, sẽ trả về 400 unsupported_parameter thay vì bị bỏ qua.
model
string
mặc định:"tts-1"
Model TTS. Ví dụ gồm tts-1, gpt-4o-mini-tts, speech-02-hd, và gemini-2.5-flash-tts. Gọi GET /v1/models?recommended_for=tts để lấy danh sách hiện tại.
input
string
bắt buộc
Văn bản dùng để tạo audio. Tối đa 4096 ký tự.
voice
string | object
Bộ chọn giọng nói. Truyền tên giọng dựng sẵn như nova, giọng Gemini như Kore, hoặc object như { "id": "voice-id" } cho giọng tuỳ chỉnh tương thích.
voice_id
string
Bộ chọn giọng native của provider cho các model speech tương thích MiniMax.
instructions
string
Chỉ dẫn style hoặc cách đọc tuỳ chọn cho các model TTS tương thích OpenAI có hỗ trợ.
prompt
string
Prompt style nói tuỳ chọn cho model Gemini TTS.
language_code
string
Mã ngôn ngữ tuỳ chọn, ví dụ en-US, cho các route Gemini, xAI và TTS tương thích.
response_format
string
Định dạng audio. Giá trị phổ biến gồm mp3, opus, aac, flac, wav, và pcm; giá trị được hỗ trợ khác nhau theo họ model.
stream_format
string
mặc định:"audio"
Định dạng trả về của TokenLab: audio hoặc sse. stream_format=sse không được hỗ trợ cho tts-1 hoặc tts-1-hd.
speed
number
Tốc độ nói cho các họ model có hỗ trợ (0.25 đến 4.0).
temperature
number
Sampling temperature cho các route TTS tương thích Gemini (0 đến 2).

Phản hồi

Trả về tệp audio theo định dạng đã yêu cầu.
curl -X POST "https://api.tokenlab.sh/v1/audio/speech" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tts-1-hd",
    "voice": "nova",
    "input": "Hello, welcome to TokenLab!"
  }' \
  --output speech.mp3
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-api-key",
    base_url="https://api.tokenlab.sh/v1"
)

response = client.audio.speech.create(
    model="tts-1-hd",
    voice="nova",
    input="Hello, welcome to TokenLab!"
)

response.stream_to_file("speech.mp3")
import OpenAI from 'openai';
import fs from 'fs';

const client = new OpenAI({
  apiKey: 'sk-your-api-key',
  baseURL: 'https://api.tokenlab.sh/v1'
});

const response = await client.audio.speech.create({
  model: 'tts-1-hd',
  voice: 'nova',
  input: 'Hello, welcome to TokenLab!'
});

const buffer = Buffer.from(await response.arrayBuffer());
fs.writeFileSync('speech.mp3', buffer);
<?php
$ch = curl_init('https://api.tokenlab.sh/v1/audio/speech');

curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'Authorization: Bearer sk-your-api-key'
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'model' => 'tts-1-hd',
        'voice' => 'nova',
        'input' => 'Hello, welcome to TokenLab!'
    ])
]);

$audio = curl_exec($ch);
curl_close($ch);

file_put_contents('speech.mp3', $audio);

Mẫu giọng nói

VoiceMô tả
alloyTrung tính, cân bằng
ashĐiềm tĩnh, chuẩn mực
balladDu dương, giàu biểu cảm
coralẤm áp, cuốn hút
echoẤm áp, mang tính hội thoại
fableGiàu biểu cảm, phù hợp kể chuyện
novaThân thiện, rõ ràng
onyxTrầm, uy quyền
sageUyên bác, sâu sắc
shimmerMềm mại, dịu dàng
verseNăng động, linh hoạt

Ví dụ phản hồi

<binary audio data>

Trường quan trọng

Content-Type
string
Loại event hoặc message do API trả về.
body
binary
Nội dung phản hồi thô. Lưu trực tiếp, không parse như JSON.