Text to Speech

1. Lấy API key

Liên hệ đội ngũ OMICX để được cấp API key.

2. Gọi thử endpoint

$curl --location 'https://api.omicx.one/public-svc/api/ai/tts' \
> --header 'accept: application/json' \
> --header 'Idempotency-Key: 6f9619ff-8b86-d011-b42d-00c04fc964ff' \
> --header 'x-api-key: YOUR_API_KEY' \
> --header 'Content-Type: application/json' \
> --data '{
> "text": "Xin chào, đây là bản demo từ OMICX"
> }'

Response trả về là JSON chứa đường dẫn file audio:

1{
2 "audio_url": "https://cdn.omicx.one/tts/output/6f9619ff-8b86-d011-b42d-00c04fc964ff.mp3",
3 "format": "mp3",
4 "duration_ms": 1850,
5 "characters": 20,
6 "credits_used": 2
7}

Tải file audio bằng cách gọi audio_url:

$curl -L "https://cdn.omicx.one/tts/output/6f9619ff-8b86-d011-b42d-00c04fc964ff.mp3" --output output.mp3

3. Xử lý lỗi

Nếu request thất bại, API trả về JSON mô tả lỗi, ví dụ:

1{
2 "error": {
3 "code": "invalid_voice",
4 "message": "Giọng đọc 'unknown-voice' không tồn tại."
5 }
6}

Xem đầy đủ tham số và mã lỗi tại API Reference.