generated from fahricansecer/boilerplate-be
35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
const axios = require('axios');
|
|
const fs = require('fs');
|
|
async function test() {
|
|
try {
|
|
const res = await axios.post('http://localhost:17493/generate', {
|
|
text: "deneme ses",
|
|
profile_id: "b8d26247-c8bc-4c06-9364-5b09d11de4bf",
|
|
language: "en",
|
|
engine: "kokoro"
|
|
});
|
|
console.log('Init:', res.data);
|
|
const id = res.data.id;
|
|
let status = res.data.status;
|
|
while (status !== 'completed') {
|
|
await new Promise(r => setTimeout(r, 1000));
|
|
const hist = await axios.get('http://localhost:17493/history');
|
|
const item = hist.data.items ? hist.data.items.find(i => i.id === id) : hist.data.find(i => i.id === id);
|
|
status = item ? item.status : 'failed';
|
|
console.log('Status:', status);
|
|
if (status === 'failed') {
|
|
console.error('Failed!', item.error);
|
|
break;
|
|
}
|
|
}
|
|
if (status === 'completed') {
|
|
const audioRes = await axios.get(`http://localhost:17493/audio/${id}`, { responseType: 'arraybuffer' });
|
|
fs.writeFileSync('/tmp/test-kokoro-direct.wav', audioRes.data);
|
|
console.log('Audio saved, length:', audioRes.data.length);
|
|
}
|
|
} catch (e) {
|
|
console.error('Error:', e.response?.data || e.message);
|
|
}
|
|
}
|
|
test();
|