From 2fe3ca0188f2c61902157f2edac1c82c909b4cfd Mon Sep 17 00:00:00 2001 From: Quentin Fuxa Date: Sat, 27 Sep 2025 13:59:44 +0200 Subject: [PATCH] connect source to output destination when used as chrome extension to keep audio playing --- whisperlivekit/web/live_transcription.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/whisperlivekit/web/live_transcription.js b/whisperlivekit/web/live_transcription.js index 360b7f6..3a1e1da 100644 --- a/whisperlivekit/web/live_transcription.js +++ b/whisperlivekit/web/live_transcription.js @@ -29,6 +29,8 @@ let selectedMicrophoneId = null; let serverUseAudioWorklet = null; let configReadyResolve; const configReady = new Promise((r) => (configReadyResolve = r)); +let outputAudioContext = null; +let audioSource = null; waveCanvas.width = 60 * (window.devicePixelRatio || 1); waveCanvas.height = 30 * (window.devicePixelRatio || 1); @@ -511,6 +513,15 @@ async function startRecording() { } }); }); + + try { + outputAudioContext = new (window.AudioContext || window.webkitAudioContext)(); + audioSource = outputAudioContext.createMediaStreamSource(stream); + audioSource.connect(outputAudioContext.destination); + } catch (audioError) { + console.warn('could not preserve system audio:', audioError); + } + statusText.textContent = "Using tab audio capture."; } catch (tabError) { console.log('Tab capture not available, falling back to microphone', tabError); @@ -659,6 +670,16 @@ async function stopRecording() { audioContext = null; } + if (audioSource) { + audioSource.disconnect(); + audioSource = null; + } + + if (outputAudioContext && outputAudioContext.state !== "closed") { + outputAudioContext.close() + outputAudioContext = null; + } + if (animationFrame) { cancelAnimationFrame(animationFrame); animationFrame = null;