Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Multi-input recording: pick a primary mic + an optional secondary device, mix them via Web Audio at recording time — solves the macOS / Linux meeting-recording problem where neither getDisplayMedia (tab-only) nor swapping the mic source in pavucontrol (loses the user's voice) can capture both sides of a conversation in one go; new state refs in app.modular.js (inputAudioDevices, selectedMicDeviceId, selectedSecondaryDeviceId — both deviceIds persisted in localStorage), plus refreshInputAudioDevices() that calls navigator.mediaDevices.enumerateDevices and tags Pulse monitor / BlackHole / VB-Cable / Voicemeeter / Stereo Mix / PipeWire monitor sources as isVirtual so the picker can badge them; audio.js's microphone-mode capture rewritten — when a secondary device is selected the code captures TWO getUserMedia streams with distinct deviceId constraints, builds a GainNode mixer in the AudioContext, connects both sources into it, routes the mixer output to a MediaStreamDestination and feeds that consolidated stream to MediaRecorder; the analyser hook is taken off the mixer too so the visualizer reflects the combined waveform; falls back gracefully to single-stream recording if the secondary device disappears between picker-populate and start-recording, with a toast explaining; single-stream path preserved unchanged for the common case so MediaRecorder still consumes the raw mic stream directly with no Web Audio hop; device-picker UI added to the upload modal as a collapsed <details> group under the recording buttons — when expanded shows two selects (primary + 'Also mix in (optional)') with monitor / virtual entries tagged; pre-permission state shows a button that calls getUserMedia briefly to populate device labels; refreshInputAudioDevices is automatically re-run after the first mic-permission grant inside startRecordingInternal so the labels become real names instead of opaque IDs

Murtaza Nasirea44dca91274
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index 041d5a87..f53c9e82 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -371,6 +371,47 @@ document.addEventListener('DOMContentLoaded', async () => {
watch(disableAudioProcessing, (v) => {
try { localStorage.setItem('disableAudioProcessing', v ? 'true' : 'false'); } catch (_) {}
});
+
+ // Per-input-device state for the multi-source recording flow.
+ // The user can pick a PRIMARY input (their mic) and an OPTIONAL
+ // SECONDARY input (e.g. a Pulse monitor source / BlackHole / VB-
+ // Cable) — both are captured via getUserMedia and mixed in Web
+ // Audio so the recording captures the user AND whatever's
+ // playing through their speakers in one stream. Device IDs are
+ // persisted in localStorage so the user only configures once.
+ // Labels populate only AFTER mic permission is granted; the
+ // first grant triggers refreshInputAudioDevices to repopulate
+ // the dropdowns with real names.
+ const inputAudioDevices = ref([]);
+ const selectedMicDeviceId = ref(
+ (typeof localStorage !== 'undefined' && localStorage.getItem('selectedMicDeviceId')) || ''
+ );
+ const selectedSecondaryDeviceId = ref(
+ (typeof localStorage !== 'undefined' && localStorage.getItem('selectedSecondaryDeviceId')) || ''
+ );
+ watch(selectedMicDeviceId, (v) => {
+ try { localStorage.setItem('selectedMicDeviceId', v || ''); } catch (_) {}
+ });
+ watch(selectedSecondaryDeviceId, (v) => {
+ try { localStorage.setItem('selectedSecondaryDeviceId', v || ''); } catch (_) {}
+ });
+ const refreshInputAudioDevices = async () => {
+ if (typeof navigator === 'undefined' || !navigator.mediaDevices) return;
+ try {
+ const devs = await navigator.mediaDevices.enumerateDevices();
+ inputAudioDevices.value = devs
+ .filter(d => d.kind === 'audioinput')
+ .map(d => ({
+ deviceId: d.deviceId,
+ label: d.label || '',
+ // Tag virtual/monitor devices so the UI can badge them
+ isVirtual: /\bmonitor of |blackhole|loopback|soundflower|vb[- ]?(audio|cable)|voicemeeter|stereo mix|what u hear|pulse.*monitor|pipewire.*monitor|monitor source/i.test(d.label || '')
+ }));
+ } catch (_) {
+ inputAudioDevices.value = [];
+ }
+ };
+ refreshInputAudioDevices();
// Platform + capability state for the system-audio flow.
// Detected once on init; the help modal uses these to
// pre-select the right OS tab and to gate which paragraphs
@@ -1424,6 +1465,7 @@ document.addEventListener('DOMContentLoaded', async () => {
isRecording, mediaRecorder, audioChunks, audioBlobURL, recordingTime, recordingInterval,
canRecordAudio, canRecordSystemAudio, systemAudioSupported, systemAudioError,
recordingNotes, showSystemAudioHelp, showSystemAudioHelpModal, disableAudioProcessing,
+ inputAudioDevices, selectedMicDeviceId, selectedSecondaryDeviceId, refreshInputAudioDevices,
platformInfo, audioCaps, helpModalOsTab, virtualAudioDevices, refreshVirtualAudioDevices,
asrLanguage, asrMinSpeakers, asrMaxSpeakers,
audioContext, analyser, micAnalyser, systemAnalyser, visualizer, micVisualizer,
@@ -1780,7 +1822,8 @@ document.addEventListener('DOMContentLoaded', async () => {
getDateForSorting, isToday, isYesterday, isThisWeek, isLastWeek, isThisMonth, isLastMonth, isSameDay,
nextTick,
onChatComplete: loadTokenBudget, // Refresh token budget after chat
- refreshVirtualAudioDevices // Re-scan installed BlackHole / VB-Cable / monitor sources
+ refreshVirtualAudioDevices, // Re-scan installed BlackHole / VB-Cable / monitor sources
+ refreshInputAudioDevices // Re-scan all audio inputs for the device picker
};
// =========================================================================
diff --git a/static/js/modules/composables/audio.js b/static/js/modules/composables/audio.js
index 5bfbd531..88e8905e 100644
--- a/static/js/modules/composables/audio.js
+++ b/static/js/modules/composables/audio.js
@@ -13,7 +13,9 @@ export function useAudio(state, utils) {
audioChunks, recordingTime, recordingInterval, recordingMode, audioBlobURL,
estimatedFileSize, actualBitrate, recordingNotes, recordingQuality,
maxRecordingMB, fileSizeWarningShown, sizeCheckInterval, recordingDisclaimer,
- showRecordingDisclaimerModal, pendingRecordingMode, currentView, showUploadModal, showSystemAudioHelp, disableAudioProcessing, isDarkMode, wakeLock, animationFrameId,
+ showRecordingDisclaimerModal, pendingRecordingMode, currentView, showUploadModal, showSystemAudioHelp, disableAudioProcessing,
+ selectedMicDeviceId, selectedSecondaryDeviceId,
+ isDarkMode, wakeLock, animationFrameId,
activeStreams, visualizer, micVisualizer, systemVisualizer, canRecordAudio,
canRecordSystemAudio, systemAudioSupported, systemAudioError, globalError,
selectedTagIds, selectedFolderId, asrLanguage, asrMinSpeakers, asrMaxSpeakers, uploadQueue,
@@ -275,28 +277,91 @@ export function useAudio(state, utils) {
// as a toggle in the upload modal next to the mic
// button and persisted in localStorage.
const skipProc = disableAudioProcessing && disableAudioProcessing.value;
- stream = await navigator.mediaDevices.getUserMedia({
- audio: {
+ const buildConstraints = (deviceId) => {
+ const c = {
echoCancellation: !skipProc,
noiseSuppression: !skipProc,
autoGainControl: !skipProc,
sampleRate: 48000
- }
+ };
+ if (deviceId) c.deviceId = { exact: deviceId };
+ return c;
+ };
+
+ const primaryDeviceId = (selectedMicDeviceId && selectedMicDeviceId.value) || '';
+ const secondaryDeviceId = (selectedSecondaryDeviceId && selectedSecondaryDeviceId.value) || '';
+ const wantsMix = !!secondaryDeviceId && secondaryDeviceId !== primaryDeviceId;
+
+ // Primary stream (the user's mic, or whatever they
+ // explicitly picked as the primary input).
+ const micStreamA = await navigator.mediaDevices.getUserMedia({
+ audio: buildConstraints(primaryDeviceId)
});
- activeStreams.value = [stream];
+
// Now that the user has granted mic permission,
// device labels populate — re-scan for virtual audio
// routing devices (BlackHole / VB-Cable / monitor
- // sources) so the upload modal can offer them.
- if (utils.refreshVirtualAudioDevices) {
- utils.refreshVirtualAudioDevices();
- }
+ // sources) so the upload modal can offer them. Also
+ // refresh the full input-device list for the picker
+ // (post-permission the labels are real names instead
+ // of opaque IDs).
+ if (utils.refreshVirtualAudioDevices) utils.refreshVirtualAudioDevices();
+ if (utils.refreshInputAudioDevices) utils.refreshInputAudioDevices();
audioContext.value = new (window.AudioContext || window.webkitAudioContext)();
- const source = audioContext.value.createMediaStreamSource(stream);
- analyser.value = audioContext.value.createAnalyser();
- analyser.value.fftSize = 256;
- source.connect(analyser.value);
+
+ if (wantsMix) {
+ // Mix-mode: capture a second getUserMedia stream
+ // from the chosen secondary device, then merge
+ // both into a single MediaStream via Web Audio so
+ // the rest of the pipeline (MediaRecorder, the
+ // visualizer analyser) sees one consolidated
+ // stream. Falls back to single-stream recording
+ // if the secondary capture fails (e.g. the device
+ // disappeared since the picker was populated).
+ let micStreamB;
+ try {
+ micStreamB = await navigator.mediaDevices.getUserMedia({
+ audio: buildConstraints(secondaryDeviceId)
+ });
+ } catch (mixErr) {
+ console.warn('[Recording] Secondary input unavailable, falling back to primary only:', mixErr);
+ if (utils.showToast) utils.showToast(
+ 'Secondary input unavailable — recording primary only.',
+ 'fa-exclamation-triangle'
+ );
+ }
+
+ if (micStreamB) {
+ const mixer = audioContext.value.createGain();
+ audioContext.value.createMediaStreamSource(micStreamA).connect(mixer);
+ audioContext.value.createMediaStreamSource(micStreamB).connect(mixer);
+ const dest = audioContext.value.createMediaStreamDestination();
+ mixer.connect(dest);
+ stream = dest.stream;
+ activeStreams.value = [micStreamA, micStreamB];
+ analyser.value = audioContext.value.createAnalyser();
+ analyser.value.fftSize = 256;
+ mixer.connect(analyser.value);
+ } else {
+ stream = micStreamA;
+ activeStreams.value = [micStreamA];
+ const src = audioContext.value.createMediaStreamSource(stream);
+ analyser.value = audioContext.value.createAnalyser();
+ analyser.value.fftSize = 256;
+ src.connect(analyser.value);
+ }
+ } else {
+ // Single-stream path (preserved from the original
+ // behaviour). The MediaRecorder consumes micStreamA
+ // directly so there's no needless Web Audio hop.
+ stream = micStreamA;
+ activeStreams.value = [stream];
+ const src = audioContext.value.createMediaStreamSource(stream);
+ analyser.value = audioContext.value.createAnalyser();
+ analyser.value.fftSize = 256;
+ src.connect(analyser.value);
+ }
} else if (mode === 'system') {
if (!canRecordSystemAudio.value) {
diff --git a/templates/components/upload-view.html b/templates/components/upload-view.html
index a18a1bb3..c31a4d70 100644
--- a/templates/components/upload-view.html
+++ b/templates/components/upload-view.html
@@ -284,6 +284,62 @@
</span>
</label>
+ <!-- Input device picker (collapsed by default). Lets
+ the user pick the primary input AND an optional
+ secondary input which Speakr mixes in via Web
+ Audio at recording time — the canonical solution
+ for capturing your voice + remote participants on
+ macOS / Linux where the browser can't capture full
+ OS audio natively. Pre-permission the device
+ labels are empty; the inline button calls
+ getUserMedia briefly to populate them. -->
+ <details class="text-[11px] mt-1 group">
+ <summary class="cursor-pointer flex items-center gap-1 px-2 py-1 rounded-md hover:bg-[var(--bg-tertiary)] transition-colors" style="color: var(--text-muted); list-style: none;">
+ <i class="fas fa-sliders-h"></i>
+ <span>Input devices</span>
+ <span v-if="selectedSecondaryDeviceId" class="text-green-500 font-medium">· Mixing 2 inputs</span>
+ <i class="fas fa-chevron-down ml-auto text-[10px] transition-transform group-open:rotate-180"></i>
+ </summary>
+ <div class="mt-2 space-y-2 px-2 py-2 rounded-md" style="background: var(--bg-tertiary);">
+ <div v-if="!inputAudioDevices || inputAudioDevices.length === 0 || !(inputAudioDevices[0] && inputAudioDevices[0].label)"
+ class="text-[11px]" style="color: var(--text-muted);">
+ <i class="fas fa-info-circle mr-1"></i>
+ Grant microphone permission once so device names can populate.
+ <button @click.prevent="navigator.mediaDevices.getUserMedia({audio:true}).then(s => { s.getTracks().forEach(t => t.stop()); refreshInputAudioDevices(); })"
+ class="underline mt-1 block" style="color: var(--text-accent);">
+ Request microphone permission
+ </button>
+ </div>
+ <template v-else>
+ <div>
+ <label class="block text-[11px] mb-1" style="color: var(--text-muted);">Primary input</label>
+ <select v-model="selectedMicDeviceId"
+ class="w-full text-[11px] px-2 py-1 rounded border border-[var(--border-secondary)] bg-[var(--bg-input)] text-[var(--text-primary)]">
+ <option value="">System default</option>
+ <option v-for="d in inputAudioDevices" :key="d.deviceId" :value="d.deviceId">
+ ${ d.label }${ d.isVirtual ? ' · virtual / monitor' : '' }
+ </option>
+ </select>
+ </div>
+ <div>
+ <label class="block text-[11px] mb-1" style="color: var(--text-muted);">
+ Also mix in (optional)
+ </label>
+ <select v-model="selectedSecondaryDeviceId"
+ class="w-full text-[11px] px-2 py-1 rounded border border-[var(--border-secondary)] bg-[var(--bg-input)] text-[var(--text-primary)]">
+ <option value="">None</option>
+ <option v-for="d in inputAudioDevices" :key="'sec-' + d.deviceId" :value="d.deviceId">
+ ${ d.label }${ d.isVirtual ? ' · virtual / monitor' : '' }
+ </option>
+ </select>
+ <p class="text-[10px] mt-1" style="color: var(--text-muted);">
+ Pick a monitor source ("Monitor of …" on Linux, BlackHole on macOS, VB-Cable on Windows) to mix system audio with your mic. Both streams combine into one recording.
+ </p>
+ </div>
+ </template>
+ </div>
+ </details>
+
<!-- Help Text - Compact -->
<div class="text-[10px] text-[var(--text-muted)] space-y-0.5 mt-2">
<div class="flex items-center justify-between">