-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_client.js
More file actions
79 lines (71 loc) · 2.28 KB
/
Copy pathtest_client.js
File metadata and controls
79 lines (71 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const axios = require("axios");
const fs = require("fs");
// Replace with your actual API key if required
const API_KEY = "your-api-key-here";
async function testTTS() {
try {
const response = await axios.post(
"http://localhost:59125/tts",
{
// text: 'Hello world, this is a test of the Chatterbox TTS system',
text: "Now let's make my mum's favourite. So three mars bars into the pan. Then we add the tuna and just stir for a bit, just let the chocolate and fish infuse. A sprinkle of olive oil and some tomato ketchup. Now smell that. Oh boy this is going to be incredible.",
options: {
referenceAudio: "female-reference-voice.wav",
exaggeration: 1.0,
cfg_weight: 1.0,
},
},
{
responseType: "stream",
headers: {
"x-api-key": API_KEY,
},
}
);
const writer = fs.createWriteStream("test_output.wav");
response.data.pipe(writer);
return new Promise((resolve, reject) => {
let finished = false;
const cleanup = () => {
if (!finished) {
finished = true;
return true;
}
return false;
};
writer.on("finish", () => {
if (cleanup()) {
resolve();
}
});
writer.on("error", (err) => {
if (cleanup()) {
reject(err);
} else {
console.error("Error after finish:", err);
}
});
});
} catch (error) {
if (error.response) {
// The request was made and the server responded with a status code
console.error(`Test failed with status ${error.response.status}:`);
try {
// Try to parse JSON error response
const errorBody = JSON.parse(error.response.data);
console.error("Error details:", errorBody);
} catch (e) {
console.error("Response data:", e.response ? e.response.data : e);
}
} else if (error.request) {
// The request was made but no response was received
console.error("No response received:", error.message);
} else {
// Something happened in setting up the request
console.error("Request setup error:", error.message);
}
}
}
testTTS().then(() => {
console.log("Test completed. Audio saved to test_output.wav");
});