import { VoiceAgentClient, VoiceStyle, Language, AUDIO_CONFIG } from '@lokutor/sdk';
import recorder from 'node-record-lpcm16';
import Speaker from 'speaker';
async function main() {
const client = new VoiceAgentClient({
apiKey: 'your-api-key',
prompt: 'You are a helpful and friendly AI assistant.',
onTranscription: (text) => console.log('User:', text),
onResponse: (text) => console.log('AI:', text),
});
const connected = await client.connect();
if (!connected) return;
// 1. Setup Microphone Recording (Input)
const mic = recorder.record({
sampleRate: AUDIO_CONFIG.SAMPLE_RATE,
channels: AUDIO_CONFIG.CHANNELS,
threshold: 0,
});
mic.stream().on('data', (chunk) => {
client.sendAudio(chunk);
});
// 2. Setup Speaker Playback (Output)
const speaker = new Speaker({
channels: AUDIO_CONFIG.CHANNELS,
bitDepth: 16,
sampleRate: AUDIO_CONFIG.SAMPLE_RATE,
});
client.onAudio((chunk) => {
speaker.write(chunk);
});
}
main().catch(console.error);