const WebSocket = require('ws');
const API_KEY = 'sk_live_your_key';
const ws = new WebSocket(`wss://api.60db.ai/ws/stt?apiKey=${API_KEY}`);
ws.onopen = () => console.log('✅ Connected');
ws.onmessage = (data) => {
const msg = JSON.parse(data);
if (msg.connection_established) {
console.log('✅ Authenticated!');
// Start session
ws.send(JSON.stringify({
type: 'start',
languages: ['en'],
config: {
encoding: 'mulaw',
sample_rate: 8000,
continuous_mode: true
}
}));
}
if (msg.type === 'connected') {
console.log('✅ Ready! Send audio now');
// Send audio chunks
const interval = setInterval(() => {
ws.send(audioBuffer); // Your audio data
}, 60);
// Stop after 5 seconds
setTimeout(() => {
clearInterval(interval);
ws.send(JSON.stringify({ type: 'stop' }));
}, 5000);
}
if (msg.type === 'transcription') {
console.log('📝 Text:', msg.text);
}
if (msg.type === 'session_stopped') {
console.log('✅ Done! Cost:', msg.billing_summary.total_cost);
ws.close();
}
};