From cff6dbaf9b0c211c608f715b3dff9cbcf568c892 Mon Sep 17 00:00:00 2001 From: examples-bot Date: Thu, 2 Apr 2026 06:28:56 +0000 Subject: [PATCH 1/2] fix(170): migrate to Deepgram SDK v5 connect() API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The SDK removed `.live()` in favor of `await .connect()`, `.sendBinary()` replaces `.send()`, and `.close()` replaces `.finish()`. Message event data is now pre-parsed (no JSON.parse needed). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../src/main.js | 17 ++++++++++------- .../tests/test.js | 15 +++++++++------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/examples/170-electron-live-transcription-node/src/main.js b/examples/170-electron-live-transcription-node/src/main.js index 1e71fd4..427671a 100644 --- a/examples/170-electron-live-transcription-node/src/main.js +++ b/examples/170-electron-live-transcription-node/src/main.js @@ -62,10 +62,10 @@ function createTray() { } // ── Deepgram live connection ──────────────────────────────────────────────── -function startDeepgramConnection() { +async function startDeepgramConnection() { if (dgConnection) return; - dgConnection = deepgram.listen.v1.live({ + dgConnection = await deepgram.listen.v1.connect({ model: 'nova-3', encoding: 'linear16', sample_rate: 16000, @@ -94,28 +94,31 @@ function startDeepgramConnection() { dgConnection.on('message', (data) => { try { - const msg = typeof data === 'string' ? JSON.parse(data) : data; - const transcript = msg?.channel?.alternatives?.[0]?.transcript; + const transcript = data?.channel?.alternatives?.[0]?.transcript; if (transcript && overlayWindow) { overlayWindow.webContents.send('transcript', { text: transcript, - is_final: msg.is_final, + is_final: data.is_final, }); } } catch {} }); + + dgConnection.connect(); + await dgConnection.waitForOpen(); } function stopDeepgramConnection() { if (!dgConnection) return; - try { dgConnection.finish(); } catch {} + try { dgConnection.sendCloseStream({ type: 'CloseStream' }); } catch {} + try { dgConnection.close(); } catch {} dgConnection = null; } // ── IPC handlers ──────────────────────────────────────────────────────────── ipcMain.on('audio-data', (_event, buffer) => { if (dgConnection) { - try { dgConnection.send(Buffer.from(buffer)); } catch {} + try { dgConnection.sendBinary(Buffer.from(buffer)); } catch {} } }); diff --git a/examples/170-electron-live-transcription-node/tests/test.js b/examples/170-electron-live-transcription-node/tests/test.js index 4bb03a1..d61dbbc 100644 --- a/examples/170-electron-live-transcription-node/tests/test.js +++ b/examples/170-electron-live-transcription-node/tests/test.js @@ -81,7 +81,7 @@ async function testDeepgramLiveTranscription() { console.log(`Audio ready: ${pcm16.length} bytes of linear16 16 kHz`); // Connect to Deepgram live STT - const connection = client.listen.v1.live({ + const connection = await client.listen.v1.connect({ model: 'nova-3', encoding: 'linear16', sample_rate: 16000, @@ -106,10 +106,9 @@ async function testDeepgramLiveTranscription() { connection.on('message', (data) => { try { - const msg = typeof data === 'string' ? JSON.parse(data) : data; - const transcript = msg?.channel?.alternatives?.[0]?.transcript; + const transcript = data?.channel?.alternatives?.[0]?.transcript; if (transcript) { - const tag = msg.is_final ? 'final' : 'interim'; + const tag = data.is_final ? 'final' : 'interim'; console.log(`[${tag}] ${transcript}`); transcripts.push(transcript); } @@ -127,10 +126,11 @@ async function testDeepgramLiveTranscription() { const sendChunk = () => { if (pos >= pcm16.length || pos >= MAX_BYTES) { console.log('[deepgram] Audio sent — waiting for final results...'); - try { connection.finish(); } catch {} + try { connection.sendCloseStream({ type: 'CloseStream' }); } catch {} + try { connection.close(); } catch {} return; } - connection.send(pcm16.subarray(pos, pos + CHUNK_BYTES)); + connection.sendBinary(pcm16.subarray(pos, pos + CHUNK_BYTES)); pos += CHUNK_BYTES; setTimeout(sendChunk, 20); }; @@ -161,6 +161,9 @@ async function testDeepgramLiveTranscription() { resolve(transcripts); }, 1000); }); + + connection.connect(); + connection.waitForOpen(); }); } From fd97bdba570fd47279258bb8a934e009a0a7910f Mon Sep 17 00:00:00 2001 From: examples-bot Date: Thu, 2 Apr 2026 07:26:45 +0000 Subject: [PATCH 2/2] fix(examples): await waitForOpen() and update README API reference in 170-electron-live-transcription-node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../README.md | 2 +- .../tests/test.js | 45 +++++++++---------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/examples/170-electron-live-transcription-node/README.md b/examples/170-electron-live-transcription-node/README.md index 9c6055a..7e548e8 100644 --- a/examples/170-electron-live-transcription-node/README.md +++ b/examples/170-electron-live-transcription-node/README.md @@ -44,7 +44,7 @@ npm start 2. When you click **Start**, the renderer requests microphone access via `getUserMedia` at 16 kHz 3. A `ScriptProcessorNode` captures raw PCM audio and converts float32 samples to linear16 4. Audio chunks are sent to the main process via IPC (`contextBridge` + `ipcRenderer`) -5. The main process connects to Deepgram's live STT WebSocket using `client.listen.v1.live()` and forwards audio +5. The main process connects to Deepgram's live STT WebSocket using `client.listen.v1.connect()` and forwards audio 6. Transcript events (interim and final) stream back and are displayed in the overlay 7. The overlay supports click-through (`setIgnoreMouseEvents`) so it never blocks interaction with other apps 8. Use **Ctrl+Shift+T** (or **Cmd+Shift+T** on macOS) to toggle overlay visibility diff --git a/examples/170-electron-live-transcription-node/tests/test.js b/examples/170-electron-live-transcription-node/tests/test.js index d61dbbc..0f6fbf7 100644 --- a/examples/170-electron-live-transcription-node/tests/test.js +++ b/examples/170-electron-live-transcription-node/tests/test.js @@ -115,29 +115,6 @@ async function testDeepgramLiveTranscription() { } catch {} }); - connection.on('open', () => { - console.log('[deepgram] Connected — streaming audio...'); - - // Stream 5 seconds of audio in real-time-paced chunks - const CHUNK_BYTES = 640; // 20ms at 16kHz * 2 bytes - const MAX_BYTES = 16000 * 2 * 5; // 5 seconds - let pos = 0; - - const sendChunk = () => { - if (pos >= pcm16.length || pos >= MAX_BYTES) { - console.log('[deepgram] Audio sent — waiting for final results...'); - try { connection.sendCloseStream({ type: 'CloseStream' }); } catch {} - try { connection.close(); } catch {} - return; - } - connection.sendBinary(pcm16.subarray(pos, pos + CHUNK_BYTES)); - pos += CHUNK_BYTES; - setTimeout(sendChunk, 20); - }; - - sendChunk(); - }); - connection.on('close', () => { clearTimeout(timeout); setTimeout(() => { @@ -163,7 +140,27 @@ async function testDeepgramLiveTranscription() { }); connection.connect(); - connection.waitForOpen(); + connection.waitForOpen().then(() => { + console.log('[deepgram] Connected — streaming audio...'); + + const CHUNK_BYTES = 640; + const MAX_BYTES = 16000 * 2 * 5; + let pos = 0; + + const sendChunk = () => { + if (pos >= pcm16.length || pos >= MAX_BYTES) { + console.log('[deepgram] Audio sent — waiting for final results...'); + try { connection.sendCloseStream({ type: 'CloseStream' }); } catch {} + try { connection.close(); } catch {} + return; + } + connection.sendBinary(pcm16.subarray(pos, pos + CHUNK_BYTES)); + pos += CHUNK_BYTES; + setTimeout(sendChunk, 20); + }; + + sendChunk(); + }).catch(reject); }); }