Lưu ý: nếu chưa cấu hình engine thật trong api/config.php, endpoint sẽ chạy ở demo mode (copy file giọng).
{}
{}
public/voice (mp3/wav/ogg/m4a).sql/init.sql để tạo bảng api_keys và log.voices.php, preview.php, tts.php.GET https://789clup.fun/api/voices.php?include_all=1
Authorization: Bearer YOUR_API_KEY
GET https://789clup.fun/api/preview.php?voice=subfolder/ten_file.mp3
Authorization: Bearer YOUR_API_KEY
hoặc dùng query cho audio tag:
GET https://789clup.fun/api/preview.php?voice=subfolder/ten_file.mp3&api_key=YOUR_API_KEY
POST https://789clup.fun/api/tts.php
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY
{
"text": "Xin chào, đây là bản đọc thử",
"voice": "subfolder/hn_female_hachi_book_22k-vc.mp3",
"speed": 1,
"format": "mp3"
}
<?php
$apiUrl = 'https://789clup.fun/api/tts.php';
$apiKey = 'YOUR_API_KEY';
$payload = [
'text' => 'Xin chào từ hệ thống của tôi',
'voice' => 'subfolder/hn_female_hachi_book_22k-vc.mp3',
'speed' => 1.0,
'format' => 'mp3',
];
$ch = curl_init($apiUrl);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'Authorization: Bearer ' . $apiKey,
],
CURLOPT_POSTFIELDS => json_encode($payload, JSON_UNESCAPED_UNICODE),
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$err = curl_error($ch);
curl_close($ch);
if ($err) {
die('cURL error: ' . $err);
}
$data = json_decode($response, true);
if ($httpCode !== 200 || empty($data['success'])) {
die('API error: ' . ($data['error'] ?? 'Unknown error'));
}
echo 'Audio URL: ' . $data['audio_url'];
const API_KEY = process.env.TTS_API_KEY; // lưu key trong env
const BASE_URL = 'https://789clup.fun';
async function createTts() {
const res = await fetch(`${BASE_URL}/api/tts.php`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`,
},
body: JSON.stringify({
text: 'Xin chào từ Node.js',
voice: 'subfolder/hn_female_hachi_book_22k-vc.mp3',
speed: 1,
format: 'mp3',
}),
});
const data = await res.json();
if (!data.success) {
throw new Error(data.error || 'TTS failed');
}
console.log('audio_url:', data.audio_url);
return data;
}
async function listVoices() {
const res = await fetch(`${BASE_URL}/api/voices.php?include_all=1`, {
headers: { Authorization: `Bearer ${API_KEY}` },
});
const data = await res.json();
if (!data.success) throw new Error(data.error || 'voices failed');
return data.voices;
}
createTts().catch(console.error);
const axios = require('axios');
const client = axios.create({
baseURL: 'https://789clup.fun',
headers: {
Authorization: `Bearer ${process.env.TTS_API_KEY}`,
},
});
async function ttsByAxios() {
const { data } = await client.post('/api/tts.php', {
text: 'Test giọng bằng axios',
voice: 'subfolder/hn_female_hachi_book_22k-vc.mp3',
speed: 1,
format: 'mp3',
});
return data;
}
Authorization: Bearer ..., không hardcode trong source..env (vd TTS_API_KEY=...).
Ghi chú: Endpoint tts.php hiện có demo mode nếu chưa cấu hình engine thật.
Khi bạn có engine/exe local, chỉ cần điền tts_command_template trong api/config.php.