API Reference
REST API chuyển văn bản thành giọng nói — hỗ trợ đa ngôn ngữ. Base URL: https://iclever-tts.yez.vn
Xác thực
Mọi endpoint tạo hoặc truy xuất dữ liệu riêng tư đều yêu cầu xác thực. Với tích hợp server-to-server, dùng API Key trong header X-API-Key. Với ứng dụng có người dùng, đăng nhập để lấy Bearer access token.
X-API-Key: ick_your_api_key_here
API Key được cấp qua endpoint Admin hoặc giao diện quản trị. Giữ key như mật khẩu: chỉ lưu ở biến môi trường, không nhúng vào app web/client.
Đăng ký, đăng nhập và làm mới token
Access token có hạn dùng 24 giờ; refresh token có hạn dùng 30 ngày. API Key phù hợp hơn cho worker/bot chạy dài hạn.
curl -X POST https://iclever-tts.yez.vn/api/v1/auth/register \ -H 'Content-Type: application/json' \ -d '{"email":"[email protected]","password":"mật-khẩu-từ-6-ký-tự","name":"Tên của bạn"}' # Login: POST /api/v1/auth/login với email và password. # Refresh: POST /api/v1/auth/refresh, header Authorization: Bearer <refresh_token>. # Current user/quota: GET /api/v1/auth/me, header Authorization: Bearer <access_token>.
Ngôn ngữ hỗ trợ
iClever TTS hỗ trợ 14 ngôn ngữ thông qua các model khác nhau. Dùng tham số language trong mọi request tổng hợp.
Model theo ngôn ngữ
| Model | Ngôn ngữ | Ghi chú |
|---|---|---|
| vieneu | vi |
Tiếng Việt bản địa — GPU inference, 10 giọng Nam miền, hỗ trợ cảm xúc & voice cloning |
| edge | vi, en, zh, ja, ko, fr, de, es, pt, ru, ar, hi, th, id |
Microsoft Neural TTS — miễn phí, không cần GPU, 50+ giọng đọc, tất cả 14 ngôn ngữ |
| xtts | en, zh, ja, ko, fr, de, es, pt, ru, ar, hi, it, nl, pl, cs, hu, tr |
Coqui XTTS v2 — voice cloning từ 6s mẫu âm thanh. Không hỗ trợ tiếng Việt. |
| vbee | vi |
Vbee API — tiếng Việt 3 miền, cần cấu hình App ID & Token |
Mã lỗi
| Code | Meaning | Ghi chú |
|---|---|---|
| 200 | OK | Thành công |
| 400 | Bad Request | Tham số không hợp lệ (language code sai, model không tương thích…) |
| 401 | Unauthorized | API key sai hoặc hết hạn mức |
| 403 | Forbidden | Thiếu Admin Key |
| 429 | Too Many Requests | Đã hết quota phút/tháng của gói — cần nâng cấp |
| 500 | Internal Error | Lỗi model / server |
POST /api/v1/synthesize
Tạo giọng nói từ văn bản. Hỗ trợ đa ngôn ngữ, cảm xúc, tốc độ và chọn model/giọng đọc.
Request Body
| Tham số | Kiểu | Required | Mô tả |
|---|---|---|---|
| text | string | Required | Văn bản cần đọc (tối đa 3.000 ký tự mỗi request). Với nội dung dài, tách theo câu và ghép audio ở phía client. |
| language | string | New | Mã ngôn ngữ ISO 639-1: vi | en | zh | ja | ko | fr | de | es | pt | ru | ar | hi | th | id. Mặc định: vi |
| voice_id | string | Optional | ID giọng đọc — xem /api/v1/voices?lang=<code>. Mặc định: giọng đầu tiên của ngôn ngữ |
| model | string | Optional | Override model. Danh sách model/trạng thái thật lấy từ GET /api/v1/models; hiện gồm vieneu, edge, omnivoice, valtec, supertonic, piper, mms_vi, voxcpm và model đang được bật. Mặc định: model active. |
| emotion | string | Optional | natural | happy | sad | angry | fearful. Mặc định: natural. Chỉ có tác dụng với model vieneu. |
| speed | float | Optional | Tốc độ đọc 0.5–2.0. Mặc định: 1.0 |
| format | string | Optional | wav hoặc mp3. Mặc định: wav |
Response
{
"job_id": "a1b2c3d4e5f6",
"audio_url": "/outputs/a1b2c3d4e5f6.wav",
"format": "wav",
"model": "edge",
"voice_id": "en-US-JennyNeural",
"characters": 42,
"duration_ms": 1843
}
emotion chỉ hoạt động với model vieneu (tiếng Việt). Với edge, xtts, vbee tham số này bị bỏ qua. Model xtts không hỗ trợ tiếng Việt — dùng edge hoặc vieneu cho language: "vi".
POST /api/v1/clone
Clone giọng nói từ file audio mẫu 3–10 giây. Hỗ trợ VieNeu TTS (tiếng Việt) và XTTS v2 (các ngôn ngữ khác).
Request (multipart/form-data)
| Field | Kiểu | Required | Mô tả |
|---|---|---|---|
| text | string | Required | Văn bản cần đọc bằng giọng clone |
| ref_audio | file | Required | File WAV/MP3 mẫu giọng đọc (3–10 giây, rõ ràng, không có tiếng ồn) |
| language | string | New | Ngôn ngữ của văn bản. Mặc định: vi. Dùng en, zh… để dùng XTTS v2. |
| model | string | Optional | vieneu (vi) hoặc xtts (en/zh/ja…) |
GET /api/v1/voices
Lấy danh sách giọng đọc. Dùng tham số lang để lọc theo ngôn ngữ.
| Query Param | Kiểu | Mô tả |
|---|---|---|
| lang | string | NewMã ngôn ngữ: vi | en | zh | ja | ko | … Mặc định: vi |
| model | string | Override model để lọc voices: vieneu | edge | xtts | vbee |
{
"model": "vieneu",
"language": "vi",
"count": 13,
"voices": [
{
"id": "Ngọc Lan",
"name": "Ngọc Lan",
"gender": "female",
"region": "south",
"region_label": "Miền Nam",
"provider": "vieneu"
},
{
"id": "vi-VN-HoaiMyNeural",
"name": "Hoài My",
"gender": "female",
"region": "north",
"region_label": "Miền Bắc",
"provider": "edge"
}
]
}
{
"model": "edge",
"language": "en",
"count": 14,
"voices": [
{
"id": "en-US-JennyNeural",
"name": "Jenny",
"gender": "female",
"accent": "en-US",
"provider": "edge",
"language": "en"
},
{
"id": "xtts_en_female",
"name": "Female (English)",
"gender": "female",
"provider": "xtts",
"clone_voice": true
}
]
}
GET /api/v1/languages New
Lấy danh sách ngôn ngữ được hỗ trợ cùng các model khả dụng cho mỗi ngôn ngữ.
{
"languages": [
{ "code": "vi", "name": "Tiếng Việt", "flag": "🇻🇳", "models": ["vieneu", "edge", "vbee"] },
{ "code": "en", "name": "English", "flag": "🇬🇧", "models": ["edge", "xtts"] },
{ "code": "zh", "name": "中文", "flag": "🇨🇳", "models": ["edge", "xtts"] },
// … 11 more languages
]
}
GET /api/v1/models
Liệt kê các model TTS có sẵn, trạng thái cài đặt và model đang active.
{
"active_model": "edge",
"models": [
{ "id": "vieneu", "status": "active", "is_active": false },
{ "id": "edge", "status": "active", "is_active": true },
{ "id": "xtts", "status": "active", "is_active": false },
{ "id": "cosyvoice2", "status": "coming_soon", "is_active": false }
]
}
GET /health
Kiểm tra trạng thái server và model.
{
"status": "ok",
"active_model": "edge",
"vieneu_ready": true,
"timestamp": "2026-06-20T10:30:00"
}
History, hồ sơ và cấu hình người dùng
Các endpoint dưới đây yêu cầu Authorization: Bearer <access_token>; dữ liệu chỉ trả về cho tài khoản hiện tại.
| Method | Endpoint | Mục đích |
|---|---|---|
| GET | /api/v1/history | Lịch sử audio của tài khoản. |
| GET | /api/v1/history/{job_id} | Metadata của một job audio. |
| DELETE | /api/v1/history/{job_id} | Xóa bản ghi/lưu trữ audio của chính bạn. |
| GET | /api/v1/profile | Thông tin hồ sơ, plan và quota. |
| PUT | /api/v1/profile/settings | Cập nhật tuỳ chọn người dùng. |
| PUT | /api/v1/profile/password | Đổi mật khẩu. |
| PUT | /api/v1/profile/change-plan | Yêu cầu đổi plan. |
| GET | /api/v1/ref-voices | Danh sách audio mẫu để clone. |
| POST | /api/v1/ref-voices | Lưu audio mẫu multipart (name, ref_audio). |
| DELETE | /api/v1/ref-voices/{ref_id} | Xóa audio mẫu của chính bạn. |
ASR — speech to text
ASR nhận file audio multipart, giới hạn 100 MB. Có thể dùng Bearer token hoặc API Key.
curl -X POST https://iclever-tts.yez.vn/api/v1/asr/transcribe \ -H 'X-API-Key: YOUR_API_KEY' \ -F '[email protected]' -F 'language=vi' # Status/model: GET /api/v1/asr/status
Danh mục endpoint đầy đủ
| Nhóm | Endpoints | Quyền |
|---|---|---|
| Public | /health, /api/v1/languages, /api/v1/models, /api/v1/plans, /api/v1/docs, /openapi.json | Không cần |
| Auth | POST /api/v1/auth/register, /login, /refresh; GET /me | Token cho /me |
| TTS | POST /api/v1/synthesize, /clone; GET /voices, /ref-voices | API Key hoặc Bearer |
| ASR | GET /api/v1/asr/status, POST /api/v1/asr/transcribe | API Key hoặc Bearer |
| User | /history, /profile, /profile/settings, /profile/password, /profile/change-plan | Bearer |
| Admin | /api/v1/keys, /api/v1/settings, /api/v1/model-profiles, /api/v1/admin/users, /api/v1/admin/stats, /api/v1/admin/history, /api/v1/admin/plans | Admin credential |
POST /api/v1/keys Admin
Tạo API key mới. Cần header X-Admin-Key.
| Field | Kiểu | Required | Mô tả |
|---|---|---|---|
| name | string | Required | Tên ứng dụng / người dùng |
| string | Optional | Email liên hệ | |
| daily_limit | int | Optional | Giới hạn requests/ngày. Mặc định: 1000 |
PUT /api/v1/settings Admin
Thay đổi model active hoặc cấu hình Vbee. Cần header X-Admin-Key.
{
"active_model": "edge" // vieneu | edge | xtts | vbee
}
{
"vbee_config": {
"app_id": "app_xxxx",
"token": "eyJhbGci..."
}
}
Ví dụ — Python
import requests API_BASE = "https://iclever-tts.yez.vn" API_KEY = "ick_your_key" HEADERS = {"X-API-Key": API_KEY, "Content-Type": "application/json"} def synthesize(text, language="vi", voice_id=None, model=None): payload = { "text": text, "language": language, # "vi" | "en" | "zh" | "ja" | … "voice_id": voice_id, "model": model, # None = use active model "format": "wav", } r = requests.post(f"{API_BASE}/api/v1/synthesize", json=payload, headers=HEADERS) r.raise_for_status() data = r.json() audio = requests.get(f"{API_BASE}{data['audio_url']}") with open("output.wav", "wb") as f: f.write(audio.content) return data # Tiếng Việt — giọng Miền Bắc (Microsoft Neural) synthesize("Xin chào, đây là iClever TTS.", language="vi", voice_id="vi-VN-HoaiMyNeural", model="edge") # English — Jenny (American) synthesize("Hello, this is iClever TTS.", language="en", voice_id="en-US-JennyNeural") # Tiếng Trung — Phổ thông synthesize("你好,这是 iClever TTS。", language="zh", voice_id="zh-CN-XiaoxiaoNeural") # Lấy danh sách giọng cho tiếng Anh r = requests.get(f"{API_BASE}/api/v1/voices", params={"lang": "en"}, headers=HEADERS) voices = r.json()["voices"]
Ví dụ — JavaScript
const API_BASE = 'https://iclever-tts.yez.vn'; const API_KEY = 'ick_your_key'; const headers = { 'Content-Type': 'application/json', 'X-API-Key': API_KEY }; async function synthesize({ text, language = 'vi', voiceId = null, model = null }) { const res = await fetch(`${API_BASE}/api/v1/synthesize`, { method: 'POST', headers, body: JSON.stringify({ text, language, // 'vi' | 'en' | 'zh' | 'ja' | 'ko' | … voice_id: voiceId, model, format: 'wav', }), }); const data = await res.json(); new Audio(`${API_BASE}${data.audio_url}`).play(); return data; } // Tiếng Việt — giọng Nam Minh (Miền Bắc) await synthesize({ text: 'Xin chào!', language: 'vi', voiceId: 'vi-VN-NamMinhNeural' }); // English — British male await synthesize({ text: 'Hello from London.', language: 'en', voiceId: 'en-GB-RyanNeural' }); // 日本語 await synthesize({ text: 'こんにちは!', language: 'ja', voiceId: 'ja-JP-NanamiNeural' }); // Fetch English voices const { voices } = await fetch(`${API_BASE}/api/v1/voices?lang=en`, { headers }).then(r => r.json());
Ví dụ — cURL
curl -X POST https://iclever-tts.yez.vn/api/v1/synthesize \
-H "Content-Type: application/json" \
-H "X-API-Key: ick_your_key" \
-d '{
"text": "Xin chào, đây là iClever TTS.",
"language": "vi",
"voice_id": "vi-VN-HoaiMyNeural",
"model": "edge",
"format": "wav"
}'
curl -X POST https://iclever-tts.yez.vn/api/v1/synthesize \
-H "Content-Type: application/json" \
-H "X-API-Key: ick_your_key" \
-d '{
"text": "Hello, this is iClever TTS.",
"language": "en",
"voice_id": "en-US-JennyNeural",
"model": "edge"
}'
curl "https://iclever-tts.yez.vn/api/v1/voices?lang=zh" \ -H "X-API-Key: ick_your_key"
curl -X POST https://iclever-tts.yez.vn/api/v1/clone \ -H "X-API-Key: ick_your_key" \ -F "text=This voice is cloned from a 6-second sample." \ -F "language=en" \ -F "model=xtts" \ -F "ref_audio=@/path/to/sample.wav"