-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_assembly_robust.js
More file actions
51 lines (40 loc) · 1.35 KB
/
Copy pathtest_assembly_robust.js
File metadata and controls
51 lines (40 loc) · 1.35 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
const WebSocket = require('ws');
const apiKey = process.env.ASSEMBLYAI_API_KEY || '';
async function testConnection(queryString) {
return new Promise((resolve) => {
const url = `wss://api.assemblyai.com/v2/realtime/ws${queryString}`;
console.log(`Testing: ${url}`);
const ws = new WebSocket(url, {
headers: { Authorization: apiKey }
});
const timeout = setTimeout(() => {
console.log(" [TIMEOUT] Success?");
ws.close();
resolve(true);
}, 3000);
ws.on('open', () => {
console.log(` [OPEN] Connected.`);
});
ws.on('message', (data) => {
const msg = JSON.parse(data.toString());
if (msg.error) {
console.log(` [SERVICE ERROR] ${msg.error}`);
}
});
ws.on('close', (code, reason) => {
clearTimeout(timeout);
console.log(` [CLOSED] Code: ${code}, Reason: ${reason}`);
resolve(false);
});
ws.on('error', (e) => {
console.log(` [ERROR] ${e.message}`);
});
});
}
async function run() {
// Try Universal-1 first param
await testConnection('?model=universal-1&sample_rate=16000');
// Try Best
await testConnection('?model=best&sample_rate=16000');
}
run();