Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
fix: harden PR #346 mic selection - skip auto-offer on resume, keep saved devices through transient enumerations, require explicit external label hints
Murtaza Nasir9998aba92fb6
diff --git a/static/js/app.modular.js b/static/js/app.modular.jsindex d15fb1b4..d9388e28 100644--- a/static/js/app.modular.js+++ b/static/js/app.modular.js@@ -456,19 +456,15 @@ document.addEventListener('DOMContentLoaded', async () => {const devs = await navigator.mediaDevices.enumerateDevices();const inputs = normalizeAudioInputDevices(devs);inputAudioDevices.value = inputs;-- // Before permission, browsers often expose only opaque or- // blank entries. Reconcile persisted IDs only once labels- // prove that the full device list is available.- if (inputs.some(device => device.label)) {- const availableIds = new Set(inputs.map(device => device.deviceId));- if (selectedMicDeviceId.value && !availableIds.has(selectedMicDeviceId.value)) {- selectedMicDeviceId.value = '';- }- if (selectedSecondaryDeviceId.value && !availableIds.has(selectedSecondaryDeviceId.value)) {- selectedSecondaryDeviceId.value = '';- }- }+ // Deliberately no reconciliation of the persisted device+ // IDs here: a device can be momentarily absent from an+ // enumeration (undock/redock, USB re-plug, devicechange+ // races), and clearing the saved selection on that signal+ // silently switches later recordings to the default mic.+ // A genuinely stale selection is handled loudly at+ // acquisition time instead: acquireMicrophoneStream falls+ // back to the default, clears the saved ID, and shows the+ // "selected microphone unavailable" toast.return inputs;} catch (_) {inputAudioDevices.value = [];diff --git a/static/js/modules/composables/audio.js b/static/js/modules/composables/audio.jsindex c2f79953..11e200cd 100644--- a/static/js/modules/composables/audio.js+++ b/static/js/modules/composables/audio.js@@ -621,7 +621,12 @@ export function useAudio(state, utils) {// mobile, when no explicit selection is active and the browser// exposes a confidently separate physical input. Desktop keeps// its native chooser without a second automatic selection step.- if (!primaryDeviceId && shouldAutoOfferExternalAudioInput()) {+ // Never offer during a resume: a continued session must keep+ // its original input, and the prompt UI lives inside the+ // upload modal, which a crash-recovery resume may not have+ // open — awaiting the selection there would hang forever+ // with the record buttons stuck disabled.+ if (!primaryDeviceId && !resumeContext && shouldAutoOfferExternalAudioInput()) {const candidates = findExternalAudioInputCandidates(refreshedInputs, activeDeviceId);const candidateSignature = getAudioInputCandidateSignature(candidates);if (candidates.length > 0diff --git a/static/js/modules/utils/platform.js b/static/js/modules/utils/platform.jsindex ce8bc253..845ff406 100644--- a/static/js/modules/utils/platform.js+++ b/static/js/modules/utils/platform.js@@ -70,13 +70,14 @@ export function findExternalAudioInputCandidates(devices = [], activeDeviceId =if (device.deviceId === activeDeviceId) return false;if (device.deviceId === 'default' || device.deviceId === 'communications') return false;if (GENERIC_INPUT_LABEL.test(device.label) || INTERNAL_INPUT_LABEL_HINT.test(device.label)) return false;- if (EXTERNAL_INPUT_LABEL_HINT.test(device.label)) return true;-- return !!(- active?.groupId- && device.groupId- && device.groupId !== active.groupId- );+ // Positive label-hint matches only. A bare "different groupId"+ // fallback was tried here and over-triggered badly: the+ // internal/generic exclusion regexes are English-only, so on+ // non-English devices internal routes (earpiece, speakerphone)+ // escape them and every phone would prompt about its own built-in+ // inputs. Requiring an explicit external hint keeps the prompt+ // conservative; users can always open the device panel manually.+ return EXTERNAL_INPUT_LABEL_HINT.test(device.label);});}diff --git a/static/js/modules/utils/platform.test.js b/static/js/modules/utils/platform.test.jsindex 9c12632f..97738abb 100644--- a/static/js/modules/utils/platform.test.js+++ b/static/js/modules/utils/platform.test.js@@ -65,13 +65,16 @@ describe('audio input device helpers', () => {.toMatchObject([{ deviceId: 'external-mic', label }]);});- it('uses a distinct group as a conservative fallback for a named device', () => {+ it('does not offer a distinct-group device without an external label hint', () => {+ // The internal/generic exclusion regexes are English-only, so a bare+ // "different groupId" fallback would promote untranslated internal+ // routes (earpiece, speakerphone) to candidates on non-English+ // devices. Only explicit external hints may trigger the prompt.const devices = [input('phone-mic', 'Primary microphone', 'phone'),input('interface', 'Scarlett 2i2', 'interface')];- expect(findExternalAudioInputCandidates(devices, 'phone-mic'))- .toMatchObject([{ deviceId: 'interface' }]);+ expect(findExternalAudioInputCandidates(devices, 'phone-mic')).toEqual([]);});it('does not infer an external input from group data without an active group', () => {