Repository navigation
Keep transcribing when another app takes the audio device (#164) - #165
Merged
Merged
Conversation
…evice Each channel's capture graph ended at the default context's destination, which tied capture to the system output device. When another app took the speakers in WASAPI exclusive mode, Chromium suspended both capture contexts at once and they never came back, while both sockets stayed open and the backend's keepalive hid the silence for the rest of the interview. - Capture contexts now render to a `none` sink, so they are clocked internally and survive the output device being taken. - A per-channel watchdog resumes a suspended context, rebuilds the graph when frames stop, and re-acquires the source when its track ends or the microphone goes digitally silent (an exclusive grab of the mic). The socket is kept throughout. - Loopback is re-acquired acquire-swap-release, like the microphone path. Refs #164 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The live signal now has a third state beside Listening and Reconnecting: "Audio lost - recovering", shown while either channel's capture watchdog reports its source lost. Before this, a dead capture with an open socket looked exactly like a quiet interview. Strings added for all nine interface languages. Refs #164 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Source-level checks, like language-switch.test.mjs: the silent sink and its fallback, frames counted before the socket check, resume on suspend, the three detections (ended track, stopped frames, digital silence), mic-only silence detection, acquire-swap-release for loopback, the watchdog cleared on stop, and the control bar reading the stall. Refs #164 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…effects Review of the first pass found five problems, each fixed and pinned: - Indicator flicker: every recovery attempt reset the timers, so a source that was still dead read as restored for ~5 s before failing again. A lost capture now clears only on evidence from the current source (frames, and real signal on the mic). - Retry churn: a mic muted at the OS or hardware level is also exact zeros, and was re-opened every 5 s for as long as it stayed muted. Retries now back off exponentially to 60 s - but only after an attempt that actually re-opened something. A refused attempt (device held exclusively, NotReadableError) opened nothing and stays on the short interval; otherwise a minute-long grab cost up to a minute of audio after release (measured live: now 4 s). - False rebuilds after a renderer freeze: frames must be missing for two consecutive checks. - stop() during a rebuild: a graph torn down while its worklet loaded no longer installs itself over the cleared fields. - setAudioInputDevice's doc comment had been left above the new loopback helpers; restored to its method. Recovery errors log name and message. The test's loopback check was vacuous (its regex stopped at the first `)` in `() =>`); it now inspects the constructor call and was verified against a mutation. Also pins that the mock channel, which mutes the mic track by design, never enables silence detection. Refs #164 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… while it is taken The first fix put every capture context on a `none` sink. Measured live in the same process as a speaker-clocked context, that software clock intermittently renders at ~65% of real time on Windows (4 of 6 runs; it set in seconds after an ordinary player started) while the speaker clock stays at 100%. At 65% a third of the audio is dropped and the rest distorted, for the whole session, with nothing reporting it - worse than the bug it replaced in the common case. Neither clock is safe alone, so: - Capture runs on the speakers, exactly as before #164. - A speaker-clocked graph that stops rendering (another app took the speakers exclusively) is rebuilt on the software clock, so both channels keep capturing through the grab. - While on the software clock, a throwaway probe context checks every 3 s whether the speakers render at real time again, by measuring its clock rather than trusting `state`; capture moves back once they do. Also: - No more resume() on a suspended context. On held speakers every resume flipped the context running/suspended hundreds of times a second, and a check landing on a running instant read the dead graph as healthy, so the fallback never happened. The handler now records the interruption and the watchdog counts it, which also detects a taken output device in ~1 s instead of waiting out the frame gap. - A refused recovery attempt (NotReadableError: Device in use) is retried after 1 s instead of the 5 s base wait, and each distinct refusal is logged once. Measured: loopback back 1-2 s after the speakers are released, down from 5 s. Live, three runs of a 15 s exclusive speaker grab: full rate on both channels outside a ~1.5 s gap at the grab, back on the speaker clock 1-2 s after release, interviewer audio arriving ~1 s after release. A normal session with a player starting and stopping: full rate every second, no watchdog action. Refs #164 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A message still queued from a graph the watchdog just replaced counted as evidence for the new graph and was resampled at the new context's rate. Drop it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #164.
Problem
A live session could stop transcribing on both channels at once and never recover, while both ASR sockets stayed open. Each channel's capture graph ended at the default
AudioContextdestination, which tied capture to the system output device. When another app took the speakers in WASAPI exclusive mode, Chromium suspended both capture contexts together ("The AudioContext encountered an error from the audio device"). They stayed suspended after the device was released. The backend's Deepgram keepalive kept the audio-less streams open, so nothing errored, the panels froze, and the export covered only the minutes before the stall.Changes
fix(transcription)(live-transcription.service.ts)buildGraph()/teardownGraph(), shared bystart()and recovery.feat(control-bar): the live signal gains an "Audio lost - recovering" state, in all nine interface languages.test:test/capture-stall.test.mjs, 33 source-level checks pinning the above. The two regressions found during review (software clock as the resting state,resume()on suspend) were each reintroduced to confirm the checks fail.stop()during a rebuild, frames still queued from a replaced graph ignored, and the clock redesign below.Why two clocks
The first version of this PR moved every capture context onto a
nonesink (sinkId: { type: 'none' }), clocked by a timer instead of the speakers. Review measured it against a speaker-clocked context in the same process:nonesink~65% matches 10 ms render ticks landing on Windows' default 15.6 ms timer granularity. It happened in 4 of 6 runs. At 65% a third of the audio is dropped and the rest distorted, all session, unreported. So:
currentTimerather than trustingstate. Capture moves back once they do.Live test, before and after
This harness runs the app's real
live-transcription.service.ts, bundled with esbuild frommain(c6b4fd1) and from this branch (7efbf97, re-run on 02f2b64). It uses Electron 40.9.1,electron-audio-loopbackand real Windows devices, against a local WebSocket sink that stands in for the backend. Per socket per second the sink reports bytes received (whether the capture clock runs at real time: about 31,500 B/s at 16 kHz PCM16), RMS, and the dominant frequency (what is actually in the audio).A shared-mode 440 Hz tone stands in for normal system audio. A second app takes the speakers in exclusive mode for 15 s and plays its own 1 kHz tone, standing in for Zoom playing the interviewer on a device it has taken. After release, a fresh shared-mode player plays 660 Hz.
main(before)isConnected()staystrueOther runs on 7efbf97:
nonesink)NotReadableError: Device in use) logged once, retried every 1 s; mic back 1-2 s after releaseLocal checks:
pnpm lint,tsc -b,tsc -p tsconfig.electron.json,pnpm build,pnpm test:main. All pass.Known limits
sounddevice).Not in this PR
🤖 Generated with Claude Code