42 lines
1.7 KiB
JavaScript
42 lines
1.7 KiB
JavaScript
import { AudioAgentClient, AudioAgentRest } from '../sdk/audio-agent-client.js';
|
|
|
|
const rest = new AudioAgentRest('http://localhost:8787');
|
|
console.log('REST health =>', JSON.stringify(await rest.health()));
|
|
const tools = await rest.getTools();
|
|
console.log('REST tools =>', tools.count, tools.source);
|
|
|
|
const client = new AudioAgentClient({ baseUrl: 'http://localhost:8787' });
|
|
const seen = [];
|
|
|
|
await new Promise((resolve, reject) => {
|
|
const timer = setTimeout(() => reject(new Error('timeout waiting for cues')), 8000);
|
|
client.on('cues', (e) => {
|
|
seen.push(`cues(lang=${e.lang})`);
|
|
clearTimeout(timer);
|
|
resolve();
|
|
});
|
|
client.on('error', (e) => console.error('ERR event', e));
|
|
client.connect().then(() => console.log('WS connected =>', client.url)).catch(reject);
|
|
});
|
|
|
|
// Observe the turn events + decoded PCM frames.
|
|
let audioFrames = 0;
|
|
client.on('user', (e) => seen.push(`user(${JSON.stringify(e.text)})`));
|
|
client.on('assistant_delta', (e) => seen.push(`assistant_delta(len=${e.text.length})`));
|
|
client.on('assistant_end', () => seen.push('assistant_end'));
|
|
client.on('cue', (e) => seen.push(`cue(${e.kind})`));
|
|
client.on('tool_call', (e) => seen.push(`tool_call(${e.name})`));
|
|
client.on('audio', (e) => {
|
|
audioFrames++;
|
|
if (e.samples.length !== 882) seen.push(`BAD frame ${e.samples.length}`);
|
|
});
|
|
|
|
// Send a PCM frame (882 samples of silence) + a text turn, then confirm events flow.
|
|
console.log('sendAudio =>', client.sendAudio(new Int16Array(882)));
|
|
client.sendUserText('di solo "ciao"');
|
|
await new Promise((r) => setTimeout(r, 12000));
|
|
client.close();
|
|
console.log('events seen:', seen.join(', '));
|
|
console.log('audio frames decoded:', audioFrames);
|
|
process.exit(0);
|