const ws = new WebSocket("wss://api.slng.ai/v1/stt/slng/deepgram/nova:3");
ws.onopen = () => {
// 1. Initialize session
ws.send(
JSON.stringify({
type: "init",
config: {
language: "en",
sample_rate: 16000,
encoding: "linear16",
},
}),
);
// 2. Send audio data (from microphone or file)
// ws.send(audioBuffer); // Binary data
};
ws.onmessage = (event) => {
const message = JSON.parse(event.data);
if (message.type === "partial_transcript") {
// Interim result — may change as more audio arrives
console.log("Interim:", message.transcript);
} else if (message.type === "final_transcript") {
// Confirmed transcription for this segment
console.log("Final:", message.transcript);
}
};